Skip to content

Commit

Permalink
CLN: clean c code - remove unused variables / functions (#1619)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Nov 24, 2022
1 parent c4774d0 commit fa0505f
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 139 deletions.
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ def finalize_options(self):
# delete any previously Cythonized or compiled files in pygeos
p = Path(".")
for pattern in [
"build/lib.*/pygeos/*.so",
"pygeos/*.c",
"pygeos/*.so",
"pygeos/*.pyd",
"build/lib.*/shapely/*.so",
"shapely/*.c",
"shapely/*.so",
"shapely/*.pyd",
]:
for filename in p.glob(pattern):
print(f"removing '{filename}'")
Expand Down
2 changes: 1 addition & 1 deletion src/geos.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ int init_geos(PyObject* m) {
PyModule_AddObject(m, "ShapelyError", base_class);
geos_exception[0] = PyErr_NewException("shapely.errors.GEOSException", base_class, NULL);
PyModule_AddObject(m, "GEOSException", geos_exception[0]);
return 0;

void* context_handle = GEOS_init_r();
// TODO: the error handling is not yet set up for the global context (it is right now
// only used where error handling is not used)
// GEOSContext_setErrorMessageHandler_r(context_handle, geos_error_handler, last_error);
geos_context[0] = context_handle;

return 0;
}

void destroy_geom_arr(void* context, GEOSGeometry** array, int length) {
Expand Down
93 changes: 0 additions & 93 deletions src/pygeom.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,99 +291,6 @@ static PyObject* GeometryObject_richcompare(GeometryObject* self, PyObject* othe
return result;
}

static PyObject* GeometryObject_FromWKT(PyObject* value) {
PyObject* result = NULL;
const char* wkt;
GEOSGeometry* geom;
GEOSWKTReader* reader;

/* Cast the PyObject str to char* */
if (PyUnicode_Check(value)) {
wkt = PyUnicode_AsUTF8(value);
if (wkt == NULL) {
return NULL;
}
} else {
PyErr_Format(PyExc_TypeError, "Expected bytes, found %s", value->ob_type->tp_name);
return NULL;
}

GEOS_INIT;

reader = GEOSWKTReader_create_r(ctx);
if (reader == NULL) {
errstate = PGERR_GEOS_EXCEPTION;
goto finish;
}
geom = GEOSWKTReader_read_r(ctx, reader, wkt);
GEOSWKTReader_destroy_r(ctx, reader);
if (geom == NULL) {
errstate = PGERR_GEOS_EXCEPTION;
goto finish;
}
result = GeometryObject_FromGEOS(geom, ctx);
if (result == NULL) {
GEOSGeom_destroy_r(ctx, geom);
PyErr_Format(PyExc_RuntimeError, "Could not instantiate a new Geometry object");
}

finish:
GEOS_FINISH;
if (errstate == PGERR_SUCCESS) {
return result;
} else {
return NULL;
}
}

static PyObject* GeometryObject_FromWKB(PyObject* value) {
PyObject* result = NULL;
unsigned char* wkb = NULL;
Py_ssize_t size;
GEOSGeometry* geom = NULL;
GEOSWKBReader* reader = NULL;

/* Cast the PyObject bytes to char* */
if (!PyBytes_Check(value)) {
PyErr_Format(PyExc_TypeError, "Expected bytes, found %s", value->ob_type->tp_name);
return NULL;
}
size = PyBytes_Size(value);
wkb = (unsigned char*)PyBytes_AsString(value);
if (wkb == NULL) {
return NULL;
}

GEOS_INIT;

reader = GEOSWKBReader_create_r(ctx);
if (reader == NULL) {
errstate = PGERR_GEOS_EXCEPTION;
goto finish;
}
geom = GEOSWKBReader_read_r(ctx, reader, wkb, size);
if (geom == NULL) {
errstate = PGERR_GEOS_EXCEPTION;
goto finish;
}

result = GeometryObject_FromGEOS(geom, ctx);
if (result == NULL) {
GEOSGeom_destroy_r(ctx, geom);
PyErr_Format(PyExc_RuntimeError, "Could not instantiate a new Geometry object");
}

finish:

if (reader != NULL) {
GEOSWKBReader_destroy_r(ctx, reader);
}

GEOS_FINISH;

return result;
}

static PyMethodDef GeometryObject_methods[] = {
{NULL} /* Sentinel */
};
Expand Down
38 changes: 0 additions & 38 deletions src/strtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,44 +65,6 @@ FuncGEOS_YpY_b* get_predicate_func(int predicate_id) {
}
}

/* Calculate indices of tree geometries.
* This uses pointer offsets of geometries from the head of tree geometries to calculate
* corresponding indices.
*
* Parameters
* ----------
* tree_geoms: array of tree geometries
*
* arr: dynamic vector of addresses of geometries within tree geometries array
*/
static PyArrayObject* tree_geom_offsets_to_npy_arr(GeometryObject** tree_geoms,
tree_geom_vec_t* geoms) {
size_t i;
size_t size = kv_size(*geoms);
npy_intp geom_index;
char* head_ptr = (char*)tree_geoms; // head of tree geometry array

npy_intp dims[1] = {size};
// the following raises a compiler warning based on how the macro is defined
// in numpy. There doesn't appear to be anything we can do to avoid it.
PyArrayObject* result = (PyArrayObject*)PyArray_SimpleNew(1, dims, NPY_INTP);
if (result == NULL) {
PyErr_SetString(PyExc_RuntimeError, "could not allocate numpy array");
return NULL;
}

for (i = 0; i < size; i++) {
// Calculate index using offset of its address compared to head of tree geometries
geom_index =
(npy_intp)(((char*)kv_A(*geoms, i) - head_ptr) / sizeof(GeometryObject*));

// assign value into numpy array
*(npy_intp*)PyArray_GETPTR1(result, i) = geom_index;
}

return (PyArrayObject*)result;
}

static void STRtree_dealloc(STRtreeObject* self) {
size_t i;

Expand Down
3 changes: 0 additions & 3 deletions src/ufuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ int check_signals_interval[1] = {10000};
unsigned long main_thread_id[1] = {0};

PyObject* PySetupSignalChecks(PyObject* self, PyObject* args) {
npy_intp ret;
int interval;
unsigned long thread_id;

if (!PyArg_ParseTuple(args, "ik", check_signals_interval, main_thread_id)) {
return NULL;
Expand Down

0 comments on commit fa0505f

Please sign in to comment.