Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/main/conversions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1308,10 +1308,14 @@ as_status as_val_new_from_pyobject(AerospikeClient *self, as_error *err,
Py_DECREF(py_parameter);

PyObject *geospatial_dump = AerospikeGeospatial_DoDumps(py_data, err);
Py_XDECREF(py_data);
if (!geospatial_dump) {
return as_error_update(err, AEROSPIKE_ERR_CLIENT,
"Unable to call dumps function");
}
const char *geo_value = PyUnicode_AsUTF8(geospatial_dump);
char *geo_value_cpy = strdup(geo_value);

Py_DECREF(py_data);
Py_DECREF(geospatial_dump);

*val = (as_val *)as_geojson_new(geo_value_cpy, true);
Expand Down Expand Up @@ -2231,6 +2235,12 @@ void initialize_bin_for_strictypes(AerospikeClient *self, as_error *err,
else if (!strcmp(py_value->ob_type->tp_name, "aerospike.Geospatial")) {
PyObject *geo_data = PyObject_GetAttrString(py_value, "geo_data");
PyObject *geo_data_py_str = AerospikeGeospatial_DoDumps(geo_data, err);
Py_XDECREF(geo_data);
if (!geo_data_py_str) {
as_error_update(err, AEROSPIKE_ERR_CLIENT,
"Unable to call dumps function");
return;
}
const char *geo_data_str = PyUnicode_AsUTF8(geo_data_py_str);

// Make a copy of the encoding since the utf8 encoding points to a buffer in the PyUnicode object
Expand All @@ -2243,7 +2253,6 @@ void initialize_bin_for_strictypes(AerospikeClient *self, as_error *err,

// Cleanup
Py_XDECREF(geo_data_py_str);
Py_XDECREF(geo_data);
}
else if (!strcmp(py_value->ob_type->tp_name, "aerospike.null")) {
((as_val *)&binop_bin->value)->type = AS_UNKNOWN;
Expand Down
11 changes: 8 additions & 3 deletions src/main/convert_expressions.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,14 @@ get_exp_val_from_pyval(AerospikeClient *self, as_static_pool *static_pool,
PyObject *py_parameter = PyUnicode_FromString("geo_data");
PyObject *py_data = PyObject_GenericGetAttr(py_obj, py_parameter);
Py_DECREF(py_parameter);
char *geo_value =
(char *)PyUnicode_AsUTF8(AerospikeGeospatial_DoDumps(py_data, err));
Py_DECREF(py_data);
PyObject *geospatial_dump = AerospikeGeospatial_DoDumps(py_data, err);
Py_XDECREF(py_data);
if (!geospatial_dump) {
return as_error_update(err, AEROSPIKE_ERR_CLIENT,
"Unable to call dumps function");
}
char *geo_value = (char *)PyUnicode_AsUTF8(geospatial_dump);

as_exp_entry tmp_entry = as_exp_geo(geo_value);
*new_entry = tmp_entry;
}
Expand Down
7 changes: 1 addition & 6 deletions src/main/geospatial/dumps.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ PyObject *AerospikeGeospatial_DoDumps(PyObject *geo_data, as_error *err)
json_module = PyImport_ImportModule("json");
}

if (!json_module) {
/* insert error handling here! and exit this function */
as_error_update(err, AEROSPIKE_ERR_CLIENT,
"Unable to load json module");
}
else {
if (json_module && geo_data) {
PyObject *py_funcname = PyUnicode_FromString("dumps");
initresult = PyObject_CallMethodObjArgs(json_module, py_funcname,
geo_data, NULL);
Expand Down
3 changes: 0 additions & 3 deletions src/main/predicates.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ static PyObject *AerospikePredicates_GeoWithin_Radius(PyObject *self,
"double type, bin of string type");
goto CLEANUP;
}
Py_CLEAR(py_geo_object);

ret_val = Py_BuildValue("iiOOOO", AS_PREDICATE_RANGE, AS_INDEX_GEO2DSPHERE,
py_bin, py_shape, Py_None, py_indexType);
Expand Down Expand Up @@ -319,10 +318,8 @@ static PyObject *AerospikePredicates_GeoContains_Point(PyObject *self,
py_list = Py_BuildValue("[OO]", py_lat, py_long);

PyDict_SetItemString(py_geo_object, "coordinates", py_list);
Py_CLEAR(py_list);

py_shape = AerospikeGeospatial_DoDumps(py_geo_object, &err);
Py_CLEAR(py_geo_object);

if (!py_shape) {
as_error_update(&err, AEROSPIKE_ERR_CLIENT,
Expand Down
Loading