Skip to content

Commit 25e756e

Browse files
committed
Remove PyCXX from _convert_path_to_polygons()
1 parent 7cc0eb2 commit 25e756e

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

src/_path.cpp

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,31 +1725,37 @@ PyObject *_path_intersects_path(PyObject *self, PyObject *_args)
17251725
return PyInt_FromLong(isect);
17261726
}
17271727

1728-
void
1729-
_add_polygon(Py::List& polygons, const std::vector<double>& polygon)
1728+
int
1729+
_add_polygon(PyObject *_polygons, const std::vector<double>& polygon)
1730+
//void
1731+
//_add_polygon(Py::List& polygons, const std::vector<double>& polygon)
17301732
{
17311733
if (polygon.size() == 0)
17321734
{
1733-
return;
1735+
return 0;
17341736
}
17351737
npy_intp polygon_dims[] = { static_cast<npy_intp>(polygon.size() / 2), 2, 0 };
17361738
PyArrayObject* polygon_array = NULL;
17371739
polygon_array = (PyArrayObject*)PyArray_SimpleNew
17381740
(2, polygon_dims, PyArray_DOUBLE);
17391741
if (!polygon_array)
17401742
{
1741-
throw Py::MemoryError("Error creating polygon array");
1743+
PyErr_SetString(PyExc_MemoryError, "Error creating polygon array");
1744+
return -1;
1745+
//throw Py::MemoryError("Error creating polygon array");
17421746
}
17431747
double* polygon_data = (double*)PyArray_DATA(polygon_array);
17441748
memcpy(polygon_data, &polygon[0], polygon.size() * sizeof(double));
1745-
polygons.append(Py::Object((PyObject*)polygon_array, true));
1749+
int status = PyList_Append(_polygons, (PyObject*)polygon_array);
1750+
Py_DECREF(polygon_array);
1751+
return status;
1752+
//polygons.append(Py::Object((PyObject*)polygon_array, true));
17461753
}
17471754

17481755
//Py::Object
17491756
//_path_module::convert_path_to_polygons(const Py::Tuple& args)
17501757
PyObject *_convert_path_to_polygons(PyObject *self, PyObject *_args)
17511758
{
1752-
const Py::Tuple args(_args);
17531759
typedef agg::conv_transform<PathIterator> transformed_path_t;
17541760
typedef PathNanRemover<transformed_path_t> nan_removal_t;
17551761
typedef PathClipper<nan_removal_t> clipped_t;
@@ -1758,13 +1764,23 @@ PyObject *_convert_path_to_polygons(PyObject *self, PyObject *_args)
17581764

17591765
typedef std::vector<double> vertices_t;
17601766

1767+
PyObject *_path, *_trans;
1768+
double width, height;
1769+
if (!PyArg_ParseTuple(_args, "OOdd", &_path, &_trans, &width, &height)) {
1770+
return NULL;
1771+
}
1772+
PathIterator path(Py::Object(_path, false));
1773+
agg::trans_affine trans = py_to_agg_transformation_matrix(_trans, false);
1774+
1775+
/*
1776+
const Py::Tuple args(_args);
17611777
args.verify_length(4);
17621778
17631779
PathIterator path(args[0]);
17641780
agg::trans_affine trans = py_to_agg_transformation_matrix(args[1].ptr(), false);
17651781
double width = Py::Float(args[2]);
17661782
double height = Py::Float(args[3]);
1767-
1783+
*/
17681784
bool do_clip = width != 0.0 && height != 0.0;
17691785

17701786
bool simplify = path.should_simplify();
@@ -1775,7 +1791,9 @@ PyObject *_convert_path_to_polygons(PyObject *self, PyObject *_args)
17751791
simplify_t simplified(clipped, simplify, path.simplify_threshold());
17761792
curve_t curve(simplified);
17771793

1778-
Py::List polygons;
1794+
PyObject* polygons = PyList_New(0);
1795+
if (polygons == NULL) return NULL;
1796+
//Py::List polygons;
17791797
vertices_t polygon;
17801798
double x, y;
17811799
unsigned code;
@@ -1790,27 +1808,31 @@ PyObject *_convert_path_to_polygons(PyObject *self, PyObject *_args)
17901808
{
17911809
polygon.push_back(polygon[0]);
17921810
polygon.push_back(polygon[1]);
1793-
_add_polygon(polygons, polygon);
1811+
if (_add_polygon(polygons, polygon) == -1) goto Fail;
17941812
}
17951813
polygon.clear();
17961814
}
17971815
else
17981816
{
17991817
if (code == agg::path_cmd_move_to)
18001818
{
1801-
_add_polygon(polygons, polygon);
1819+
if (_add_polygon(polygons, polygon) == -1) goto Fail;
18021820
polygon.clear();
18031821
}
18041822
polygon.push_back(x);
18051823
polygon.push_back(y);
18061824
}
18071825
}
18081826

1809-
_add_polygon(polygons, polygon);
1827+
if (_add_polygon(polygons, polygon) == -1) goto Fail;
1828+
1829+
return polygons;
1830+
//Py_INCREF(polygons.ptr());
1831+
//return polygons.ptr();
18101832

1811-
//return polygons;
1812-
Py_INCREF(polygons.ptr());
1813-
return polygons.ptr();
1833+
Fail:
1834+
Py_DECREF(polygons);
1835+
return NULL;
18141836
}
18151837

18161838
template<class VertexSource>

0 commit comments

Comments
 (0)