don't heap-allocate vectors in findLabeledEdgeRings
[geos.git] / swig / python / python.i
blob6ad890ee785e9983c6e8282335be0a3199668770
1 /* =========================================================================
2 * Copyright 2005-2007 Charlie Savage, cfis@interserv.com
4 * Interface for a SWIG generated geos module.
6 * This is free software; you can redistribute and/or modify it under
7 * the terms of the GNU Lesser General Public Licence as published
8 * by the Free Software Foundation.
9 * See the COPYING file for more information.
11 * ========================================================================= */
13 /* Convert a Ruby array of GeosLinearRings to a C array. */
14 %typemap(in,numinputs=1) (GeosLinearRing **holes, size_t nholes)
16 if ($input == Py_None)
18 $1 = NULL;
19 $2 = 0;
21 else
23 /* Make sure the input can be treated as an array. */
24 if (!PySequence_Check($input))
25 SWIG_exception_fail(SWIG_RuntimeError, "in method '" "createPolygon" "', argument " "1"" of type '" "GeosLinearRing *""'");
27 /* Get the length */
28 $2 = PySequence_Size($input);
30 /* Allocate space for the C array. */
31 $1 = (GeosLinearRing**) malloc($2*sizeof(GeosLinearRing*));
33 for(size_t i = 0; i<$2; i++)
35 /* Get the Python Object */
36 PyObject *item = PySequence_GetItem($input,i);
38 /* Get the underlying pointer and give up ownership of it. */
39 GeosLinearRing *ring = NULL;
40 int convertResult = SWIG_ConvertPtr(item, (void**)&ring, $descriptor(GeosLinearRing*), SWIG_POINTER_DISOWN);
41 if (!SWIG_IsOK(convertResult)) {
42 SWIG_exception_fail(SWIG_ArgError(convertResult), "in method '" "createPolygon" "', argument " "1"" of type '" "GeosLinearRing *""'");
45 /* Put the pointer in the array */
46 $1[i] = ring;
51 %typemap(freearg) (GeosLinearRing **holes, size_t nholes)
53 if ($1) {
54 free((void*) $1);