Revision: 8474
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8474&view=rev
Author: mdboom
Date: 2010-06-28 13:54:52 + (Mon, 28 Jun 2010)
Log Message:
---
Use automatic memory management to simplify the code.
Modified Paths:
--
trunk/matplotlib/src/_backend_agg.cpp
trunk/matplotlib/src/_image.cpp
trunk/matplotlib/src/agg_py_path_iterator.h
Modified: trunk/matplotlib/src/_backend_agg.cpp
===
--- trunk/matplotlib/src/_backend_agg.cpp 2010-06-28 13:51:16 UTC (rev
8473)
+++ trunk/matplotlib/src/_backend_agg.cpp 2010-06-28 13:54:52 UTC (rev
8474)
@@ -881,23 +881,24 @@
const unsigned char* buffer = NULL;
int width, height;
Py::Object image_obj = args[0];
-PyArrayObject* image_array = NULL;
if (PyArray_Check(image_obj.ptr()))
{
-image_array = (PyArrayObject*)PyArray_FromObject(image_obj.ptr(),
PyArray_UBYTE, 2, 2);
+PyObject* image_array = PyArray_FromObject(
+image_obj.ptr(), PyArray_UBYTE, 2, 2);
if (!image_array)
{
throw Py::ValueError(
"First argument to draw_text_image must be a FT2Font.Image
object or a Nx2 uint8 numpy array.");
}
+image_obj = Py::Object(image_array, true);
buffer = (unsigned char *)PyArray_DATA(image_array);
width = PyArray_DIM(image_array, 1);
height = PyArray_DIM(image_array, 0);
}
else
{
-FT2Image *image = static_cast(args[0].ptr());
+FT2Image *image = static_cast(image_obj.ptr());
if (!image->get_buffer())
{
throw Py::ValueError(
@@ -916,7 +917,6 @@
}
catch (Py::TypeError)
{
-Py_XDECREF(image_array);
throw Py::TypeError("Invalid input arguments to draw_text_image");
}
@@ -959,8 +959,6 @@
theRasterizer.add_path(rect2);
agg::render_scanlines(theRasterizer, slineP8, ri);
-Py_XDECREF(image_array);
-
return Py::Object();
}
@@ -1352,204 +1350,193 @@
typedef agg::conv_curve
snapped_curve_t;
typedef agg::conv_curve curve_t;
-PyArrayObject* offsets= NULL;
-PyArrayObject* facecolors = NULL;
-PyArrayObject* edgecolors = NULL;
+PyArrayObject* offsets = (PyArrayObject*)PyArray_FromObject
+(offsets_obj.ptr(), PyArray_DOUBLE, 0, 2);
+if (!offsets ||
+(PyArray_NDIM(offsets) == 2 && PyArray_DIM(offsets, 1) != 2) ||
+(PyArray_NDIM(offsets) == 1 && PyArray_DIM(offsets, 0) != 0))
+{
+Py_XDECREF(offsets);
+throw Py::ValueError("Offsets array must be Nx2");
+}
+Py::Object offsets_arr_obj((PyObject*)offsets, true);
-try
+PyArrayObject* facecolors = (PyArrayObject*)PyArray_FromObject
+(facecolors_obj.ptr(), PyArray_DOUBLE, 1, 2);
+if (!facecolors ||
+(PyArray_NDIM(facecolors) == 1 && PyArray_DIM(facecolors, 0) != 0) ||
+(PyArray_NDIM(facecolors) == 2 && PyArray_DIM(facecolors, 1) != 4))
{
-offsets = (PyArrayObject*)PyArray_FromObject
- (offsets_obj.ptr(), PyArray_DOUBLE, 0, 2);
-if (!offsets ||
-(PyArray_NDIM(offsets) == 2 && PyArray_DIM(offsets, 1) != 2) ||
-(PyArray_NDIM(offsets) == 1 && PyArray_DIM(offsets, 0) != 0))
-{
-throw Py::ValueError("Offsets array must be Nx2");
-}
+Py_XDECREF(facecolors);
+throw Py::ValueError("Facecolors must be a Nx4 numpy array or empty");
+}
+Py::Object facecolors_arr_obj((PyObject*)facecolors, true);
-facecolors = (PyArrayObject*)PyArray_FromObject
- (facecolors_obj.ptr(), PyArray_DOUBLE, 1, 2);
-if (!facecolors ||
-(PyArray_NDIM(facecolors) == 1 && PyArray_DIM(facecolors, 0) != 0)
||
-(PyArray_NDIM(facecolors) == 2 && PyArray_DIM(facecolors, 1) != 4))
-{
-throw Py::ValueError("Facecolors must be a Nx4 numpy array or
empty");
-}
+PyArrayObject* edgecolors = (PyArrayObject*)PyArray_FromObject
+(edgecolors_obj.ptr(), PyArray_DOUBLE, 1, 2);
+if (!edgecolors ||
+(PyArray_NDIM(edgecolors) == 1 && PyArray_DIM(edgecolors, 0) != 0) ||
+(PyArray_NDIM(edgecolors) == 2 && PyArray_DIM(edgecolors, 1) != 4))
+{
+Py_XDECREF(edgecolors);
+throw Py::ValueError("Edgecolors must be a Nx4 numpy array");
+}
+Py::Object edgecolors_arr_obj((PyObject*)edgecolors, true);
-edgecolors = (PyArrayObject*)PyArray_FromObject
- (edgecolors_obj.ptr(), PyArray_DOUBLE, 1, 2);
-if (!edgecolors ||
-(PyArray_NDIM(edgecolors) == 1 && PyArray_DIM(edgecolors, 0) != 0)
||
-(PyArray_NDIM(edgecolors) == 2 && PyArray_DIM(edgecolors, 1) != 4))
-{
-throw Py::ValueError("Edgecolors