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
3 changes: 2 additions & 1 deletion src/include/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ as_status pyobject_to_strArray(as_error *err, PyObject *py_list, char **arr,
as_status as_val_new_from_pyobject(AerospikeClient *self, as_error *err,
PyObject *py_obj, as_val **val,
as_static_pool *static_pool,
int serializer_type);
int serializer_type,
bool ignore_send_bool_as);

as_status pyobject_to_map(AerospikeClient *self, as_error *err,
PyObject *py_dict, as_map **map,
Expand Down
2 changes: 1 addition & 1 deletion src/main/client/cdt_operation_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ as_status get_asval(AerospikeClient *self, as_error *err, char *key,
return AEROSPIKE_OK;
}
return as_val_new_from_pyobject(self, err, py_val, val, static_pool,
serializer_type);
serializer_type, false);
}

as_status get_val_list(AerospikeClient *self, as_error *err,
Expand Down
6 changes: 3 additions & 3 deletions src/main/client/operate.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ static inline bool isExprOp(int op);

#define CONVERT_VAL_TO_AS_VAL() \
if (as_val_new_from_pyobject(self, err, py_value, &put_val, static_pool, \
SERIALIZER_PYTHON) != AEROSPIKE_OK) { \
SERIALIZER_PYTHON, false) != AEROSPIKE_OK) { \
return err->code; \
}

#define CONVERT_KEY_TO_AS_VAL() \
if (as_val_new_from_pyobject(self, err, py_key, &put_key, static_pool, \
SERIALIZER_PYTHON) != AEROSPIKE_OK) { \
SERIALIZER_PYTHON, false) != AEROSPIKE_OK) { \
return err->code; \
}

Expand All @@ -113,7 +113,7 @@ static inline bool isExprOp(int op);

#define CONVERT_RANGE_TO_AS_VAL() \
if (as_val_new_from_pyobject(self, err, py_range, &put_range, static_pool, \
SERIALIZER_PYTHON) != AEROSPIKE_OK) { \
SERIALIZER_PYTHON, false) != AEROSPIKE_OK) { \
return err->code; \
}

