This is an automated email from the ASF dual-hosted git repository.
jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git
The following commit(s) were added to refs/heads/master by this push:
new ec1e26c98 [CI] Add pre-commit hook ClangFormat; format C files with
style `Google` (#1631)
ec1e26c98 is described below
commit ec1e26c980e315ada448e9a5b0557212b44f42b6
Author: John Bampton <[email protected]>
AuthorDate: Tue Oct 15 14:30:08 2024 +1000
[CI] Add pre-commit hook ClangFormat; format C files with style `Google`
(#1631)
https://clang.llvm.org/docs/ClangFormat.html
https://clang.llvm.org/docs/ClangFormatStyleOptions.html#basedonstyle
Standardizes the C code to one consistent format.
https://github.com/pre-commit/mirrors-clang-format
https://github.com/ssciwr/clang-format-wheel
---
.pre-commit-config.yaml | 6 ++++
python/src/geomserde_speedup_module.c | 52 ++++++++++++++++++---------------
python/src/pygeos/c_api.h | 55 ++++++++++++++++++++---------------
3 files changed, 66 insertions(+), 47 deletions(-)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index f84f612d5..9a41bd1a3 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -19,6 +19,12 @@ repos:
hooks:
- id: isort
name: isort (python)
+ - repo: https://github.com/pre-commit/mirrors-clang-format
+ rev: v19.1.1
+ hooks:
+ - id: clang-format
+ args: [--style=Google]
+ types_or: [c]
- repo: https://github.com/PyCQA/bandit
rev: 1.7.10
hooks:
diff --git a/python/src/geomserde_speedup_module.c
b/python/src/geomserde_speedup_module.c
index 2edf4b7b3..a95ced29e 100644
--- a/python/src/geomserde_speedup_module.c
+++ b/python/src/geomserde_speedup_module.c
@@ -192,33 +192,37 @@ static GEOSGeometry *do_deserialize(PyObject *args,
/* serialize/deserialize functions for Shapely 2.x */
static PyObject *serialize(PyObject *self, PyObject *args) {
- PyObject *pygeos_geom = NULL;
- if (!PyArg_ParseTuple(args, "O", &pygeos_geom)) {
- return NULL; // Argument parsing failed; error already set by
PyArg_ParseTuple
- }
+ PyObject *pygeos_geom = NULL;
+ if (!PyArg_ParseTuple(args, "O", &pygeos_geom)) {
+ return NULL; // Argument parsing failed; error already set by
+ // PyArg_ParseTuple
+ }
- GEOSGeometry *geos_geom = NULL;
- char success = PyGEOS_GetGEOSGeometry(pygeos_geom, &geos_geom);
- if (success == 0) {
- // Retrieve the type of the supplied object
- PyObject *type = (PyObject *)Py_TYPE(pygeos_geom);
- PyObject *type_name = PyObject_GetAttrString(type, "__name__");
- if (type_name == NULL) {
- // Fallback error if we can't get the type name
- PyErr_SetString(PyExc_TypeError, "Argument is of incorrect type.");
- } else {
- // Construct the error message with the type name
- const char *type_str = PyUnicode_AsUTF8(type_name);
- char error_msg[256];
- snprintf(error_msg, sizeof(error_msg), "Argument is of incorrect
type: '%s'. Please provide only Geometry objects.", type_str);
-
- PyErr_SetString(PyExc_TypeError, error_msg);
- Py_DECREF(type_name); // Cleanup the reference to type_name
- }
- return NULL;
+ GEOSGeometry *geos_geom = NULL;
+ char success = PyGEOS_GetGEOSGeometry(pygeos_geom, &geos_geom);
+ if (success == 0) {
+ // Retrieve the type of the supplied object
+ PyObject *type = (PyObject *)Py_TYPE(pygeos_geom);
+ PyObject *type_name = PyObject_GetAttrString(type, "__name__");
+ if (type_name == NULL) {
+ // Fallback error if we can't get the type name
+ PyErr_SetString(PyExc_TypeError, "Argument is of incorrect type.");
+ } else {
+ // Construct the error message with the type name
+ const char *type_str = PyUnicode_AsUTF8(type_name);
+ char error_msg[256];
+ snprintf(error_msg, sizeof(error_msg),
+ "Argument is of incorrect type: '%s'. Please provide only "
+ "Geometry objects.",
+ type_str);
+
+ PyErr_SetString(PyExc_TypeError, error_msg);
+ Py_DECREF(type_name); // Cleanup the reference to type_name
}
+ return NULL;
+ }
- return do_serialize(geos_geom);
+ return do_serialize(geos_geom);
}
static PyObject *deserialize(PyObject *self, PyObject *args) {
diff --git a/python/src/pygeos/c_api.h b/python/src/pygeos/c_api.h
index 9cae70491..a2bcaa5a5 100644
--- a/python/src/pygeos/c_api.h
+++ b/python/src/pygeos/c_api.h
@@ -38,23 +38,28 @@
#define _PYGEOS_API_H
#include <Python.h>
+
#include "../geos_c_dyn.h"
-/* PyObject* PyGEOS_CreateGeometry(GEOSGeometry *ptr, GEOSContextHandle_t ctx)
*/
+/* PyObject* PyGEOS_CreateGeometry(GEOSGeometry *ptr, GEOSContextHandle_t ctx)
+ */
#define PyGEOS_CreateGeometry_NUM 0
#define PyGEOS_CreateGeometry_RETURN PyObject *
-#define PyGEOS_CreateGeometry_PROTO (GEOSGeometry * ptr, GEOSContextHandle_t
ctx)
+#define PyGEOS_CreateGeometry_PROTO \
+ (GEOSGeometry * ptr, GEOSContextHandle_t ctx)
/* char PyGEOS_GetGEOSGeometry(GeometryObject *obj, GEOSGeometry **out) */
#define PyGEOS_GetGEOSGeometry_NUM 1
#define PyGEOS_GetGEOSGeometry_RETURN char
#define PyGEOS_GetGEOSGeometry_PROTO (PyObject * obj, GEOSGeometry * *out)
-/* GEOSCoordSequence* PyGEOS_CoordSeq_FromBuffer(GEOSContextHandle_t ctx,
const double* buf,
- unsigned int size, unsigned
int dims, char ring_closure)*/
+/* GEOSCoordSequence* PyGEOS_CoordSeq_FromBuffer(GEOSContextHandle_t ctx, const
+ double* buf, unsigned int size, unsigned int dims, char ring_closure)*/
#define PyGEOS_CoordSeq_FromBuffer_NUM 2
-#define PyGEOS_CoordSeq_FromBuffer_RETURN GEOSCoordSequence*
-#define PyGEOS_CoordSeq_FromBuffer_PROTO (GEOSContextHandle_t ctx, const
double* buf, unsigned int size, unsigned int dims, char ring_closure)
+#define PyGEOS_CoordSeq_FromBuffer_RETURN GEOSCoordSequence *
+#define PyGEOS_CoordSeq_FromBuffer_PROTO \
+ (GEOSContextHandle_t ctx, const double *buf, unsigned int size, \
+ unsigned int dims, char ring_closure)
/* Total number of C API pointers */
#define PyGEOS_API_num_pointers 3
@@ -64,39 +69,43 @@
* Each API function needs to provide a corresponding *_PROTO here.
*/
-extern PyGEOS_CreateGeometry_RETURN PyGEOS_CreateGeometry
PyGEOS_CreateGeometry_PROTO;
-extern PyGEOS_GetGEOSGeometry_RETURN PyGEOS_GetGEOSGeometry
PyGEOS_GetGEOSGeometry_PROTO;
-extern PyGEOS_CoordSeq_FromBuffer_RETURN PyGEOS_CoordSeq_FromBuffer
PyGEOS_CoordSeq_FromBuffer_PROTO;
+extern PyGEOS_CreateGeometry_RETURN PyGEOS_CreateGeometry
+ PyGEOS_CreateGeometry_PROTO;
+extern PyGEOS_GetGEOSGeometry_RETURN PyGEOS_GetGEOSGeometry
+ PyGEOS_GetGEOSGeometry_PROTO;
+extern PyGEOS_CoordSeq_FromBuffer_RETURN PyGEOS_CoordSeq_FromBuffer
+ PyGEOS_CoordSeq_FromBuffer_PROTO;
#else
/* This section is used in modules that use the PyGEOS C API
* Each API function needs to provide the lookup into PyGEOS_API as a
* define statement.
-*/
+ */
static void **PyGEOS_API;
-#define PyGEOS_CreateGeometry \
- (*(PyGEOS_CreateGeometry_RETURN(*)
PyGEOS_CreateGeometry_PROTO)PyGEOS_API[PyGEOS_CreateGeometry_NUM])
+#define PyGEOS_CreateGeometry \
+ (*(PyGEOS_CreateGeometry_RETURN(*) \
+ PyGEOS_CreateGeometry_PROTO)PyGEOS_API[PyGEOS_CreateGeometry_NUM])
-#define PyGEOS_GetGEOSGeometry \
- (*(PyGEOS_GetGEOSGeometry_RETURN(*)
PyGEOS_GetGEOSGeometry_PROTO)PyGEOS_API[PyGEOS_GetGEOSGeometry_NUM])
+#define PyGEOS_GetGEOSGeometry \
+ (*(PyGEOS_GetGEOSGeometry_RETURN(*) \
+ PyGEOS_GetGEOSGeometry_PROTO)PyGEOS_API[PyGEOS_GetGEOSGeometry_NUM])
-#define PyGEOS_CoordSeq_FromBuffer \
- (*(PyGEOS_CoordSeq_FromBuffer_RETURN(*)
PyGEOS_CoordSeq_FromBuffer_PROTO)PyGEOS_API[PyGEOS_CoordSeq_FromBuffer_NUM])
+#define PyGEOS_CoordSeq_FromBuffer \
+ (*(PyGEOS_CoordSeq_FromBuffer_RETURN(*) PyGEOS_CoordSeq_FromBuffer_PROTO) \
+ PyGEOS_API[PyGEOS_CoordSeq_FromBuffer_NUM])
/* Dynamically load C API from PyCapsule.
- * This MUST be called prior to using C API functions in other modules;
otherwise
- * segfaults will occur when the PyGEOS C API functions are called.
+ * This MUST be called prior to using C API functions in other modules;
+ * otherwise segfaults will occur when the PyGEOS C API functions are called.
*
* Returns 0 on success, -1 if error.
* PyCapsule_Import will set an exception on error.
*/
-static int
-import_shapely_c_api(void)
-{
- PyGEOS_API = (void **)PyCapsule_Import("shapely.lib._C_API", 0);
- return (PyGEOS_API == NULL) ? -1 : 0;
+static int import_shapely_c_api(void) {
+ PyGEOS_API = (void **)PyCapsule_Import("shapely.lib._C_API", 0);
+ return (PyGEOS_API == NULL) ? -1 : 0;
}
#endif