Expand Down
15 changes: 8 additions & 7 deletions src/main/conversions.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ as_status pyobject_to_list(AerospikeClient *self, as_error *err,
PyObject *py_val = PyList_GetItem(py_list, i);
as_val *val = NULL;
as_val_new_from_pyobject(self, err, py_val, &val, static_pool,
serializer_type);
serializer_type, false);
if (err->code != AEROSPIKE_OK) {
break;
}
Expand Down Expand Up @@ -712,12 +712,12 @@ as_status pyobject_to_map(AerospikeClient *self, as_error *err,
as_val *key = NULL;
as_val *val = NULL;
as_val_new_from_pyobject(self, err, py_key, &key, static_pool,
serializer_type);
serializer_type, false);
if (err->code != AEROSPIKE_OK) {
break;
}
as_val_new_from_pyobject(self, err, py_val, &val, static_pool,
serializer_type);
serializer_type, false);
if (err->code != AEROSPIKE_OK) {
if (key) {
as_val_destroy(key);
Expand Down Expand Up @@ -1228,7 +1228,8 @@ bool is_pyobj_correct_as_helpers_type(PyObject *obj,
as_status as_val_new_from_pyobject(AerospikeClient *self, as_error *err,
PyObject *py_obj, as_val **val,
as_static_pool *static_pool,
int serializer_type)
int serializer_type,
bool ignore_send_bool_as)
{
as_error_reset(err);

Expand Down Expand Up @@ -1428,7 +1429,7 @@ as_status as_record_init_from_pyobject(AerospikeClient *self, as_error *err,

as_val *val = NULL;
as_val_new_from_pyobject(self, err, py_bin_value, &val, static_pool,
serializer_type);
serializer_type, false);
if (err->code != AEROSPIKE_OK) {
break;
}
Expand Down Expand Up @@ -2844,8 +2845,8 @@ as_status get_cdt_ctx(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx,
}
else {
if (as_val_new_from_pyobject(self, err, py_value, &val,
static_pool,
serializer_type) != AEROSPIKE_OK) {
static_pool, serializer_type,
false) != AEROSPIKE_OK) {
as_cdt_ctx_destroy(cdt_ctx);
status = as_error_update(
err, AEROSPIKE_ERR_PARAM,
Expand Down
138 changes: 19 additions & 119 deletions src/main/convert_expressions.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,129 +464,29 @@ get_exp_val_from_pyval(AerospikeClient *self, as_static_pool *static_pool,
{
as_error_reset(err);

if (!py_obj) {
return as_error_update(err, AEROSPIKE_ERR_CLIENT,
"py_obj value is null");
as_val *val = NULL;
as_val_new_from_pyobject(self, err, py_obj, &val, static_pool,
serializer_type, true);
if (err->code != AEROSPIKE_OK) {
return err->code;
}
else if (PyBool_Check(py_obj)) {
as_exp_entry tmp_entry = as_exp_bool(PyObject_IsTrue(py_obj));
*new_entry =
tmp_entry; //TODO use as_exp_val((as_val *) bytes); here, might need a cast, not blocker
}
else if (PyLong_Check(py_obj)) {
int64_t l = (int64_t)PyLong_AsLongLong(py_obj);
if (l == -1 && PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
return as_error_update(err, AEROSPIKE_ERR_PARAM,
"integer value exceeds sys.maxsize");
}
}

as_exp_entry tmp_entry = as_exp_int(l);
*new_entry = tmp_entry;
}
else if (PyUnicode_Check(py_obj)) {
PyObject *py_ustr = PyUnicode_AsUTF8String(py_obj);
char *str = PyBytes_AsString(py_ustr);
temp_expr->val.val_string_p = strdup(str);
temp_expr->val_flag = VAL_STRING_P_ACTIVE;
as_exp_entry tmp_entry = as_exp_str(temp_expr->val.val_string_p);
*new_entry = tmp_entry;
Py_DECREF(py_ustr);
}
else if (PyBytes_Check(py_obj)) {
uint8_t *b = (uint8_t *)PyBytes_AsString(py_obj);
uint32_t b_len = (uint32_t)PyBytes_Size(py_obj);
as_exp_entry tmp_entry = as_exp_bytes(b, b_len);
*new_entry = tmp_entry;
}
else if (!strcmp(py_obj->ob_type->tp_name, "aerospike.Geospatial")) {
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);
as_exp_entry tmp_entry = as_exp_geo(geo_value);
*new_entry = tmp_entry;
}
else if (PyByteArray_Check(py_obj)) {
as_bytes *bytes;
GET_BYTES_POOL(bytes, static_pool, err);
if (err->code == AEROSPIKE_OK) {
if (serialize_based_on_serializer_policy(self, serializer_type,
&bytes, py_obj,
err) != AEROSPIKE_OK) {
return err->code;
}
as_exp_entry tmp_entry = as_exp_val(
(as_val *)
bytes); //TODO can this be simplified to a buffer and as_exp_bytes?
*new_entry = tmp_entry;
}
}
else if (PyList_Check(py_obj)) {
as_list *list = NULL;
pyobject_to_list(self, err, py_obj, &list, static_pool,
serializer_type);
if (err->code == AEROSPIKE_OK) {
temp_expr->val.val_list_p = list;
temp_expr->val_flag = VAL_LIST_P_ACTIVE;
as_exp_entry tmp_entry = as_exp_val(list);
*new_entry = tmp_entry;
}
}
else if (PyDict_Check(py_obj)) {
as_map *map = NULL;
pyobject_to_map(self, err, py_obj, &map, static_pool, serializer_type);
if (err->code == AEROSPIKE_OK) {
temp_expr->val.val_map_p = map;
temp_expr->val_flag = VAL_MAP_P_ACTIVE;
as_exp_entry tmp_entry = as_exp_val(map);
*new_entry = tmp_entry;
}
}
else if (Py_None == py_obj) {
as_exp_entry tmp_entry = as_exp_nil();
*new_entry = tmp_entry;
}
else if (!strcmp(py_obj->ob_type->tp_name, "aerospike.null")) {
as_exp_entry tmp_entry = as_exp_nil();
*new_entry = tmp_entry;
}
else if (AS_Matches_Classname(py_obj, AS_CDT_WILDCARD_NAME)) {
as_exp_entry tmp_entry =
as_exp_val((as_val *)as_val_reserve(&as_cmp_wildcard));
*new_entry = tmp_entry;
}
else if (AS_Matches_Classname(py_obj, AS_CDT_INFINITE_NAME)) {
as_exp_entry tmp_entry =
as_exp_val((as_val *)as_val_reserve(&as_cmp_inf));
*new_entry = tmp_entry;
}
else {
if (PyFloat_Check(py_obj)) {
double d = PyFloat_AsDouble(py_obj);
as_exp_entry tmp_entry = as_exp_float(d);
*new_entry = tmp_entry;
}
else {
as_bytes *bytes;
GET_BYTES_POOL(bytes, static_pool, err);
if (err->code == AEROSPIKE_OK) {
if (serialize_based_on_serializer_policy(self, serializer_type,
&bytes, py_obj,
err) != AEROSPIKE_OK) {
return err->code;
}

as_exp_entry tmp_entry = as_exp_val((as_val *)bytes);
*new_entry = tmp_entry;
}
}
}
as_exp_entry entry = as_exp_val(val);
*new_entry = entry;

return err->code;

// TODO: two ways:
// 1. Use as_val
// 2. Set raw value directly as a c type
// Misc:
// TODO:
// Here, passing a bytearray relies on serializer_type. bytes does not.
// as_val_new_from_pyobject does not rely on that for either bytearrays or bytes.
// Behavior only matches here if serializer_type = *_PYTHON
// TODO: Here bytearray conversion relies on static_pool, conversions.c does not.
// TODO: for Py_None, null, wildcard, infinite: conversions.c uses as_val_reserve(), here does not.
// TODO: floats and doubles may be different?
}

/*
Expand Down
3 changes: 2 additions & 1 deletion src/main/query/apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ AerospikeQuery *AerospikeQuery_Apply(AerospikeQuery *self, PyObject *args,
PyObject *py_val = PyList_GetItem(py_args, (Py_ssize_t)i);
as_val *val = NULL;
as_val_new_from_pyobject(self->client, &err, py_val, &val,
&static_pool, SERIALIZER_PYTHON);
&static_pool, SERIALIZER_PYTHON,
false);
if (err.code != AEROSPIKE_OK) {
as_error_update(&err, err.code, NULL);
as_arraylist_destroy(arglist);
Expand Down
2 changes: 1 addition & 1 deletion src/main/scan/apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ AerospikeScan *AerospikeScan_Apply(AerospikeScan *self, PyObject *args,
PyObject *py_val = PyList_GetItem(py_args, (Py_ssize_t)i);
as_val *val = NULL;
as_val_new_from_pyobject(self->client, &err, py_val, &val,
&static_pool, SERIALIZER_PYTHON);
&static_pool, SERIALIZER_PYTHON, false);
if (err.code != AEROSPIKE_OK) {
as_error_update(&err, err.code, NULL);
as_arraylist_destroy(arglist);
Expand Down
Loading