From 5b7a841122e1dfc43f9d4a47dcba44fa614ba3db Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 6 Aug 2025 15:16:37 -0700 Subject: [PATCH 01/57] fix regression --- src/main/query/where.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/query/where.c b/src/main/query/where.c index 0d3694fe30..50d6e5653e 100644 --- a/src/main/query/where.c +++ b/src/main/query/where.c @@ -67,10 +67,15 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, memset(&static_pool, 0, sizeof(static_pool)); pctx = cf_malloc(sizeof(as_cdt_ctx)); memset(pctx, 0, sizeof(as_cdt_ctx)); + // TODO: error suppressed if ctx is not the right type (e.g a python dictionary). if (get_cdt_ctx(self->client, &err, pctx, py_ctx, &ctx_in_use, &static_pool, SERIALIZER_PYTHON) != AEROSPIKE_OK) { return err.code; } + if (!ctx_in_use) { + cf_free(pctx); + pctx = NULL; + } } as_exp *exp_list = NULL; From 7d67f12d74e170bcc8f65ac9f3c148a1e1bd6f9a Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 6 Aug 2025 15:23:35 -0700 Subject: [PATCH 02/57] add regression test. --- test/new_tests/test_query.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/new_tests/test_query.py b/test/new_tests/test_query.py index 6ee01988d6..72cda2edd3 100644 --- a/test/new_tests/test_query.py +++ b/test/new_tests/test_query.py @@ -309,13 +309,22 @@ def teardown(): request.addfinalizer(teardown) - def test_query_with_correct_parameters_hi(self): + @pytest.mark.parametrize( + "extra_args", + [ + # ctx + [], + [None], + [[]] + ] + ) + def test_query_with_correct_parameters_hi(self, extra_args): """ Invoke query() with correct arguments """ query = self.as_connection.query("test", "demo") query.select("name", "test_age") - query.where(p.equals("test_age", 1)) + query.where(p.equals("test_age", 1), *extra_args) records = [] From af81d290c1e7d3663a8b0e4e55a069fd02a541e5 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 6 Aug 2025 15:26:22 -0700 Subject: [PATCH 03/57] add neg test --- test/new_tests/test_query.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/new_tests/test_query.py b/test/new_tests/test_query.py index 72cda2edd3..e10d9ead27 100644 --- a/test/new_tests/test_query.py +++ b/test/new_tests/test_query.py @@ -1110,6 +1110,10 @@ def callback(input_tuple): assert records assert len(records) == 3 + def test_query_with_invalid_ctx(self): + query = self.as_connection.query("test", "demo") + query.where(p.equals("bin", 1), ctx=1) + def test_query_with_base64_cdt_ctx(self): bs_b4_cdt = self.as_connection.get_cdtctx_base64(ctx_list_index) assert bs_b4_cdt == "khAA" From 2a0da1bfce5b78264ee0338549263226559b042f Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 6 Aug 2025 16:45:57 -0700 Subject: [PATCH 04/57] rm --- test/new_tests/test_query.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/new_tests/test_query.py b/test/new_tests/test_query.py index e10d9ead27..3cc655b3c0 100644 --- a/test/new_tests/test_query.py +++ b/test/new_tests/test_query.py @@ -1112,7 +1112,7 @@ def callback(input_tuple): def test_query_with_invalid_ctx(self): query = self.as_connection.query("test", "demo") - query.where(p.equals("bin", 1), ctx=1) + query.where(p.equals("bin", 1), 1) def test_query_with_base64_cdt_ctx(self): bs_b4_cdt = self.as_connection.get_cdtctx_base64(ctx_list_index) From 5782f655ade793ac310860031304483695316915 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 2 Jan 2026 11:47:12 -0800 Subject: [PATCH 05/57] Improve naming for as_cdt_ctx helper function --- src/include/conversions.h | 8 +- src/main/client/cdt_list_operate.c | 170 +++++++++++++++++----------- src/main/client/cdt_map_operate.c | 20 ++-- src/main/client/get_cdtctx_base64.c | 5 +- src/main/client/operate.c | 5 +- src/main/client/sec_index.c | 5 +- src/main/conversions.c | 10 +- src/main/convert_expressions.c | 6 +- src/main/query/where.c | 5 +- 9 files changed, 140 insertions(+), 94 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index 91504bf629..1f5fdcbf9f 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -167,9 +167,11 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, PyObject **pyuni_r, char **c_str_ptr, as_error *err); -as_status get_cdt_ctx(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, - PyObject *op_dict, bool *ctx_in_use, - as_static_pool *static_pool, int serializer_type); +as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, + as_cdt_ctx *cdt_ctx, PyObject *op_dict, + bool *ctx_in_use, + as_static_pool *static_pool, + int serializer_type); // allow_base64_encoded_exprs: can the Python object also be a Python unicode object (base64 encoded)? // if false, the Python object should only be a compiled Python expression object from aerospike_helpers diff --git a/src/main/client/cdt_list_operate.c b/src/main/client/cdt_list_operate.c index ca83b51c52..1f6ad57ddb 100644 --- a/src/main/client/cdt_list_operate.c +++ b/src/main/client/cdt_list_operate.c @@ -446,8 +446,9 @@ static as_status add_op_list_get_by_index(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -493,8 +494,9 @@ add_op_list_get_by_index_range(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -541,8 +543,9 @@ static as_status add_op_list_get_by_rank(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -587,8 +590,9 @@ add_op_list_get_by_rank_range(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -634,8 +638,9 @@ static as_status add_op_list_get_by_value(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to convert ctx list"); } @@ -673,8 +678,9 @@ add_op_list_get_by_value_list(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { /* Failed to add the operation, we need to destroy the list of values*/ as_val_destroy(value_list); return err->code; @@ -722,8 +728,9 @@ add_op_list_get_by_value_range(AerospikeClient *self, as_error *err, char *bin, goto error; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { goto error; } @@ -778,8 +785,9 @@ add_op_list_remove_by_index(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -824,8 +832,9 @@ static as_status add_op_list_remove_by_index_range( return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -871,8 +880,9 @@ add_op_list_remove_by_rank(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -916,8 +926,9 @@ static as_status add_op_list_remove_by_rank_range( return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -963,8 +974,9 @@ add_op_list_remove_by_value(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } @@ -1001,8 +1013,9 @@ static as_status add_op_list_remove_by_value_list( return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { /* Failed to convert ctx, we need to destroy the list of values*/ as_val_destroy(value_list); return err->code; @@ -1047,8 +1060,9 @@ static as_status add_op_list_remove_by_value_range( goto error; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { goto error; } @@ -1098,8 +1112,9 @@ static as_status add_op_list_set_order(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1132,8 +1147,9 @@ static as_status add_op_list_sort(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1176,8 +1192,9 @@ static as_status add_op_list_create(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1220,8 +1237,9 @@ static as_status add_op_list_append(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } @@ -1264,8 +1282,9 @@ static as_status add_op_list_append_items(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(items_list); return err->code; } @@ -1313,8 +1332,9 @@ static as_status add_op_list_insert(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } @@ -1362,8 +1382,9 @@ static as_status add_op_list_insert_items(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(items_list); return err->code; } @@ -1411,8 +1432,9 @@ static as_status add_op_list_increment(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(incr); return err->code; } @@ -1448,8 +1470,9 @@ static as_status add_op_list_pop(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1486,8 +1509,9 @@ static as_status add_op_list_pop_range(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1518,8 +1542,9 @@ static as_status add_op_list_remove(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { ; return err->code; } @@ -1559,8 +1584,9 @@ static as_status add_op_list_remove_range(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1586,8 +1612,9 @@ static as_status add_op_list_clear(AerospikeClient *self, as_error *err, bool ctx_in_use = false; as_cdt_ctx ctx; - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1631,8 +1658,9 @@ static as_status add_op_list_set(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } @@ -1667,8 +1695,9 @@ static as_status add_op_list_get(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1706,8 +1735,9 @@ static as_status add_op_list_get_range(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1745,8 +1775,9 @@ static as_status add_op_list_trim(AerospikeClient *self, as_error *err, return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1772,8 +1803,9 @@ static as_status add_op_list_size(AerospikeClient *self, as_error *err, bool ctx_in_use = false; as_cdt_ctx ctx; - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1820,8 +1852,9 @@ static as_status add_add_op_list_remove_by_value_rel_rank_range( return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1884,8 +1917,9 @@ static as_status add_add_op_list_get_by_value_rel_rank_range( return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } diff --git a/src/main/client/cdt_map_operate.c b/src/main/client/cdt_map_operate.c index b3f850adde..1c4809b766 100644 --- a/src/main/client/cdt_map_operate.c +++ b/src/main/client/cdt_map_operate.c @@ -125,8 +125,9 @@ static as_status add_op_map_remove_by_value_rel_rank_range( return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -188,8 +189,9 @@ static as_status add_op_map_get_by_value_rel_rank_range( return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -251,8 +253,9 @@ static as_status add_op_map_remove_by_key_rel_index_range( return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -313,8 +316,9 @@ static as_status add_op_map_get_by_key_rel_index_range( return err->code; } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, + static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } diff --git a/src/main/client/get_cdtctx_base64.c b/src/main/client/get_cdtctx_base64.c index 5b3e2cc25e..214df70ff6 100644 --- a/src/main/client/get_cdtctx_base64.c +++ b/src/main/client/get_cdtctx_base64.c @@ -91,8 +91,9 @@ PyObject *AerospikeClient_GetCDTCTXBase64(AerospikeClient *self, PyObject *args, "unable to convert Python cdtctx to it's C client counterpart"); goto CLEANUP; } - if (get_cdt_ctx(self, &err, &ctx, op_dict, &ctx_in_use, &static_pool, - SERIALIZER_PYTHON) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, &err, &ctx, op_dict, &ctx_in_use, + &static_pool, + SERIALIZER_PYTHON) != AEROSPIKE_OK) { goto CLEANUP; } if (!ctx_in_use) { diff --git a/src/main/client/operate.c b/src/main/client/operate.c index e80696a72d..3d9bddb191 100644 --- a/src/main/client/operate.c +++ b/src/main/client/operate.c @@ -107,8 +107,9 @@ static inline bool isExprOp(int op); } #define CONVERT_PY_CTX_TO_AS_CTX() \ - if (get_cdt_ctx(self, err, &ctx, py_operation_dict, &ctx_in_use, \ - static_pool, SERIALIZER_PYTHON) != AEROSPIKE_OK) { \ + if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, py_operation_dict, \ + &ctx_in_use, static_pool, \ + SERIALIZER_PYTHON) != AEROSPIKE_OK) { \ return err->code; \ } diff --git a/src/main/client/sec_index.c b/src/main/client/sec_index.c index d071758717..72904ac116 100644 --- a/src/main/client/sec_index.c +++ b/src/main/client/sec_index.c @@ -250,8 +250,9 @@ PyObject *AerospikeClient_Index_Cdt_Create(AerospikeClient *self, as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); - if (get_cdt_ctx(self, &err, &ctx, py_ctx, &ctx_in_use, &static_pool, - SERIALIZER_PYTHON) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, &err, &ctx, py_ctx, &ctx_in_use, + &static_pool, + SERIALIZER_PYTHON) != AEROSPIKE_OK) { goto CLEANUP; } if (!ctx_in_use) { diff --git a/src/main/conversions.c b/src/main/conversions.c index b3fb652d96..1b4cf40722 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2401,11 +2401,13 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, // an as_cdt_ctx object for use with the c-client. the cdt_ctx parameter should be an uninitialized as_cdt_ctx // object. This function will initilaise it, and free it IF an error occurs, otherwise, the caller must destroy // the as_cdt_ctx when it is done. -as_status get_cdt_ctx(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, - PyObject *op_dict, bool *ctx_in_use, - as_static_pool *static_pool, int serializer_type) +as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, + as_cdt_ctx *cdt_ctx, + PyObject *py_cdt_ctx, bool *ctx_in_use, + as_static_pool *static_pool, + int serializer_type) { - PyObject *py_ctx_list = PyDict_GetItemString(op_dict, CTX_KEY); + PyObject *py_ctx_list = PyDict_GetItemString(py_cdt_ctx, CTX_KEY); if (!py_ctx_list) { return AEROSPIKE_OK; diff --git a/src/main/convert_expressions.c b/src/main/convert_expressions.c index d8140d61db..a3a2b7f6ae 100644 --- a/src/main/convert_expressions.c +++ b/src/main/convert_expressions.c @@ -1840,9 +1840,9 @@ as_status as_exp_new_from_pyobject(AerospikeClient *self, PyObject *py_expr, goto CLEANUP; } - if (get_cdt_ctx(self, err, temp_expr.ctx, temp_expr.pydict, - &ctx_in_use, &static_pool, - SERIALIZER_PYTHON) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject( + self, err, temp_expr.ctx, temp_expr.pydict, &ctx_in_use, + &static_pool, SERIALIZER_PYTHON) != AEROSPIKE_OK) { goto CLEANUP; } } diff --git a/src/main/query/where.c b/src/main/query/where.c index 912389b195..fc1df2e199 100644 --- a/src/main/query/where.c +++ b/src/main/query/where.c @@ -68,8 +68,9 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, pctx = cf_malloc(sizeof(as_cdt_ctx)); memset(pctx, 0, sizeof(as_cdt_ctx)); // TODO: error suppressed if ctx is not the right type (e.g a python dictionary). - if (get_cdt_ctx(self->client, &err, pctx, py_ctx, &ctx_in_use, - &static_pool, SERIALIZER_PYTHON) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self->client, &err, pctx, py_ctx, + &ctx_in_use, &static_pool, + SERIALIZER_PYTHON) != AEROSPIKE_OK) { return err.code; } if (!ctx_in_use) { From 74b997cfc81e909871981208dd62ab6e9434edf5 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 2 Jan 2026 13:14:26 -0800 Subject: [PATCH 06/57] function docstring belongs in header file --- src/include/conversions.h | 4 ++++ src/main/conversions.c | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index 1f5fdcbf9f..2eebbebc58 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -167,6 +167,10 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, PyObject **pyuni_r, char **c_str_ptr, as_error *err); +// This function converts a list of cdt_ctx from aerospike_helpers.ctx to +// an as_cdt_ctx object for use with the c-client. the cdt_ctx parameter should be an uninitialized as_cdt_ctx +// object. This function will initilaise it, and free it IF an error occurs, otherwise, the caller must destroy +// the as_cdt_ctx when it is done. as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *op_dict, bool *ctx_in_use, diff --git a/src/main/conversions.c b/src/main/conversions.c index 1b4cf40722..3539605c15 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2397,10 +2397,6 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, return as_error_update(err, AEROSPIKE_ERR_PARAM, "String value required"); } -// This function converts a list of cdt_ctx from aerospike_helpers.ctx to -// an as_cdt_ctx object for use with the c-client. the cdt_ctx parameter should be an uninitialized as_cdt_ctx -// object. This function will initilaise it, and free it IF an error occurs, otherwise, the caller must destroy -// the as_cdt_ctx when it is done. as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_cdt_ctx, bool *ctx_in_use, From 22bd028ccb793923a151b8d5587427baded7de78 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 2 Jan 2026 13:43:16 -0800 Subject: [PATCH 07/57] Fix bug for all operations and expressions that accept a ctx argument --- src/include/conversions.h | 17 ++- src/main/client/cdt_list_operate.c | 204 ++++++++++++++-------------- src/main/client/get_cdtctx_base64.c | 21 +-- src/main/client/operate.c | 6 +- src/main/conversions.c | 32 +++-- src/main/query/where.c | 1 - 6 files changed, 139 insertions(+), 142 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index 2eebbebc58..1291013264 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -167,16 +167,23 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, PyObject **pyuni_r, char **c_str_ptr, as_error *err); -// This function converts a list of cdt_ctx from aerospike_helpers.ctx to -// an as_cdt_ctx object for use with the c-client. the cdt_ctx parameter should be an uninitialized as_cdt_ctx -// object. This function will initilaise it, and free it IF an error occurs, otherwise, the caller must destroy +// This function takes in a python list of contexts from aerospike_helpers.cdt_ctx +// and converts it to an as_cdt_ctx object for use with the c-client. +// +// The cdt_ctx parameter should point to an uninitialized as_cdt_ctx +// object. This function will initialize it, and free it IF an error occurs. Otherwise, the caller must destroy // the as_cdt_ctx when it is done. as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, - as_cdt_ctx *cdt_ctx, PyObject *op_dict, - bool *ctx_in_use, + as_cdt_ctx *cdt_ctx, + PyObject *py_cdt_ctx, bool *ctx_in_use, as_static_pool *static_pool, int serializer_type); +as_status as_cdt_ctx_init_from_py_operation_dict( + AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, + PyObject *py_op_dict, bool *ctx_in_use, as_static_pool *static_pool, + int serializer_type); + // allow_base64_encoded_exprs: can the Python object also be a Python unicode object (base64 encoded)? // if false, the Python object should only be a compiled Python expression object from aerospike_helpers as_status as_exp_new_from_pyobject(AerospikeClient *self, PyObject *py_expr, diff --git a/src/main/client/cdt_list_operate.c b/src/main/client/cdt_list_operate.c index 1f6ad57ddb..b90d732811 100644 --- a/src/main/client/cdt_list_operate.c +++ b/src/main/client/cdt_list_operate.c @@ -446,9 +446,9 @@ static as_status add_op_list_get_by_index(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -494,9 +494,9 @@ add_op_list_get_by_index_range(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -543,9 +543,9 @@ static as_status add_op_list_get_by_rank(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -590,9 +590,9 @@ add_op_list_get_by_rank_range(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -638,9 +638,9 @@ static as_status add_op_list_get_by_value(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to convert ctx list"); } @@ -678,9 +678,9 @@ add_op_list_get_by_value_list(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { /* Failed to add the operation, we need to destroy the list of values*/ as_val_destroy(value_list); return err->code; @@ -728,9 +728,9 @@ add_op_list_get_by_value_range(AerospikeClient *self, as_error *err, char *bin, goto error; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { goto error; } @@ -785,9 +785,9 @@ add_op_list_remove_by_index(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -832,9 +832,9 @@ static as_status add_op_list_remove_by_index_range( return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -880,9 +880,9 @@ add_op_list_remove_by_rank(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -926,9 +926,9 @@ static as_status add_op_list_remove_by_rank_range( return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -974,9 +974,9 @@ add_op_list_remove_by_value(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } @@ -1013,9 +1013,9 @@ static as_status add_op_list_remove_by_value_list( return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { /* Failed to convert ctx, we need to destroy the list of values*/ as_val_destroy(value_list); return err->code; @@ -1060,9 +1060,9 @@ static as_status add_op_list_remove_by_value_range( goto error; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { goto error; } @@ -1112,9 +1112,9 @@ static as_status add_op_list_set_order(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1147,9 +1147,9 @@ static as_status add_op_list_sort(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1192,9 +1192,9 @@ static as_status add_op_list_create(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1237,9 +1237,9 @@ static as_status add_op_list_append(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } @@ -1282,9 +1282,9 @@ static as_status add_op_list_append_items(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(items_list); return err->code; } @@ -1332,9 +1332,9 @@ static as_status add_op_list_insert(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } @@ -1382,9 +1382,9 @@ static as_status add_op_list_insert_items(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(items_list); return err->code; } @@ -1432,9 +1432,9 @@ static as_status add_op_list_increment(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(incr); return err->code; } @@ -1470,9 +1470,9 @@ static as_status add_op_list_pop(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1509,9 +1509,9 @@ static as_status add_op_list_pop_range(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1542,9 +1542,9 @@ static as_status add_op_list_remove(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { ; return err->code; } @@ -1584,9 +1584,9 @@ static as_status add_op_list_remove_range(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1612,9 +1612,9 @@ static as_status add_op_list_clear(AerospikeClient *self, as_error *err, bool ctx_in_use = false; as_cdt_ctx ctx; - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1658,9 +1658,9 @@ static as_status add_op_list_set(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } @@ -1695,9 +1695,9 @@ static as_status add_op_list_get(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1735,9 +1735,9 @@ static as_status add_op_list_get_range(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1775,9 +1775,9 @@ static as_status add_op_list_trim(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1803,9 +1803,9 @@ static as_status add_op_list_size(AerospikeClient *self, as_error *err, bool ctx_in_use = false; as_cdt_ctx ctx; - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1852,9 +1852,9 @@ static as_status add_add_op_list_remove_by_value_rel_rank_range( return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1917,9 +1917,9 @@ static as_status add_add_op_list_get_by_value_rel_rank_range( return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } diff --git a/src/main/client/get_cdtctx_base64.c b/src/main/client/get_cdtctx_base64.c index 214df70ff6..ef68c99159 100644 --- a/src/main/client/get_cdtctx_base64.c +++ b/src/main/client/get_cdtctx_base64.c @@ -47,7 +47,6 @@ PyObject *AerospikeClient_GetCDTCTXBase64(AerospikeClient *self, PyObject *args, as_cdt_ctx ctx; bool ctx_in_use = false; - PyObject *op_dict = NULL; char *base64 = NULL; PyObject *py_response = NULL; @@ -75,23 +74,7 @@ PyObject *AerospikeClient_GetCDTCTXBase64(AerospikeClient *self, PyObject *args, as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); - // Convert Python cdt_ctx to C version - // Pass in ctx into a dict so we can use helper function - op_dict = PyDict_New(); - if (op_dict == NULL) { - as_error_update( - &err, AEROSPIKE_ERR, - "unable to convert Python cdtctx to it's C client counterpart"); - goto CLEANUP; - } - int retval = PyDict_SetItemString(op_dict, "ctx", py_cdtctx); - if (retval == -1) { - as_error_update( - &err, AEROSPIKE_ERR, - "unable to convert Python cdtctx to it's C client counterpart"); - goto CLEANUP; - } - if (as_cdt_ctx_init_from_pyobject(self, &err, &ctx, op_dict, &ctx_in_use, + if (as_cdt_ctx_init_from_pyobject(self, &err, &ctx, py_cdtctx, &ctx_in_use, &static_pool, SERIALIZER_PYTHON) != AEROSPIKE_OK) { goto CLEANUP; @@ -129,7 +112,5 @@ PyObject *AerospikeClient_GetCDTCTXBase64(AerospikeClient *self, PyObject *args, return NULL; } - Py_XDECREF(op_dict); - return py_response; } diff --git a/src/main/client/operate.c b/src/main/client/operate.c index 3d9bddb191..e18ee61941 100644 --- a/src/main/client/operate.c +++ b/src/main/client/operate.c @@ -107,9 +107,9 @@ static inline bool isExprOp(int op); } #define CONVERT_PY_CTX_TO_AS_CTX() \ - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, py_operation_dict, \ - &ctx_in_use, static_pool, \ - SERIALIZER_PYTHON) != AEROSPIKE_OK) { \ + if (as_cdt_ctx_init_from_py_operation_dict( \ + self, err, &ctx, py_operation_dict, &ctx_in_use, static_pool, \ + SERIALIZER_PYTHON) != AEROSPIKE_OK) { \ return err->code; \ } diff --git a/src/main/conversions.c b/src/main/conversions.c index 3539605c15..ec2f9906fc 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2399,30 +2399,25 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, - PyObject *py_cdt_ctx, bool *ctx_in_use, + PyObject *py_ctx_list, bool *ctx_in_use, as_static_pool *static_pool, int serializer_type) { - PyObject *py_ctx_list = PyDict_GetItemString(py_cdt_ctx, CTX_KEY); + as_status status = 0; - if (!py_ctx_list) { - return AEROSPIKE_OK; + if (!py_ctx_list || !PyList_Check(py_ctx_list)) { + status = as_error_update(err, AEROSPIKE_ERR_PARAM, + "Failed to convert %s", CTX_KEY); + goto CLEANUP5; } long int_val = 0; as_val *val = NULL; - as_status status = 0; PyObject *py_id = NULL; PyObject *py_value = NULL; PyObject *py_extra_args = NULL; - if (!PyList_Check(py_ctx_list)) { - status = as_error_update(err, AEROSPIKE_ERR_PARAM, - "Failed to convert %s", CTX_KEY); - goto CLEANUP5; - } - Py_ssize_t py_list_size = PyList_Size(py_ctx_list); as_cdt_ctx_init(cdt_ctx, (int)py_list_size); @@ -2576,6 +2571,21 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, return status; } +as_status as_cdt_ctx_init_from_py_operation_dict( + AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, + PyObject *py_op_dict, bool *ctx_in_use, as_static_pool *static_pool, + int serializer_type) +{ + PyObject *py_ctx_list = PyDict_GetItemString(py_op_dict, CTX_KEY); + if (!py_ctx_list) { + return AEROSPIKE_OK; + } + + return as_cdt_ctx_init_from_pyobject(self, err, cdt_ctx, py_ctx_list, + ctx_in_use, static_pool, + serializer_type); +} + static bool requires_int(uint64_t op) { return op == AS_CDT_CTX_LIST_INDEX || op == AS_CDT_CTX_LIST_RANK || diff --git a/src/main/query/where.c b/src/main/query/where.c index fc1df2e199..0d48289f1f 100644 --- a/src/main/query/where.c +++ b/src/main/query/where.c @@ -67,7 +67,6 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, memset(&static_pool, 0, sizeof(static_pool)); pctx = cf_malloc(sizeof(as_cdt_ctx)); memset(pctx, 0, sizeof(as_cdt_ctx)); - // TODO: error suppressed if ctx is not the right type (e.g a python dictionary). if (as_cdt_ctx_init_from_pyobject(self->client, &err, pctx, py_ctx, &ctx_in_use, &static_pool, SERIALIZER_PYTHON) != AEROSPIKE_OK) { From 2bec4fdf87f00390de09064241d39ff422eca033 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 2 Jan 2026 14:48:01 -0800 Subject: [PATCH 08/57] Cherrypick some test changes from Dominic's CLIENT-2383 branch --- test/new_tests/test_cdt_index.py | 75 ++++++++++++++++++++------------ test/new_tests/test_query.py | 4 +- 2 files changed, 50 insertions(+), 29 deletions(-) diff --git a/test/new_tests/test_cdt_index.py b/test/new_tests/test_cdt_index.py index acf7beba0a..5c6fe70460 100644 --- a/test/new_tests/test_cdt_index.py +++ b/test/new_tests/test_cdt_index.py @@ -92,6 +92,27 @@ def teardown(): request.addfinalizer(teardown) def test_pos_cdtindex_with_correct_parameters(self): + """ + Invoke index_cdt_create() with correct arguments + """ + policy = {} + retobj = self.as_connection.index_cdt_create( + "test", + "demo", + "string_list", + aerospike.INDEX_TYPE_LIST, + aerospike.INDEX_STRING, + "test_string_list_cdt_index", + ctx_list_index, + policy, + ) + + self.as_connection.index_remove("test", "test_string_list_cdt_index", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_list_cdt_index") + + assert retobj == 0 + + def test_pos_cdtindex_dict_with_correct_parameters(self): """ Invoke index_cdt_create() with correct arguments """ @@ -148,7 +169,7 @@ def test_pos_cdtindex_with_listrank_correct_parameters(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_STRING, "test_string_list_cdt_index", - {"ctx": ctx_list_rank}, + ctx_list_rank, policy, ) @@ -169,7 +190,7 @@ def test_pos_cdtindex_with_listvalue_correct_parameters(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_STRING, "test_string_list_cdt_index", - {"ctx": ctx_list_value}, + ctx_list_value, policy, ) @@ -190,7 +211,7 @@ def test_pos_cdtindex_with_mapindex_correct_parameters(self): aerospike.INDEX_TYPE_MAPKEYS, aerospike.INDEX_STRING, "test_string_list_cdt_index", - {"ctx": ctx_map_index}, + ctx_map_index, policy, ) @@ -211,7 +232,7 @@ def test_pos_cdtindex_with_mapvalue_correct_parameters(self): aerospike.INDEX_TYPE_MAPVALUES, aerospike.INDEX_STRING, "test_string_list_cdt_index", - {"ctx": ctx_map_value}, + ctx_map_value, policy, ) @@ -232,7 +253,7 @@ def test_pos_cdtindex_with_maprankvalue_correct_parameters(self): aerospike.INDEX_TYPE_MAPVALUES, aerospike.INDEX_STRING, "test_string_list_cdt_index", - {"ctx": ctx_map_rank}, + ctx_map_rank, policy, ) @@ -254,7 +275,7 @@ def test_pos_cdtindex_with_correct_parameters1(self): aerospike.INDEX_TYPE_MAPVALUES, aerospike.INDEX_STRING, "test_string_list_cdt_index", - {"ctx": ctx_map_rank}, + ctx_map_rank, policy, ) @@ -275,7 +296,7 @@ def test_pos_cdtindex_with_correct_parameters_numeric(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_NUMERIC, "test_numeric_list_cdt_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) @@ -298,7 +319,7 @@ def test_pos_cdtindex_with_correct_parameters_set_length_extra(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_STRING, "test_string_list_cdt_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) assert False @@ -319,7 +340,7 @@ def test_pos_cdtindex_with_incorrect_bin(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_STRING, "test_string_list_cdt_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) @@ -339,7 +360,7 @@ def test_pos_create_same_cdtindex_multiple_times(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_NUMERIC, "test_numeric_list_cdt_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) if retobj == 0: @@ -351,7 +372,7 @@ def test_pos_create_same_cdtindex_multiple_times(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_NUMERIC, "test_numeric_list_cdt_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) except e.IndexFoundError: @@ -373,7 +394,7 @@ def test_pos_create_same_cdtindex_multiple_times_different_bin(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_STRING, "test_string_list_cdt_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) if retobj == 0: @@ -385,7 +406,7 @@ def test_pos_create_same_cdtindex_multiple_times_different_bin(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_NUMERIC, "test_string_list_cdt_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) self.as_connection.index_remove("test", "test_string_list_cdt_index", policy) @@ -409,7 +430,7 @@ def test_pos_create_different_cdtindex_multiple_times_same_bin(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_STRING, "test_string_list_cdt_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) if retobj == 0: @@ -421,7 +442,7 @@ def test_pos_create_different_cdtindex_multiple_times_same_bin(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_STRING, "test_string_list_cdt_index1", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) except e.IndexFoundError: @@ -444,7 +465,7 @@ def test_pos_createcdtindex_with_policy(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_NUMERIC, "test_numeric_list_cdt_index_pol", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) @@ -464,7 +485,7 @@ def test_pos_createcdtindex_with_policystring(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_STRING, "test_string_list_cdt_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) @@ -501,7 +522,7 @@ def test_pos_create_liststringindex_unicode_positive(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_STRING, "uni_name_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) @@ -521,7 +542,7 @@ def test_pos_create_list_integer_index_unicode(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_NUMERIC, "uni_age_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) @@ -557,7 +578,7 @@ def test_neg_cdtindex_with_namespace_is_none(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_STRING, "test_string_list_cdt_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) @@ -578,7 +599,7 @@ def test_neg_cdtindex_with_set_is_int(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_STRING, "test_string_list_cdt_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) assert False @@ -601,7 +622,7 @@ def test_neg_cdtindex_with_set_is_none(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_STRING, "test_string_list_cdt_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) @@ -624,7 +645,7 @@ def test_neg_cdtindex_with_bin_is_none(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_NUMERIC, "test_numeric_list_cdt_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) @@ -645,7 +666,7 @@ def test_neg_cdtindex_with_index_is_none(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_STRING, None, - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) @@ -667,7 +688,7 @@ def test_neg_cdtindex_with_incorrect_namespace(self): aerospike.INDEX_TYPE_DEFAULT, aerospike.INDEX_NUMERIC, "test_numeric_list_cdt_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) @@ -686,7 +707,7 @@ def test_neg_cdtindex_with_incorrect_set(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_NUMERIC, "test_numeric_list_cdt_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) @@ -711,7 +732,7 @@ def test_neg_cdtindex_with_correct_parameters_no_connection(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_STRING, "test_string_list_cdt_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) diff --git a/test/new_tests/test_query.py b/test/new_tests/test_query.py index ac789a9ee7..ea34c51b77 100644 --- a/test/new_tests/test_query.py +++ b/test/new_tests/test_query.py @@ -151,7 +151,7 @@ def setupClass(self, as_connection): aerospike.INDEX_TYPE_DEFAULT, aerospike.INDEX_NUMERIC, "numeric_list_cdt_index", - {"ctx": ctx_list_index}, + ctx_list_index, ) except e.IndexFoundError: pass @@ -164,7 +164,7 @@ def setupClass(self, as_connection): aerospike.INDEX_TYPE_DEFAULT, aerospike.INDEX_NUMERIC, "numeric_map_cdt_index", - {"ctx": ctx_map_index}, + ctx_map_index, ) except e.IndexFoundError: pass From 78e4eff7e223147b6013803a8a93d126c7af5293 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 2 Jan 2026 15:48:54 -0800 Subject: [PATCH 09/57] Explicitly state --- src/include/conversions.h | 1 + src/main/conversions.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index 1291013264..7fe584fadb 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -173,6 +173,7 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, // The cdt_ctx parameter should point to an uninitialized as_cdt_ctx // object. This function will initialize it, and free it IF an error occurs. Otherwise, the caller must destroy // the as_cdt_ctx when it is done. +// py_cdt_ctx must be a non-NULL python object as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_cdt_ctx, bool *ctx_in_use, diff --git a/src/main/conversions.c b/src/main/conversions.c index ec2f9906fc..589d088e32 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2405,7 +2405,10 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, { as_status status = 0; - if (!py_ctx_list || !PyList_Check(py_ctx_list)) { + if (Py_IsNone(py_ctx_list)) { + goto CLEANUP5; + } + if (!PyList_Check(py_ctx_list)) { status = as_error_update(err, AEROSPIKE_ERR_PARAM, "Failed to convert %s", CTX_KEY); goto CLEANUP5; From a337395278689d1680264c604903b23748b5588a Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 2 Jan 2026 16:12:24 -0800 Subject: [PATCH 10/57] Refactor ctx conversion code for expressions --- src/main/convert_expressions.c | 21 +++++---------------- test/new_tests/test_cdt_index.py | 2 +- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/main/convert_expressions.c b/src/main/convert_expressions.c index a3a2b7f6ae..0a0761e2ea 100644 --- a/src/main/convert_expressions.c +++ b/src/main/convert_expressions.c @@ -1829,22 +1829,11 @@ as_status as_exp_new_from_pyobject(AerospikeClient *self, PyObject *py_expr, } } - //TODO Is ctx/list_policy/map_policy allocation and parsing necessary here? - //TODO Could it be moved somewhere else? - py_ctx_list_p = PyDict_GetItemString(temp_expr.pydict, CTX_KEY); - if (py_ctx_list_p != NULL) { - temp_expr.ctx = malloc(sizeof(as_cdt_ctx)); - if (temp_expr.ctx == NULL) { - as_error_update(err, AEROSPIKE_ERR, - "Could not malloc mem for temp_expr.ctx."); - goto CLEANUP; - } - - if (as_cdt_ctx_init_from_pyobject( - self, err, temp_expr.ctx, temp_expr.pydict, &ctx_in_use, - &static_pool, SERIALIZER_PYTHON) != AEROSPIKE_OK) { - goto CLEANUP; - } + as_status status = as_cdt_ctx_init_from_py_operation_dict( + self, err, temp_expr.ctx, temp_expr.pydict, &is_ctx_initialized, + &static_pool, SERIALIZER_PYTHON); + if (status != AEROSPIKE_OK) { + goto CLEANUP; } is_ctx_initialized = true; diff --git a/test/new_tests/test_cdt_index.py b/test/new_tests/test_cdt_index.py index 5c6fe70460..932c9db353 100644 --- a/test/new_tests/test_cdt_index.py +++ b/test/new_tests/test_cdt_index.py @@ -124,7 +124,7 @@ def test_pos_cdtindex_dict_with_correct_parameters(self): aerospike.INDEX_TYPE_LIST, aerospike.INDEX_STRING, "test_string_list_cdt_index", - {"ctx": ctx_list_index}, + ctx_list_index, policy, ) From e1d1a04c439482b41480011f194f9fdb3619ddaf Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 2 Jan 2026 16:28:17 -0800 Subject: [PATCH 11/57] fix compiler error --- src/main/convert_expressions.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/convert_expressions.c b/src/main/convert_expressions.c index 0a0761e2ea..967c7df48e 100644 --- a/src/main/convert_expressions.c +++ b/src/main/convert_expressions.c @@ -1769,7 +1769,6 @@ as_status as_exp_new_from_pyobject(AerospikeClient *self, PyObject *py_expr, PyObject *py_expr_tuple = NULL; PyObject *py_list_policy_p = NULL; PyObject *py_map_policy_p = NULL; - PyObject *py_ctx_list_p = NULL; as_vector intermediate_expr_queue; intermediate_expr temp_expr; as_exp_entry *c_expr_entries = NULL; From 1ee6751ca505d708adb0f6a971004c04c2f00dcf Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 2 Jan 2026 16:34:39 -0800 Subject: [PATCH 12/57] fix --- src/main/convert_expressions.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/convert_expressions.c b/src/main/convert_expressions.c index 967c7df48e..9fae327036 100644 --- a/src/main/convert_expressions.c +++ b/src/main/convert_expressions.c @@ -1765,7 +1765,6 @@ as_status as_exp_new_from_pyobject(AerospikeClient *self, PyObject *py_expr, int processed_exp_count = 0; int size_to_alloc = 0; - bool ctx_in_use = false; PyObject *py_expr_tuple = NULL; PyObject *py_list_policy_p = NULL; PyObject *py_map_policy_p = NULL; @@ -1785,7 +1784,6 @@ as_status as_exp_new_from_pyobject(AerospikeClient *self, PyObject *py_expr, for (int i = 0; i < size; ++i) { memset(&temp_expr, 0, sizeof(intermediate_expr)); - ctx_in_use = false; // Reset flag for next temp expr being built is_ctx_initialized = false; @@ -1834,7 +1832,6 @@ as_status as_exp_new_from_pyobject(AerospikeClient *self, PyObject *py_expr, if (status != AEROSPIKE_OK) { goto CLEANUP; } - is_ctx_initialized = true; py_list_policy_p = PyDict_GetItemString(temp_expr.pydict, AS_PY_LIST_POLICY); From 232dbc436a82312157168283876ea82d8522bb04 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 7 Jan 2026 16:49:42 -0800 Subject: [PATCH 13/57] Short term fix. --- src/main/conversions.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/conversions.c b/src/main/conversions.c index 589d088e32..dedb98a30d 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2584,6 +2584,10 @@ as_status as_cdt_ctx_init_from_py_operation_dict( return AEROSPIKE_OK; } + if (!cdt_ctx) { + cdt_ctx = malloc(sizeof(as_cdt_ctx)); + } + return as_cdt_ctx_init_from_pyobject(self, err, cdt_ctx, py_ctx_list, ctx_in_use, static_pool, serializer_type); From 7a1af237a64a9d43eb9c0a9a86512ef015de6c22 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Thu, 8 Jan 2026 10:35:07 -0800 Subject: [PATCH 14/57] Fix... --- src/main/convert_expressions.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/convert_expressions.c b/src/main/convert_expressions.c index cae50250ba..74c6cefc13 100644 --- a/src/main/convert_expressions.c +++ b/src/main/convert_expressions.c @@ -1769,9 +1769,11 @@ as_status as_exp_new_from_pyobject(AerospikeClient *self, PyObject *py_expr, int processed_exp_count = 0; int size_to_alloc = 0; + bool ctx_in_use = false; PyObject *py_expr_tuple = NULL; PyObject *py_list_policy_p = NULL; PyObject *py_map_policy_p = NULL; + PyObject *py_ctx_list_p = NULL; as_vector intermediate_expr_queue; intermediate_expr temp_expr; as_exp_entry *c_expr_entries = NULL; @@ -1788,6 +1790,7 @@ as_status as_exp_new_from_pyobject(AerospikeClient *self, PyObject *py_expr, for (int i = 0; i < size; ++i) { memset(&temp_expr, 0, sizeof(intermediate_expr)); + ctx_in_use = false; // Reset flag for next temp expr being built is_ctx_initialized = false; @@ -1830,12 +1833,24 @@ as_status as_exp_new_from_pyobject(AerospikeClient *self, PyObject *py_expr, } } - as_status status = as_cdt_ctx_init_from_py_operation_dict( - self, err, temp_expr.ctx, temp_expr.pydict, &is_ctx_initialized, - &static_pool, SERIALIZER_PYTHON); - if (status != AEROSPIKE_OK) { - goto CLEANUP; + //TODO Is ctx/list_policy/map_policy allocation and parsing necessary here? + //TODO Could it be moved somewhere else? + py_ctx_list_p = PyDict_GetItemString(temp_expr.pydict, CTX_KEY); + if (py_ctx_list_p != NULL) { + temp_expr.ctx = malloc(sizeof(as_cdt_ctx)); + if (temp_expr.ctx == NULL) { + as_error_update(err, AEROSPIKE_ERR, + "Could not malloc mem for temp_expr.ctx."); + goto CLEANUP; + } + + if (as_cdt_ctx_init_from_py_operation_dict( + self, err, temp_expr.ctx, temp_expr.pydict, &ctx_in_use, + &static_pool, SERIALIZER_PYTHON) != AEROSPIKE_OK) { + goto CLEANUP; + } } + is_ctx_initialized = true; py_list_policy_p = PyDict_GetItemString(temp_expr.pydict, AS_PY_LIST_POLICY); From 05c57e3cc9fd42b82216e58541bab4c2026cd40d Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Thu, 8 Jan 2026 10:40:25 -0800 Subject: [PATCH 15/57] Rename to something more generic because expressions have a dictionary called fixed that contain a ctx list --- src/include/conversions.h | 2 +- src/main/client/cdt_list_operate.c | 204 ++++++++++++++--------------- src/main/client/cdt_map_operate.c | 24 ++-- src/main/client/operate.c | 2 +- src/main/conversions.c | 2 +- src/main/convert_expressions.c | 2 +- 6 files changed, 118 insertions(+), 118 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index 7fe584fadb..78f7d70220 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -180,7 +180,7 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_static_pool *static_pool, int serializer_type); -as_status as_cdt_ctx_init_from_py_operation_dict( +as_status as_cdt_ctx_get_from_py_dict_and_init( AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_op_dict, bool *ctx_in_use, as_static_pool *static_pool, int serializer_type); diff --git a/src/main/client/cdt_list_operate.c b/src/main/client/cdt_list_operate.c index b90d732811..1c3706098a 100644 --- a/src/main/client/cdt_list_operate.c +++ b/src/main/client/cdt_list_operate.c @@ -446,9 +446,9 @@ static as_status add_op_list_get_by_index(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -494,9 +494,9 @@ add_op_list_get_by_index_range(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -543,9 +543,9 @@ static as_status add_op_list_get_by_rank(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -590,9 +590,9 @@ add_op_list_get_by_rank_range(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -638,9 +638,9 @@ static as_status add_op_list_get_by_value(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to convert ctx list"); } @@ -678,9 +678,9 @@ add_op_list_get_by_value_list(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { /* Failed to add the operation, we need to destroy the list of values*/ as_val_destroy(value_list); return err->code; @@ -728,9 +728,9 @@ add_op_list_get_by_value_range(AerospikeClient *self, as_error *err, char *bin, goto error; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { goto error; } @@ -785,9 +785,9 @@ add_op_list_remove_by_index(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -832,9 +832,9 @@ static as_status add_op_list_remove_by_index_range( return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -880,9 +880,9 @@ add_op_list_remove_by_rank(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -926,9 +926,9 @@ static as_status add_op_list_remove_by_rank_range( return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -974,9 +974,9 @@ add_op_list_remove_by_value(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } @@ -1013,9 +1013,9 @@ static as_status add_op_list_remove_by_value_list( return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { /* Failed to convert ctx, we need to destroy the list of values*/ as_val_destroy(value_list); return err->code; @@ -1060,9 +1060,9 @@ static as_status add_op_list_remove_by_value_range( goto error; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { goto error; } @@ -1112,9 +1112,9 @@ static as_status add_op_list_set_order(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1147,9 +1147,9 @@ static as_status add_op_list_sort(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1192,9 +1192,9 @@ static as_status add_op_list_create(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1237,9 +1237,9 @@ static as_status add_op_list_append(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } @@ -1282,9 +1282,9 @@ static as_status add_op_list_append_items(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(items_list); return err->code; } @@ -1332,9 +1332,9 @@ static as_status add_op_list_insert(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } @@ -1382,9 +1382,9 @@ static as_status add_op_list_insert_items(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(items_list); return err->code; } @@ -1432,9 +1432,9 @@ static as_status add_op_list_increment(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(incr); return err->code; } @@ -1470,9 +1470,9 @@ static as_status add_op_list_pop(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1509,9 +1509,9 @@ static as_status add_op_list_pop_range(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1542,9 +1542,9 @@ static as_status add_op_list_remove(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { ; return err->code; } @@ -1584,9 +1584,9 @@ static as_status add_op_list_remove_range(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1612,9 +1612,9 @@ static as_status add_op_list_clear(AerospikeClient *self, as_error *err, bool ctx_in_use = false; as_cdt_ctx ctx; - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1658,9 +1658,9 @@ static as_status add_op_list_set(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } @@ -1695,9 +1695,9 @@ static as_status add_op_list_get(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1735,9 +1735,9 @@ static as_status add_op_list_get_range(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1775,9 +1775,9 @@ static as_status add_op_list_trim(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1803,9 +1803,9 @@ static as_status add_op_list_size(AerospikeClient *self, as_error *err, bool ctx_in_use = false; as_cdt_ctx ctx; - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1852,9 +1852,9 @@ static as_status add_add_op_list_remove_by_value_rel_rank_range( return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1917,9 +1917,9 @@ static as_status add_add_op_list_get_by_value_rel_rank_range( return err->code; } - if (as_cdt_ctx_init_from_py_operation_dict( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } diff --git a/src/main/client/cdt_map_operate.c b/src/main/client/cdt_map_operate.c index 1c4809b766..b6ae39f21c 100644 --- a/src/main/client/cdt_map_operate.c +++ b/src/main/client/cdt_map_operate.c @@ -125,9 +125,9 @@ static as_status add_op_map_remove_by_value_rel_rank_range( return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -189,9 +189,9 @@ static as_status add_op_map_get_by_value_rel_rank_range( return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -253,9 +253,9 @@ static as_status add_op_map_remove_by_key_rel_index_range( return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -316,9 +316,9 @@ static as_status add_op_map_get_by_key_rel_index_range( return err->code; } - if (as_cdt_ctx_init_from_pyobject(self, err, &ctx, op_dict, &ctx_in_use, - static_pool, - serializer_type) != AEROSPIKE_OK) { + if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, + &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } diff --git a/src/main/client/operate.c b/src/main/client/operate.c index e18ee61941..1a3c7cf304 100644 --- a/src/main/client/operate.c +++ b/src/main/client/operate.c @@ -107,7 +107,7 @@ static inline bool isExprOp(int op); } #define CONVERT_PY_CTX_TO_AS_CTX() \ - if (as_cdt_ctx_init_from_py_operation_dict( \ + if (as_cdt_ctx_get_from_py_dict_and_init( \ self, err, &ctx, py_operation_dict, &ctx_in_use, static_pool, \ SERIALIZER_PYTHON) != AEROSPIKE_OK) { \ return err->code; \ diff --git a/src/main/conversions.c b/src/main/conversions.c index dedb98a30d..7ad46c576e 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2574,7 +2574,7 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, return status; } -as_status as_cdt_ctx_init_from_py_operation_dict( +as_status as_cdt_ctx_get_from_py_dict_and_init( AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_op_dict, bool *ctx_in_use, as_static_pool *static_pool, int serializer_type) diff --git a/src/main/convert_expressions.c b/src/main/convert_expressions.c index 74c6cefc13..8e546e5d55 100644 --- a/src/main/convert_expressions.c +++ b/src/main/convert_expressions.c @@ -1844,7 +1844,7 @@ as_status as_exp_new_from_pyobject(AerospikeClient *self, PyObject *py_expr, goto CLEANUP; } - if (as_cdt_ctx_init_from_py_operation_dict( + if (as_cdt_ctx_get_from_py_dict_and_init( self, err, temp_expr.ctx, temp_expr.pydict, &ctx_in_use, &static_pool, SERIALIZER_PYTHON) != AEROSPIKE_OK) { goto CLEANUP; From 5212466a05f50486827a143a9786df801244010a Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Thu, 8 Jan 2026 10:45:50 -0800 Subject: [PATCH 16/57] convert_expressions.c already mallocs the ctx obj for us --- src/main/conversions.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/conversions.c b/src/main/conversions.c index 7ad46c576e..dc6a0e356d 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2584,10 +2584,6 @@ as_status as_cdt_ctx_get_from_py_dict_and_init( return AEROSPIKE_OK; } - if (!cdt_ctx) { - cdt_ctx = malloc(sizeof(as_cdt_ctx)); - } - return as_cdt_ctx_init_from_pyobject(self, err, cdt_ctx, py_ctx_list, ctx_in_use, static_pool, serializer_type); From 9a0ef701831caa13e22e91dfd8e146a271e37219 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Thu, 8 Jan 2026 13:19:32 -0800 Subject: [PATCH 17/57] Fix tests --- test/new_tests/test_query.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/new_tests/test_query.py b/test/new_tests/test_query.py index ea34c51b77..8dd89b9ca2 100644 --- a/test/new_tests/test_query.py +++ b/test/new_tests/test_query.py @@ -1071,7 +1071,7 @@ def test_query_with_list_cdt_ctx(self): query = self.as_connection.query("test", "demo") query.select("numeric_list") - query.where(p.range("numeric_list", aerospike.INDEX_TYPE_DEFAULT, 2, 4), {"ctx": ctx_list_index}) + query.where(p.range("numeric_list", aerospike.INDEX_TYPE_DEFAULT, 2, 4), ctx_list_index) records = [] @@ -1113,7 +1113,7 @@ def test_query_with_map_cdt_ctx(self): query = self.as_connection.query("test", "demo") query.select("numeric_map") - query.where(p.range("numeric_map", aerospike.INDEX_TYPE_DEFAULT, 2, 4), {"ctx": ctx_map_index}) + query.where(p.range("numeric_map", aerospike.INDEX_TYPE_DEFAULT, 2, 4), ctx_map_index) records = [] From b8562204428f95e8f13f1e2f788c0225d92d4f04 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Thu, 8 Jan 2026 13:25:50 -0800 Subject: [PATCH 18/57] Fix tests. Not sure why invalid ctx test does not expect a ParamError --- test/new_tests/test_query.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/new_tests/test_query.py b/test/new_tests/test_query.py index 8dd89b9ca2..be99d79c02 100644 --- a/test/new_tests/test_query.py +++ b/test/new_tests/test_query.py @@ -311,8 +311,8 @@ def teardown(): [ # ctx [], - [None], - [[]] + [None] + # Empty context list raises an InvalidRequest exception ] ) def test_query_with_correct_parameters_hi(self, extra_args): @@ -1130,7 +1130,8 @@ def callback(input_tuple): def test_query_with_invalid_ctx(self): query = self.as_connection.query("test", "demo") - query.where(p.equals("bin", 1), 1) + with pytest.raises(e.ParamError): + query.where(p.equals("bin", 1), 1) def test_query_with_base64_cdt_ctx(self): bs_b4_cdt = self.as_connection.get_cdtctx_base64(ctx_list_index) From 575485cb7be88b93e9ac24af3a380fca0a76e391 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Thu, 8 Jan 2026 13:41:15 -0800 Subject: [PATCH 19/57] Just allow NULL to be safe. this was the old behavior --- src/include/conversions.h | 1 - src/main/conversions.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index 78f7d70220..a8961f7c15 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -173,7 +173,6 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, // The cdt_ctx parameter should point to an uninitialized as_cdt_ctx // object. This function will initialize it, and free it IF an error occurs. Otherwise, the caller must destroy // the as_cdt_ctx when it is done. -// py_cdt_ctx must be a non-NULL python object as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_cdt_ctx, bool *ctx_in_use, diff --git a/src/main/conversions.c b/src/main/conversions.c index dc6a0e356d..4892d550c4 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2405,10 +2405,10 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, { as_status status = 0; - if (Py_IsNone(py_ctx_list)) { + if (!py_ctx_list || Py_IsNone(py_ctx_list)) { goto CLEANUP5; } - if (!PyList_Check(py_ctx_list)) { + else if (!PyList_Check(py_ctx_list)) { status = as_error_update(err, AEROSPIKE_ERR_PARAM, "Failed to convert %s", CTX_KEY); goto CLEANUP5; From fa6de73d42bd30d0221f7cbca2da43481a600596 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Thu, 8 Jan 2026 13:44:17 -0800 Subject: [PATCH 20/57] Remove duplicate test case --- test/new_tests/test_cdt_index.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/test/new_tests/test_cdt_index.py b/test/new_tests/test_cdt_index.py index 932c9db353..49c7916e7c 100644 --- a/test/new_tests/test_cdt_index.py +++ b/test/new_tests/test_cdt_index.py @@ -112,27 +112,6 @@ def test_pos_cdtindex_with_correct_parameters(self): assert retobj == 0 - def test_pos_cdtindex_dict_with_correct_parameters(self): - """ - Invoke index_cdt_create() with correct arguments - """ - policy = {} - retobj = self.as_connection.index_cdt_create( - "test", - "demo", - "string_list", - aerospike.INDEX_TYPE_LIST, - aerospike.INDEX_STRING, - "test_string_list_cdt_index", - ctx_list_index, - policy, - ) - - self.as_connection.index_remove("test", "test_string_list_cdt_index", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_list_cdt_index") - - assert retobj == 0 - def test_pos_cdtindex_with_info_command(self): """ Invoke index_cdt_create() with info command From 80996c4353ccaae957ecee4d7b6180f6cd126bde Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Thu, 8 Jan 2026 13:49:11 -0800 Subject: [PATCH 21/57] Add negative input test for index_cdt_create --- test/new_tests/test_cdt_index.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/new_tests/test_cdt_index.py b/test/new_tests/test_cdt_index.py index 49c7916e7c..bcb81875f6 100644 --- a/test/new_tests/test_cdt_index.py +++ b/test/new_tests/test_cdt_index.py @@ -726,3 +726,15 @@ def test_neg_cdtindex_with_no_paramters(self): self.as_connection.index_cdt_create() assert "argument 'ns' (pos 1)" in str(typeError.value) + + def test_neg_cdtindex_with_invalid_ctx(self): + with pytest.raises(TypeError) as typeError: + self.as_connection.index_cdt_create( + ns="test", + set="demo", + bin="string_list", + index_type=aerospike.INDEX_TYPE_LIST, + index_datatype=aerospike.INDEX_STRING, + name="test_string_list_cdt_index", + ctx={"ctx": ctx_list_index}, + ) From d9a891c43ecd1020379c05107bddba5e6c3c34d8 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Thu, 8 Jan 2026 14:04:57 -0800 Subject: [PATCH 22/57] Fix test.... --- test/new_tests/test_cdt_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/new_tests/test_cdt_index.py b/test/new_tests/test_cdt_index.py index bcb81875f6..e1579c5a56 100644 --- a/test/new_tests/test_cdt_index.py +++ b/test/new_tests/test_cdt_index.py @@ -728,7 +728,7 @@ def test_neg_cdtindex_with_no_paramters(self): assert "argument 'ns' (pos 1)" in str(typeError.value) def test_neg_cdtindex_with_invalid_ctx(self): - with pytest.raises(TypeError) as typeError: + with pytest.raises(e.ParamError): self.as_connection.index_cdt_create( ns="test", set="demo", From 5874e8d8cc63e1f88754393c3c949ca005200e75 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Thu, 8 Jan 2026 17:14:52 -0800 Subject: [PATCH 23/57] this is much cleaner --- src/main/query/where.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/query/where.c b/src/main/query/where.c index 0d48289f1f..b30a1c2993 100644 --- a/src/main/query/where.c +++ b/src/main/query/where.c @@ -65,16 +65,15 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, // TODO: does static pool go out of scope? as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); - pctx = cf_malloc(sizeof(as_cdt_ctx)); - memset(pctx, 0, sizeof(as_cdt_ctx)); + + if (PyList_Check(py_ctx)) { + pctx = cf_malloc(sizeof(as_cdt_ctx)); + } + if (as_cdt_ctx_init_from_pyobject(self->client, &err, pctx, py_ctx, &ctx_in_use, &static_pool, SERIALIZER_PYTHON) != AEROSPIKE_OK) { - return err.code; - } - if (!ctx_in_use) { - cf_free(pctx); - pctx = NULL; + goto CLEANUP_CTX_ON_ERROR; } } From 302e182497e5ae983650adc723380dc63cb17ce7 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Thu, 8 Jan 2026 17:17:50 -0800 Subject: [PATCH 24/57] Clear up --- src/include/conversions.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index a8961f7c15..4184218a02 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -171,8 +171,8 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, // and converts it to an as_cdt_ctx object for use with the c-client. // // The cdt_ctx parameter should point to an uninitialized as_cdt_ctx -// object. This function will initialize it, and free it IF an error occurs. Otherwise, the caller must destroy -// the as_cdt_ctx when it is done. +// object. This function will initialize it, and call as_cdt_ctx_destroy on it IF an error occurs. Otherwise, the caller +// must do it themselves when they are done with the object. as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_cdt_ctx, bool *ctx_in_use, From ff5e48aa4b473b75274d1d42ef929ae38126448e Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 09:08:45 -0800 Subject: [PATCH 25/57] Rename to something more helpful --- src/include/conversions.h | 2 +- src/main/client/cdt_list_operate.c | 204 ++++++++++++++--------------- src/main/client/cdt_map_operate.c | 24 ++-- src/main/client/operate.c | 2 +- src/main/conversions.c | 2 +- src/main/convert_expressions.c | 2 +- 6 files changed, 118 insertions(+), 118 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index 4184218a02..4b991e8d77 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -179,7 +179,7 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_static_pool *static_pool, int serializer_type); -as_status as_cdt_ctx_get_from_py_dict_and_init( +as_status get_optional_as_cdt_ctx_from_py_dict_and_init( AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_op_dict, bool *ctx_in_use, as_static_pool *static_pool, int serializer_type); diff --git a/src/main/client/cdt_list_operate.c b/src/main/client/cdt_list_operate.c index 1c3706098a..2d3ec3576a 100644 --- a/src/main/client/cdt_list_operate.c +++ b/src/main/client/cdt_list_operate.c @@ -446,9 +446,9 @@ static as_status add_op_list_get_by_index(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -494,9 +494,9 @@ add_op_list_get_by_index_range(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -543,9 +543,9 @@ static as_status add_op_list_get_by_rank(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -590,9 +590,9 @@ add_op_list_get_by_rank_range(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -638,9 +638,9 @@ static as_status add_op_list_get_by_value(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to convert ctx list"); } @@ -678,9 +678,9 @@ add_op_list_get_by_value_list(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { /* Failed to add the operation, we need to destroy the list of values*/ as_val_destroy(value_list); return err->code; @@ -728,9 +728,9 @@ add_op_list_get_by_value_range(AerospikeClient *self, as_error *err, char *bin, goto error; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { goto error; } @@ -785,9 +785,9 @@ add_op_list_remove_by_index(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -832,9 +832,9 @@ static as_status add_op_list_remove_by_index_range( return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -880,9 +880,9 @@ add_op_list_remove_by_rank(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -926,9 +926,9 @@ static as_status add_op_list_remove_by_rank_range( return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -974,9 +974,9 @@ add_op_list_remove_by_value(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } @@ -1013,9 +1013,9 @@ static as_status add_op_list_remove_by_value_list( return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { /* Failed to convert ctx, we need to destroy the list of values*/ as_val_destroy(value_list); return err->code; @@ -1060,9 +1060,9 @@ static as_status add_op_list_remove_by_value_range( goto error; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { goto error; } @@ -1112,9 +1112,9 @@ static as_status add_op_list_set_order(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1147,9 +1147,9 @@ static as_status add_op_list_sort(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1192,9 +1192,9 @@ static as_status add_op_list_create(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1237,9 +1237,9 @@ static as_status add_op_list_append(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } @@ -1282,9 +1282,9 @@ static as_status add_op_list_append_items(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(items_list); return err->code; } @@ -1332,9 +1332,9 @@ static as_status add_op_list_insert(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } @@ -1382,9 +1382,9 @@ static as_status add_op_list_insert_items(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(items_list); return err->code; } @@ -1432,9 +1432,9 @@ static as_status add_op_list_increment(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(incr); return err->code; } @@ -1470,9 +1470,9 @@ static as_status add_op_list_pop(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1509,9 +1509,9 @@ static as_status add_op_list_pop_range(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1542,9 +1542,9 @@ static as_status add_op_list_remove(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { ; return err->code; } @@ -1584,9 +1584,9 @@ static as_status add_op_list_remove_range(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1612,9 +1612,9 @@ static as_status add_op_list_clear(AerospikeClient *self, as_error *err, bool ctx_in_use = false; as_cdt_ctx ctx; - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1658,9 +1658,9 @@ static as_status add_op_list_set(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } @@ -1695,9 +1695,9 @@ static as_status add_op_list_get(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1735,9 +1735,9 @@ static as_status add_op_list_get_range(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1775,9 +1775,9 @@ static as_status add_op_list_trim(AerospikeClient *self, as_error *err, return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1803,9 +1803,9 @@ static as_status add_op_list_size(AerospikeClient *self, as_error *err, bool ctx_in_use = false; as_cdt_ctx ctx; - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1852,9 +1852,9 @@ static as_status add_add_op_list_remove_by_value_rel_rank_range( return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -1917,9 +1917,9 @@ static as_status add_add_op_list_get_by_value_rel_rank_range( return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } diff --git a/src/main/client/cdt_map_operate.c b/src/main/client/cdt_map_operate.c index b6ae39f21c..ce7e8651cd 100644 --- a/src/main/client/cdt_map_operate.c +++ b/src/main/client/cdt_map_operate.c @@ -125,9 +125,9 @@ static as_status add_op_map_remove_by_value_rel_rank_range( return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -189,9 +189,9 @@ static as_status add_op_map_get_by_value_rel_rank_range( return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -253,9 +253,9 @@ static as_status add_op_map_remove_by_key_rel_index_range( return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } @@ -316,9 +316,9 @@ static as_status add_op_map_get_by_key_rel_index_range( return err->code; } - if (as_cdt_ctx_get_from_py_dict_and_init(self, err, &ctx, op_dict, - &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + if (get_optional_as_cdt_ctx_from_py_dict_and_init( + self, err, &ctx, op_dict, &ctx_in_use, static_pool, + serializer_type) != AEROSPIKE_OK) { return err->code; } diff --git a/src/main/client/operate.c b/src/main/client/operate.c index 1a3c7cf304..d3064258aa 100644 --- a/src/main/client/operate.c +++ b/src/main/client/operate.c @@ -107,7 +107,7 @@ static inline bool isExprOp(int op); } #define CONVERT_PY_CTX_TO_AS_CTX() \ - if (as_cdt_ctx_get_from_py_dict_and_init( \ + if (get_optional_as_cdt_ctx_from_py_dict_and_init( \ self, err, &ctx, py_operation_dict, &ctx_in_use, static_pool, \ SERIALIZER_PYTHON) != AEROSPIKE_OK) { \ return err->code; \ diff --git a/src/main/conversions.c b/src/main/conversions.c index 4892d550c4..9af5a0745e 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2574,7 +2574,7 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, return status; } -as_status as_cdt_ctx_get_from_py_dict_and_init( +as_status get_optional_as_cdt_ctx_from_py_dict_and_init( AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_op_dict, bool *ctx_in_use, as_static_pool *static_pool, int serializer_type) diff --git a/src/main/convert_expressions.c b/src/main/convert_expressions.c index 8e546e5d55..8bd6b51a70 100644 --- a/src/main/convert_expressions.c +++ b/src/main/convert_expressions.c @@ -1844,7 +1844,7 @@ as_status as_exp_new_from_pyobject(AerospikeClient *self, PyObject *py_expr, goto CLEANUP; } - if (as_cdt_ctx_get_from_py_dict_and_init( + if (get_optional_as_cdt_ctx_from_py_dict_and_init( self, err, temp_expr.ctx, temp_expr.pydict, &ctx_in_use, &static_pool, SERIALIZER_PYTHON) != AEROSPIKE_OK) { goto CLEANUP; From d99892ac7c423fc5ac108d51b9ed9d67c682b46e Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 09:12:05 -0800 Subject: [PATCH 26/57] this makes more sense. remove unused var --- src/main/convert_expressions.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/convert_expressions.c b/src/main/convert_expressions.c index 8bd6b51a70..076d98d3a2 100644 --- a/src/main/convert_expressions.c +++ b/src/main/convert_expressions.c @@ -1769,7 +1769,6 @@ as_status as_exp_new_from_pyobject(AerospikeClient *self, PyObject *py_expr, int processed_exp_count = 0; int size_to_alloc = 0; - bool ctx_in_use = false; PyObject *py_expr_tuple = NULL; PyObject *py_list_policy_p = NULL; PyObject *py_map_policy_p = NULL; @@ -1790,7 +1789,6 @@ as_status as_exp_new_from_pyobject(AerospikeClient *self, PyObject *py_expr, for (int i = 0; i < size; ++i) { memset(&temp_expr, 0, sizeof(intermediate_expr)); - ctx_in_use = false; // Reset flag for next temp expr being built is_ctx_initialized = false; @@ -1845,12 +1843,12 @@ as_status as_exp_new_from_pyobject(AerospikeClient *self, PyObject *py_expr, } if (get_optional_as_cdt_ctx_from_py_dict_and_init( - self, err, temp_expr.ctx, temp_expr.pydict, &ctx_in_use, - &static_pool, SERIALIZER_PYTHON) != AEROSPIKE_OK) { + self, err, temp_expr.ctx, temp_expr.pydict, + &is_ctx_initialized, &static_pool, + SERIALIZER_PYTHON) != AEROSPIKE_OK) { goto CLEANUP; } } - is_ctx_initialized = true; py_list_policy_p = PyDict_GetItemString(temp_expr.pydict, AS_PY_LIST_POLICY); From 9c80ab733a5dac6d6490214c0d614e96326648bb Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 09:14:54 -0800 Subject: [PATCH 27/57] Improve naming --- src/include/conversions.h | 2 +- src/main/client/cdt_list_operate.c | 68 +++++++++++++++--------------- src/main/client/cdt_map_operate.c | 8 ++-- src/main/client/operate.c | 2 +- src/main/conversions.c | 2 +- src/main/convert_expressions.c | 2 +- 6 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index 4b991e8d77..9b697492a9 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -179,7 +179,7 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_static_pool *static_pool, int serializer_type); -as_status get_optional_as_cdt_ctx_from_py_dict_and_init( +as_status get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_op_dict, bool *ctx_in_use, as_static_pool *static_pool, int serializer_type); diff --git a/src/main/client/cdt_list_operate.c b/src/main/client/cdt_list_operate.c index 2d3ec3576a..ee15d9d9f7 100644 --- a/src/main/client/cdt_list_operate.c +++ b/src/main/client/cdt_list_operate.c @@ -446,7 +446,7 @@ static as_status add_op_list_get_by_index(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -494,7 +494,7 @@ add_op_list_get_by_index_range(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -543,7 +543,7 @@ static as_status add_op_list_get_by_rank(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -590,7 +590,7 @@ add_op_list_get_by_rank_range(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -638,7 +638,7 @@ static as_status add_op_list_get_by_value(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { as_error_update(err, AEROSPIKE_ERR_CLIENT, @@ -678,7 +678,7 @@ add_op_list_get_by_value_list(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { /* Failed to add the operation, we need to destroy the list of values*/ @@ -728,7 +728,7 @@ add_op_list_get_by_value_range(AerospikeClient *self, as_error *err, char *bin, goto error; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { goto error; @@ -785,7 +785,7 @@ add_op_list_remove_by_index(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -832,7 +832,7 @@ static as_status add_op_list_remove_by_index_range( return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -880,7 +880,7 @@ add_op_list_remove_by_rank(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -926,7 +926,7 @@ static as_status add_op_list_remove_by_rank_range( return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -974,7 +974,7 @@ add_op_list_remove_by_value(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); @@ -1013,7 +1013,7 @@ static as_status add_op_list_remove_by_value_list( return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { /* Failed to convert ctx, we need to destroy the list of values*/ @@ -1060,7 +1060,7 @@ static as_status add_op_list_remove_by_value_range( goto error; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { goto error; @@ -1112,7 +1112,7 @@ static as_status add_op_list_set_order(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -1147,7 +1147,7 @@ static as_status add_op_list_sort(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -1192,7 +1192,7 @@ static as_status add_op_list_create(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -1237,7 +1237,7 @@ static as_status add_op_list_append(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); @@ -1282,7 +1282,7 @@ static as_status add_op_list_append_items(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { as_val_destroy(items_list); @@ -1332,7 +1332,7 @@ static as_status add_op_list_insert(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); @@ -1382,7 +1382,7 @@ static as_status add_op_list_insert_items(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { as_val_destroy(items_list); @@ -1432,7 +1432,7 @@ static as_status add_op_list_increment(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { as_val_destroy(incr); @@ -1470,7 +1470,7 @@ static as_status add_op_list_pop(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -1509,7 +1509,7 @@ static as_status add_op_list_pop_range(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -1542,7 +1542,7 @@ static as_status add_op_list_remove(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { ; @@ -1584,7 +1584,7 @@ static as_status add_op_list_remove_range(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -1612,7 +1612,7 @@ static as_status add_op_list_clear(AerospikeClient *self, as_error *err, bool ctx_in_use = false; as_cdt_ctx ctx; - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -1658,7 +1658,7 @@ static as_status add_op_list_set(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { as_val_destroy(val); @@ -1695,7 +1695,7 @@ static as_status add_op_list_get(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -1735,7 +1735,7 @@ static as_status add_op_list_get_range(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -1775,7 +1775,7 @@ static as_status add_op_list_trim(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -1803,7 +1803,7 @@ static as_status add_op_list_size(AerospikeClient *self, as_error *err, bool ctx_in_use = false; as_cdt_ctx ctx; - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -1852,7 +1852,7 @@ static as_status add_add_op_list_remove_by_value_rel_rank_range( return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -1917,7 +1917,7 @@ static as_status add_add_op_list_get_by_value_rel_rank_range( return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; diff --git a/src/main/client/cdt_map_operate.c b/src/main/client/cdt_map_operate.c index ce7e8651cd..a4976ca8e3 100644 --- a/src/main/client/cdt_map_operate.c +++ b/src/main/client/cdt_map_operate.c @@ -125,7 +125,7 @@ static as_status add_op_map_remove_by_value_rel_rank_range( return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -189,7 +189,7 @@ static as_status add_op_map_get_by_value_rel_rank_range( return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -253,7 +253,7 @@ static as_status add_op_map_remove_by_key_rel_index_range( return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; @@ -316,7 +316,7 @@ static as_status add_op_map_get_by_key_rel_index_range( return err->code; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; diff --git a/src/main/client/operate.c b/src/main/client/operate.c index d3064258aa..2b20d91a0c 100644 --- a/src/main/client/operate.c +++ b/src/main/client/operate.c @@ -107,7 +107,7 @@ static inline bool isExprOp(int op); } #define CONVERT_PY_CTX_TO_AS_CTX() \ - if (get_optional_as_cdt_ctx_from_py_dict_and_init( \ + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( \ self, err, &ctx, py_operation_dict, &ctx_in_use, static_pool, \ SERIALIZER_PYTHON) != AEROSPIKE_OK) { \ return err->code; \ diff --git a/src/main/conversions.c b/src/main/conversions.c index 9af5a0745e..5207bdfd2f 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2574,7 +2574,7 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, return status; } -as_status get_optional_as_cdt_ctx_from_py_dict_and_init( +as_status get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_op_dict, bool *ctx_in_use, as_static_pool *static_pool, int serializer_type) diff --git a/src/main/convert_expressions.c b/src/main/convert_expressions.c index 076d98d3a2..24282fac6e 100644 --- a/src/main/convert_expressions.c +++ b/src/main/convert_expressions.c @@ -1842,7 +1842,7 @@ as_status as_exp_new_from_pyobject(AerospikeClient *self, PyObject *py_expr, goto CLEANUP; } - if (get_optional_as_cdt_ctx_from_py_dict_and_init( + if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, temp_expr.ctx, temp_expr.pydict, &is_ctx_initialized, &static_pool, SERIALIZER_PYTHON) != AEROSPIKE_OK) { From 12343cfbb070a18d615095a8a8337f67ba7dbc2d Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 09:31:58 -0800 Subject: [PATCH 28/57] Rename var to something more helpful --- src/include/conversions.h | 7 ++++--- src/main/client/get_cdtctx_base64.c | 10 +++++----- src/main/client/sec_index.c | 8 ++++---- src/main/conversions.c | 13 +++++++------ src/main/query/where.c | 12 ++++++------ 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index 9b697492a9..28e98b8cf2 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -175,14 +175,15 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, // must do it themselves when they are done with the object. as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, - PyObject *py_cdt_ctx, bool *ctx_in_use, + PyObject *py_cdt_ctx, + bool *was_cdt_ctx_initialized, as_static_pool *static_pool, int serializer_type); as_status get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, - PyObject *py_op_dict, bool *ctx_in_use, as_static_pool *static_pool, - int serializer_type); + PyObject *py_op_dict, bool *was_cdt_ctx_initialized, + as_static_pool *static_pool, int serializer_type); // allow_base64_encoded_exprs: can the Python object also be a Python unicode object (base64 encoded)? // if false, the Python object should only be a compiled Python expression object from aerospike_helpers diff --git a/src/main/client/get_cdtctx_base64.c b/src/main/client/get_cdtctx_base64.c index ef68c99159..798fd6cadc 100644 --- a/src/main/client/get_cdtctx_base64.c +++ b/src/main/client/get_cdtctx_base64.c @@ -45,7 +45,7 @@ PyObject *AerospikeClient_GetCDTCTXBase64(AerospikeClient *self, PyObject *args, // function args PyObject *py_cdtctx = NULL; as_cdt_ctx ctx; - bool ctx_in_use = false; + bool was_cdt_ctx_initialized = false; char *base64 = NULL; PyObject *py_response = NULL; @@ -74,12 +74,12 @@ PyObject *AerospikeClient_GetCDTCTXBase64(AerospikeClient *self, PyObject *args, as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); - if (as_cdt_ctx_init_from_pyobject(self, &err, &ctx, py_cdtctx, &ctx_in_use, - &static_pool, + if (as_cdt_ctx_init_from_pyobject(self, &err, &ctx, py_cdtctx, + &was_cdt_ctx_initialized, &static_pool, SERIALIZER_PYTHON) != AEROSPIKE_OK) { goto CLEANUP; } - if (!ctx_in_use) { + if (!was_cdt_ctx_initialized) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "cdt ctx must be valid " ", generated by aerospike cdt context helper"); @@ -99,7 +99,7 @@ PyObject *AerospikeClient_GetCDTCTXBase64(AerospikeClient *self, PyObject *args, CLEANUP: - if (ctx_in_use) { + if (was_cdt_ctx_initialized) { as_cdt_ctx_destroy(&ctx); } diff --git a/src/main/client/sec_index.c b/src/main/client/sec_index.c index 72904ac116..585dc4acff 100644 --- a/src/main/client/sec_index.c +++ b/src/main/client/sec_index.c @@ -221,7 +221,7 @@ PyObject *AerospikeClient_Index_Cdt_Create(AerospikeClient *self, PyObject *py_name = NULL; PyObject *py_ctx = NULL; as_cdt_ctx ctx; - bool ctx_in_use = false; + bool was_cdt_ctx_initialized = false; PyObject *py_obj = NULL; as_index_datatype data_type; as_index_type index_type; @@ -250,12 +250,12 @@ PyObject *AerospikeClient_Index_Cdt_Create(AerospikeClient *self, as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); - if (as_cdt_ctx_init_from_pyobject(self, &err, &ctx, py_ctx, &ctx_in_use, - &static_pool, + if (as_cdt_ctx_init_from_pyobject(self, &err, &ctx, py_ctx, + &was_cdt_ctx_initialized, &static_pool, SERIALIZER_PYTHON) != AEROSPIKE_OK) { goto CLEANUP; } - if (!ctx_in_use) { + if (!was_cdt_ctx_initialized) { goto CLEANUP; } diff --git a/src/main/conversions.c b/src/main/conversions.c index 5207bdfd2f..9f2aabe361 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2399,7 +2399,8 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, - PyObject *py_ctx_list, bool *ctx_in_use, + PyObject *py_ctx_list, + bool *was_as_cdt_ctx_initialized, as_static_pool *static_pool, int serializer_type) { @@ -2559,7 +2560,7 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, Py_DECREF(py_extra_args); } - *ctx_in_use = true; + *was_as_cdt_ctx_initialized = true; return AEROSPIKE_OK; CLEANUP1: @@ -2576,8 +2577,8 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_status get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, - PyObject *py_op_dict, bool *ctx_in_use, as_static_pool *static_pool, - int serializer_type) + PyObject *py_op_dict, bool *was_as_cdt_ctx_initialized, + as_static_pool *static_pool, int serializer_type) { PyObject *py_ctx_list = PyDict_GetItemString(py_op_dict, CTX_KEY); if (!py_ctx_list) { @@ -2585,8 +2586,8 @@ as_status get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( } return as_cdt_ctx_init_from_pyobject(self, err, cdt_ctx, py_ctx_list, - ctx_in_use, static_pool, - serializer_type); + was_as_cdt_ctx_initialized, + static_pool, serializer_type); } static bool requires_int(uint64_t op) diff --git a/src/main/query/where.c b/src/main/query/where.c index b30a1c2993..18fee1f8f5 100644 --- a/src/main/query/where.c +++ b/src/main/query/where.c @@ -59,7 +59,7 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, as_error err; as_error_init(&err); as_cdt_ctx *pctx = NULL; - bool ctx_in_use = false; + bool was_cdt_ctx_initialized = false; if (py_ctx) { // TODO: does static pool go out of scope? @@ -70,9 +70,9 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, pctx = cf_malloc(sizeof(as_cdt_ctx)); } - if (as_cdt_ctx_init_from_pyobject(self->client, &err, pctx, py_ctx, - &ctx_in_use, &static_pool, - SERIALIZER_PYTHON) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject( + self->client, &err, pctx, py_ctx, &was_cdt_ctx_initialized, + &static_pool, SERIALIZER_PYTHON) != AEROSPIKE_OK) { goto CLEANUP_CTX_ON_ERROR; } } @@ -265,7 +265,7 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, goto CLEANUP_VALUES_ON_ERROR; } - if (ctx_in_use) { + if (was_cdt_ctx_initialized) { self->query.where.entries[0].ctx_free = true; } if (exp_list) { @@ -292,7 +292,7 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, CLEANUP_CTX_ON_ERROR: // The ctx ends up not being used by as_query - if (ctx_in_use) { + if (was_cdt_ctx_initialized) { as_cdt_ctx_destroy(pctx); } if (pctx) { From 6632640aa26cdedbfa80f1e8dbb08e7d832d2c17 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 09:49:12 -0800 Subject: [PATCH 29/57] Create helper function to heap allocate as_cdt_ctx since there is an API for that in the c client --- src/include/conversions.h | 7 +++++++ src/main/conversions.c | 16 ++++++++++++++++ src/main/query/where.c | 11 ++++------- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index 28e98b8cf2..184b7ef266 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -167,6 +167,13 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, PyObject **pyuni_r, char **c_str_ptr, as_error *err); +as_status as_cdt_ctx_create_from_pyobject(AerospikeClient *self, as_error *err, + as_cdt_ctx **cdt_ctx, + PyObject *py_ctx_list, + bool *was_as_cdt_ctx_initialized, + as_static_pool *static_pool, + int serializer_type); + // This function takes in a python list of contexts from aerospike_helpers.cdt_ctx // and converts it to an as_cdt_ctx object for use with the c-client. // diff --git a/src/main/conversions.c b/src/main/conversions.c index 9f2aabe361..2a3d9cd0db 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2397,6 +2397,22 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, return as_error_update(err, AEROSPIKE_ERR_PARAM, "String value required"); } +as_status as_cdt_ctx_create_from_pyobject(AerospikeClient *self, as_error *err, + as_cdt_ctx **cdt_ctx, + PyObject *py_ctx_list, + bool *was_as_cdt_ctx_initialized, + as_static_pool *static_pool, + int serializer_type) +{ + if (py_ctx_list && PyList_Check(py_ctx_list)) { + *cdt_ctx = cf_malloc(sizeof(as_cdt_ctx)); + + return as_cdt_ctx_init_from_pyobject(self, err, *cdt_ctx, py_ctx_list, + was_as_cdt_ctx_initialized, + static_pool, serializer_type); + } +} + as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_ctx_list, diff --git a/src/main/query/where.c b/src/main/query/where.c index 18fee1f8f5..95c718ba68 100644 --- a/src/main/query/where.c +++ b/src/main/query/where.c @@ -66,13 +66,10 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); - if (PyList_Check(py_ctx)) { - pctx = cf_malloc(sizeof(as_cdt_ctx)); - } - - if (as_cdt_ctx_init_from_pyobject( - self->client, &err, pctx, py_ctx, &was_cdt_ctx_initialized, - &static_pool, SERIALIZER_PYTHON) != AEROSPIKE_OK) { + pctx = as_cdt_ctx_create_from_pyobject(self->client, &err, pctx, py_ctx, + &was_cdt_ctx_initialized, + &static_pool, SERIALIZER_PYTHON); + if (err.code != AEROSPIKE_OK) { goto CLEANUP_CTX_ON_ERROR; } } From ad0482738696e5294b0fbbe610ba076144f40070 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 10:11:26 -0800 Subject: [PATCH 30/57] In case ctx is None or not set, just return AEROSPIKE_OK assuming the ctx pointer was originally pointing to NULL --- src/main/conversions.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/conversions.c b/src/main/conversions.c index 2a3d9cd0db..ffe468e74f 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2411,6 +2411,7 @@ as_status as_cdt_ctx_create_from_pyobject(AerospikeClient *self, as_error *err, was_as_cdt_ctx_initialized, static_pool, serializer_type); } + return AEROSPIKE_OK; } as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, From ed7d4004bfe5fe6964581e09b34e239d771ac673 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 10:13:11 -0800 Subject: [PATCH 31/57] fix --- src/main/query/where.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/query/where.c b/src/main/query/where.c index 95c718ba68..73c8f67a47 100644 --- a/src/main/query/where.c +++ b/src/main/query/where.c @@ -66,8 +66,8 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); - pctx = as_cdt_ctx_create_from_pyobject(self->client, &err, pctx, py_ctx, - &was_cdt_ctx_initialized, + pctx = as_cdt_ctx_create_from_pyobject(self->client, &err, &pctx, + py_ctx, &was_cdt_ctx_initialized, &static_pool, SERIALIZER_PYTHON); if (err.code != AEROSPIKE_OK) { goto CLEANUP_CTX_ON_ERROR; From edd0ed35357917139d7e83a9951f27e059ef7b75 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 10:21:56 -0800 Subject: [PATCH 32/57] I think this is correct --- src/include/conversions.h | 12 ++++++------ src/main/conversions.c | 30 ++++++++++++++++++------------ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index 184b7ef266..bf5d4a6d0e 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -167,12 +167,12 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, PyObject **pyuni_r, char **c_str_ptr, as_error *err); -as_status as_cdt_ctx_create_from_pyobject(AerospikeClient *self, as_error *err, - as_cdt_ctx **cdt_ctx, - PyObject *py_ctx_list, - bool *was_as_cdt_ctx_initialized, - as_static_pool *static_pool, - int serializer_type); +as_cdt_ctx *as_cdt_ctx_create_from_pyobject(AerospikeClient *self, + as_error *err, as_cdt_ctx **cdt_ctx, + PyObject *py_ctx_list, + bool *was_as_cdt_ctx_initialized, + as_static_pool *static_pool, + int serializer_type); // This function takes in a python list of contexts from aerospike_helpers.cdt_ctx // and converts it to an as_cdt_ctx object for use with the c-client. diff --git a/src/main/conversions.c b/src/main/conversions.c index ffe468e74f..ea31dafd1c 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2397,21 +2397,27 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, return as_error_update(err, AEROSPIKE_ERR_PARAM, "String value required"); } -as_status as_cdt_ctx_create_from_pyobject(AerospikeClient *self, as_error *err, - as_cdt_ctx **cdt_ctx, - PyObject *py_ctx_list, - bool *was_as_cdt_ctx_initialized, - as_static_pool *static_pool, - int serializer_type) +as_cdt_ctx *as_cdt_ctx_create_from_pyobject(AerospikeClient *self, + as_error *err, + PyObject *py_ctx_list, + bool *was_as_cdt_ctx_initialized, + as_static_pool *static_pool, + int serializer_type) { - if (py_ctx_list && PyList_Check(py_ctx_list)) { - *cdt_ctx = cf_malloc(sizeof(as_cdt_ctx)); + if (!py_ctx_list || Py_IsNone(py_ctx_list)) { + return NULL; + } + as_cdt_ctx *cdt_ctx = cf_malloc(sizeof(as_cdt_ctx)); - return as_cdt_ctx_init_from_pyobject(self, err, *cdt_ctx, py_ctx_list, - was_as_cdt_ctx_initialized, - static_pool, serializer_type); + as_cdt_ctx_init_from_pyobject(self, err, cdt_ctx, py_ctx_list, + was_as_cdt_ctx_initialized, static_pool, + serializer_type); + if (err->code != AEROSPIKE_OK) { + cf_free(cdt_ctx); + return NULL; } - return AEROSPIKE_OK; + + return cdt_ctx; } as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, From 97fa3c61cda935c567f7e7320d87263ab711cecc Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 10:23:59 -0800 Subject: [PATCH 33/57] fix --- src/include/conversions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index bf5d4a6d0e..ae07737c92 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -168,7 +168,7 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, as_error *err); as_cdt_ctx *as_cdt_ctx_create_from_pyobject(AerospikeClient *self, - as_error *err, as_cdt_ctx **cdt_ctx, + as_error *err, PyObject *py_ctx_list, bool *was_as_cdt_ctx_initialized, as_static_pool *static_pool, From 55d5a7757f89522cbe1c0a248bf0344886573985 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 10:24:27 -0800 Subject: [PATCH 34/57] Fix --- src/main/query/where.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/query/where.c b/src/main/query/where.c index 73c8f67a47..400cbf2dfe 100644 --- a/src/main/query/where.c +++ b/src/main/query/where.c @@ -66,8 +66,8 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); - pctx = as_cdt_ctx_create_from_pyobject(self->client, &err, &pctx, - py_ctx, &was_cdt_ctx_initialized, + pctx = as_cdt_ctx_create_from_pyobject(self->client, &err, py_ctx, + &was_cdt_ctx_initialized, &static_pool, SERIALIZER_PYTHON); if (err.code != AEROSPIKE_OK) { goto CLEANUP_CTX_ON_ERROR; From bcfc356cd2f58a514d00d7b2172688f18ed1f528 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 10:34:56 -0800 Subject: [PATCH 35/57] this should work --- src/include/conversions.h | 5 ++--- src/main/client/get_cdtctx_base64.c | 15 +++++---------- src/main/client/sec_index.c | 9 +++------ src/main/conversions.c | 20 ++++++++++---------- src/main/query/where.c | 6 +----- 5 files changed, 21 insertions(+), 34 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index ae07737c92..95bab24b29 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -170,7 +170,6 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, as_cdt_ctx *as_cdt_ctx_create_from_pyobject(AerospikeClient *self, as_error *err, PyObject *py_ctx_list, - bool *was_as_cdt_ctx_initialized, as_static_pool *static_pool, int serializer_type); @@ -183,9 +182,9 @@ as_cdt_ctx *as_cdt_ctx_create_from_pyobject(AerospikeClient *self, as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_cdt_ctx, - bool *was_cdt_ctx_initialized, as_static_pool *static_pool, - int serializer_type); + int serializer_type, + bool is_cdt_ctx_optional); as_status get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, diff --git a/src/main/client/get_cdtctx_base64.c b/src/main/client/get_cdtctx_base64.c index 798fd6cadc..98fd773af6 100644 --- a/src/main/client/get_cdtctx_base64.c +++ b/src/main/client/get_cdtctx_base64.c @@ -45,7 +45,6 @@ PyObject *AerospikeClient_GetCDTCTXBase64(AerospikeClient *self, PyObject *args, // function args PyObject *py_cdtctx = NULL; as_cdt_ctx ctx; - bool was_cdt_ctx_initialized = false; char *base64 = NULL; PyObject *py_response = NULL; @@ -74,15 +73,13 @@ PyObject *AerospikeClient_GetCDTCTXBase64(AerospikeClient *self, PyObject *args, as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); - if (as_cdt_ctx_init_from_pyobject(self, &err, &ctx, py_cdtctx, - &was_cdt_ctx_initialized, &static_pool, - SERIALIZER_PYTHON) != AEROSPIKE_OK) { - goto CLEANUP; - } - if (!was_cdt_ctx_initialized) { + if (as_cdt_ctx_init_from_pyobject(self, &err, &ctx, py_cdtctx, &static_pool, + SERIALIZER_PYTHON, + false) != AEROSPIKE_OK) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "cdt ctx must be valid " ", generated by aerospike cdt context helper"); + goto CLEANUP; } //convert cdtctx to base64 @@ -99,9 +96,7 @@ PyObject *AerospikeClient_GetCDTCTXBase64(AerospikeClient *self, PyObject *args, CLEANUP: - if (was_cdt_ctx_initialized) { - as_cdt_ctx_destroy(&ctx); - } + as_cdt_ctx_destroy(&ctx); if (base64 != NULL) { cf_free(base64); diff --git a/src/main/client/sec_index.c b/src/main/client/sec_index.c index 585dc4acff..e69f7f5d00 100644 --- a/src/main/client/sec_index.c +++ b/src/main/client/sec_index.c @@ -250,12 +250,9 @@ PyObject *AerospikeClient_Index_Cdt_Create(AerospikeClient *self, as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); - if (as_cdt_ctx_init_from_pyobject(self, &err, &ctx, py_ctx, - &was_cdt_ctx_initialized, &static_pool, - SERIALIZER_PYTHON) != AEROSPIKE_OK) { - goto CLEANUP; - } - if (!was_cdt_ctx_initialized) { + if (as_cdt_ctx_init_from_pyobject( + self, &err, &ctx, py_ctx, &was_cdt_ctx_initialized, &static_pool, + SERIALIZER_PYTHON, false) != AEROSPIKE_OK) { goto CLEANUP; } diff --git a/src/main/conversions.c b/src/main/conversions.c index ea31dafd1c..9238d0c58a 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2400,7 +2400,6 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, as_cdt_ctx *as_cdt_ctx_create_from_pyobject(AerospikeClient *self, as_error *err, PyObject *py_ctx_list, - bool *was_as_cdt_ctx_initialized, as_static_pool *static_pool, int serializer_type) { @@ -2409,9 +2408,8 @@ as_cdt_ctx *as_cdt_ctx_create_from_pyobject(AerospikeClient *self, } as_cdt_ctx *cdt_ctx = cf_malloc(sizeof(as_cdt_ctx)); - as_cdt_ctx_init_from_pyobject(self, err, cdt_ctx, py_ctx_list, - was_as_cdt_ctx_initialized, static_pool, - serializer_type); + as_cdt_ctx_init_from_pyobject(self, err, cdt_ctx, py_ctx_list, static_pool, + serializer_type, false); if (err->code != AEROSPIKE_OK) { cf_free(cdt_ctx); return NULL; @@ -2423,9 +2421,9 @@ as_cdt_ctx *as_cdt_ctx_create_from_pyobject(AerospikeClient *self, as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_ctx_list, - bool *was_as_cdt_ctx_initialized, as_static_pool *static_pool, - int serializer_type) + int serializer_type, + bool is_cdt_ctx_optional) { as_status status = 0; @@ -2600,17 +2598,19 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_status get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, - PyObject *py_op_dict, bool *was_as_cdt_ctx_initialized, + PyObject *py_op_dict, bool *was_cdt_ctx_not_set, as_static_pool *static_pool, int serializer_type) { PyObject *py_ctx_list = PyDict_GetItemString(py_op_dict, CTX_KEY); if (!py_ctx_list) { + *was_cdt_ctx_not_set = false; return AEROSPIKE_OK; } - return as_cdt_ctx_init_from_pyobject(self, err, cdt_ctx, py_ctx_list, - was_as_cdt_ctx_initialized, - static_pool, serializer_type); + as_cdt_ctx_init_from_pyobject(self, err, cdt_ctx, py_ctx_list, static_pool, + serializer_type, true); + + *was_cdt_ctx_not_set = !PyList_Check(py_ctx_list); } static bool requires_int(uint64_t op) diff --git a/src/main/query/where.c b/src/main/query/where.c index 400cbf2dfe..696c45de20 100644 --- a/src/main/query/where.c +++ b/src/main/query/where.c @@ -59,7 +59,6 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, as_error err; as_error_init(&err); as_cdt_ctx *pctx = NULL; - bool was_cdt_ctx_initialized = false; if (py_ctx) { // TODO: does static pool go out of scope? @@ -67,7 +66,6 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, memset(&static_pool, 0, sizeof(static_pool)); pctx = as_cdt_ctx_create_from_pyobject(self->client, &err, py_ctx, - &was_cdt_ctx_initialized, &static_pool, SERIALIZER_PYTHON); if (err.code != AEROSPIKE_OK) { goto CLEANUP_CTX_ON_ERROR; @@ -289,10 +287,8 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, CLEANUP_CTX_ON_ERROR: // The ctx ends up not being used by as_query - if (was_cdt_ctx_initialized) { - as_cdt_ctx_destroy(pctx); - } if (pctx) { + as_cdt_ctx_destroy(pctx); cf_free(pctx); } From 4e27ba8e816ebaec20fff31735184d4842f2ccde Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 11:19:42 -0800 Subject: [PATCH 36/57] fix --- src/main/client/sec_index.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/client/sec_index.c b/src/main/client/sec_index.c index e69f7f5d00..8a318bc0a7 100644 --- a/src/main/client/sec_index.c +++ b/src/main/client/sec_index.c @@ -250,9 +250,9 @@ PyObject *AerospikeClient_Index_Cdt_Create(AerospikeClient *self, as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); - if (as_cdt_ctx_init_from_pyobject( - self, &err, &ctx, py_ctx, &was_cdt_ctx_initialized, &static_pool, - SERIALIZER_PYTHON, false) != AEROSPIKE_OK) { + if (as_cdt_ctx_init_from_pyobject(self, &err, &ctx, py_ctx, &static_pool, + SERIALIZER_PYTHON, + false) != AEROSPIKE_OK) { goto CLEANUP; } From 8d1e419f7542c34146b35adf46413ceee1760236 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 11:22:07 -0800 Subject: [PATCH 37/57] fix --- src/main/client/sec_index.c | 1 - src/main/query/where.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/client/sec_index.c b/src/main/client/sec_index.c index 8a318bc0a7..39373be7b0 100644 --- a/src/main/client/sec_index.c +++ b/src/main/client/sec_index.c @@ -221,7 +221,6 @@ PyObject *AerospikeClient_Index_Cdt_Create(AerospikeClient *self, PyObject *py_name = NULL; PyObject *py_ctx = NULL; as_cdt_ctx ctx; - bool was_cdt_ctx_initialized = false; PyObject *py_obj = NULL; as_index_datatype data_type; as_index_type index_type; diff --git a/src/main/query/where.c b/src/main/query/where.c index 696c45de20..4b40839687 100644 --- a/src/main/query/where.c +++ b/src/main/query/where.c @@ -260,7 +260,7 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, goto CLEANUP_VALUES_ON_ERROR; } - if (was_cdt_ctx_initialized) { + if (pctx) { self->query.where.entries[0].ctx_free = true; } if (exp_list) { From 09f4126ae5c81530cff9776194d439377b8a18eb Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 11:34:23 -0800 Subject: [PATCH 38/57] fix --- src/main/conversions.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/conversions.c b/src/main/conversions.c index 9238d0c58a..78fb419672 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2428,6 +2428,10 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_status status = 0; if (!py_ctx_list || Py_IsNone(py_ctx_list)) { + if (!is_cdt_ctx_optional) { + as_error_update(err, AEROSPIKE_ERR_PARAM, + "Ctx must be a list of contexts"); + } goto CLEANUP5; } else if (!PyList_Check(py_ctx_list)) { @@ -2581,7 +2585,6 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, Py_DECREF(py_extra_args); } - *was_as_cdt_ctx_initialized = true; return AEROSPIKE_OK; CLEANUP1: @@ -2602,11 +2605,6 @@ as_status get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( as_static_pool *static_pool, int serializer_type) { PyObject *py_ctx_list = PyDict_GetItemString(py_op_dict, CTX_KEY); - if (!py_ctx_list) { - *was_cdt_ctx_not_set = false; - return AEROSPIKE_OK; - } - as_cdt_ctx_init_from_pyobject(self, err, cdt_ctx, py_ctx_list, static_pool, serializer_type, true); From ae9cfdd089465b520a12826d771faa633dab5f76 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 11:37:32 -0800 Subject: [PATCH 39/57] finish... --- src/main/conversions.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/conversions.c b/src/main/conversions.c index 78fb419672..fdf456bbd7 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2607,8 +2607,12 @@ as_status get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( PyObject *py_ctx_list = PyDict_GetItemString(py_op_dict, CTX_KEY); as_cdt_ctx_init_from_pyobject(self, err, cdt_ctx, py_ctx_list, static_pool, serializer_type, true); + if (err->code != AEROSPIKE_OK) { + return err->code; + } *was_cdt_ctx_not_set = !PyList_Check(py_ctx_list); + return AEROSPIKE_OK; } static bool requires_int(uint64_t op) From fc8c760d6e4de83b85797918ba2e58951563cc5d Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 11:47:46 -0800 Subject: [PATCH 40/57] as_cdt_ctx_create_from_pyobject is only used by Query.where() which takes in an optional ctx parameter, but adding a is_cdt_ctx_optional param to this helper makes the helpers consistent --- src/include/conversions.h | 8 +++----- src/main/conversions.c | 15 +++++++++------ src/main/query/where.c | 4 ++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index 95bab24b29..e293a8358a 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -167,11 +167,9 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, PyObject **pyuni_r, char **c_str_ptr, as_error *err); -as_cdt_ctx *as_cdt_ctx_create_from_pyobject(AerospikeClient *self, - as_error *err, - PyObject *py_ctx_list, - as_static_pool *static_pool, - int serializer_type); +as_cdt_ctx *as_cdt_ctx_create_from_pyobject( + AerospikeClient *self, as_error *err, PyObject *py_ctx_list, + as_static_pool *static_pool, int serializer_type, bool is_cdt_ctx_optional); // This function takes in a python list of contexts from aerospike_helpers.cdt_ctx // and converts it to an as_cdt_ctx object for use with the c-client. diff --git a/src/main/conversions.c b/src/main/conversions.c index fdf456bbd7..fd4250a361 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2397,19 +2397,22 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, return as_error_update(err, AEROSPIKE_ERR_PARAM, "String value required"); } -as_cdt_ctx *as_cdt_ctx_create_from_pyobject(AerospikeClient *self, - as_error *err, - PyObject *py_ctx_list, - as_static_pool *static_pool, - int serializer_type) +as_cdt_ctx *as_cdt_ctx_create_from_pyobject( + AerospikeClient *self, as_error *err, PyObject *py_ctx_list, + as_static_pool *static_pool, int serializer_type, bool is_cdt_ctx_optional) { if (!py_ctx_list || Py_IsNone(py_ctx_list)) { + if (!is_cdt_ctx_optional) { + as_error_update(err, AEROSPIKE_ERR_PARAM, + "ctx must be a list of cdt_ctx"); + } return NULL; } + as_cdt_ctx *cdt_ctx = cf_malloc(sizeof(as_cdt_ctx)); as_cdt_ctx_init_from_pyobject(self, err, cdt_ctx, py_ctx_list, static_pool, - serializer_type, false); + serializer_type, is_cdt_ctx_optional); if (err->code != AEROSPIKE_OK) { cf_free(cdt_ctx); return NULL; diff --git a/src/main/query/where.c b/src/main/query/where.c index 4b40839687..b5ba7fe047 100644 --- a/src/main/query/where.c +++ b/src/main/query/where.c @@ -65,8 +65,8 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); - pctx = as_cdt_ctx_create_from_pyobject(self->client, &err, py_ctx, - &static_pool, SERIALIZER_PYTHON); + pctx = as_cdt_ctx_create_from_pyobject( + self->client, &err, py_ctx, &static_pool, SERIALIZER_PYTHON, true); if (err.code != AEROSPIKE_OK) { goto CLEANUP_CTX_ON_ERROR; } From d2d7065fa526f92c06fc782435be00a4fa4aa8d3 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 11:50:24 -0800 Subject: [PATCH 41/57] Clear up --- src/include/conversions.h | 3 ++- src/main/conversions.c | 2 +- src/main/query/where.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index e293a8358a..741b0c5f7b 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -167,7 +167,8 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, PyObject **pyuni_r, char **c_str_ptr, as_error *err); -as_cdt_ctx *as_cdt_ctx_create_from_pyobject( +// Sets err on error. Return value can be NULL if as_cdt_ctx is optional +as_cdt_ctx *optional_as_cdt_ctx_create_from_pyobject( AerospikeClient *self, as_error *err, PyObject *py_ctx_list, as_static_pool *static_pool, int serializer_type, bool is_cdt_ctx_optional); diff --git a/src/main/conversions.c b/src/main/conversions.c index fd4250a361..62fc98b020 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2397,7 +2397,7 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, return as_error_update(err, AEROSPIKE_ERR_PARAM, "String value required"); } -as_cdt_ctx *as_cdt_ctx_create_from_pyobject( +as_cdt_ctx *optional_as_cdt_ctx_create_from_pyobject( AerospikeClient *self, as_error *err, PyObject *py_ctx_list, as_static_pool *static_pool, int serializer_type, bool is_cdt_ctx_optional) { diff --git a/src/main/query/where.c b/src/main/query/where.c index b5ba7fe047..b7647b3172 100644 --- a/src/main/query/where.c +++ b/src/main/query/where.c @@ -65,7 +65,7 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); - pctx = as_cdt_ctx_create_from_pyobject( + pctx = optional_as_cdt_ctx_create_from_pyobject( self->client, &err, py_ctx, &static_pool, SERIALIZER_PYTHON, true); if (err.code != AEROSPIKE_OK) { goto CLEANUP_CTX_ON_ERROR; From 8b3c63e1bcb0e9ce19c9717e7399b7bfe0d05a08 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 11:54:22 -0800 Subject: [PATCH 42/57] Clear up --- src/include/conversions.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/include/conversions.h b/src/include/conversions.h index 741b0c5f7b..19f662466c 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -168,6 +168,7 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, as_error *err); // Sets err on error. Return value can be NULL if as_cdt_ctx is optional +// Returns as_cdt_ctx * value to be passed to the C client API as_cdt_ctx *optional_as_cdt_ctx_create_from_pyobject( AerospikeClient *self, as_error *err, PyObject *py_ctx_list, as_static_pool *static_pool, int serializer_type, bool is_cdt_ctx_optional); @@ -178,6 +179,8 @@ as_cdt_ctx *optional_as_cdt_ctx_create_from_pyobject( // The cdt_ctx parameter should point to an uninitialized as_cdt_ctx // object. This function will initialize it, and call as_cdt_ctx_destroy on it IF an error occurs. Otherwise, the caller // must do it themselves when they are done with the object. +// +// The API calls that take in a Python list of contexts doesn't check the parameter's type, so we check it here. as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_cdt_ctx, From bc367daa55b3dc99b722747313f2335107f83948 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 11:59:35 -0800 Subject: [PATCH 43/57] Rename since we have the optional param --- src/include/conversions.h | 2 +- src/main/conversions.c | 2 +- src/main/query/where.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index 19f662466c..c8f54e4122 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -169,7 +169,7 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, // Sets err on error. Return value can be NULL if as_cdt_ctx is optional // Returns as_cdt_ctx * value to be passed to the C client API -as_cdt_ctx *optional_as_cdt_ctx_create_from_pyobject( +as_cdt_ctx *as_cdt_ctx_create_from_pyobject( AerospikeClient *self, as_error *err, PyObject *py_ctx_list, as_static_pool *static_pool, int serializer_type, bool is_cdt_ctx_optional); diff --git a/src/main/conversions.c b/src/main/conversions.c index 62fc98b020..fd4250a361 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2397,7 +2397,7 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, return as_error_update(err, AEROSPIKE_ERR_PARAM, "String value required"); } -as_cdt_ctx *optional_as_cdt_ctx_create_from_pyobject( +as_cdt_ctx *as_cdt_ctx_create_from_pyobject( AerospikeClient *self, as_error *err, PyObject *py_ctx_list, as_static_pool *static_pool, int serializer_type, bool is_cdt_ctx_optional) { diff --git a/src/main/query/where.c b/src/main/query/where.c index b7647b3172..b5ba7fe047 100644 --- a/src/main/query/where.c +++ b/src/main/query/where.c @@ -65,7 +65,7 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); - pctx = optional_as_cdt_ctx_create_from_pyobject( + pctx = as_cdt_ctx_create_from_pyobject( self->client, &err, py_ctx, &static_pool, SERIALIZER_PYTHON, true); if (err.code != AEROSPIKE_OK) { goto CLEANUP_CTX_ON_ERROR; From 0dccd79e2f560528687422fad5c722311d09ce49 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 12:05:53 -0800 Subject: [PATCH 44/57] fix --- src/main/client/get_cdtctx_base64.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/client/get_cdtctx_base64.c b/src/main/client/get_cdtctx_base64.c index 98fd773af6..b873676413 100644 --- a/src/main/client/get_cdtctx_base64.c +++ b/src/main/client/get_cdtctx_base64.c @@ -79,7 +79,7 @@ PyObject *AerospikeClient_GetCDTCTXBase64(AerospikeClient *self, PyObject *args, as_error_update(&err, AEROSPIKE_ERR_PARAM, "cdt ctx must be valid " ", generated by aerospike cdt context helper"); - goto CLEANUP; + goto CLEANUP2; } //convert cdtctx to base64 @@ -89,15 +89,15 @@ PyObject *AerospikeClient_GetCDTCTXBase64(AerospikeClient *self, PyObject *args, if (!rv) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "failed to convert cdt ctx to base64 "); - goto CLEANUP; + goto CLEANUP2; } py_response = PyUnicode_FromString((const char *)base64); -CLEANUP: - +CLEANUP2: as_cdt_ctx_destroy(&ctx); +CLEANUP: if (base64 != NULL) { cf_free(base64); } From 26ee07586e1f3a89fd338a6965a66ad437f98d93 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 13:09:22 -0800 Subject: [PATCH 45/57] Fix segfault --- src/main/conversions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/conversions.c b/src/main/conversions.c index fd4250a361..ffef8a3cff 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2614,7 +2614,7 @@ as_status get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( return err->code; } - *was_cdt_ctx_not_set = !PyList_Check(py_ctx_list); + *was_cdt_ctx_not_set = !py_ctx_list || Py_IsNone(py_ctx_list); return AEROSPIKE_OK; } From 9f42edb9760b14c4cbb4547bb4641d56a78efc94 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 13:17:53 -0800 Subject: [PATCH 46/57] fix --- src/main/conversions.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/conversions.c b/src/main/conversions.c index ffef8a3cff..5834b802da 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2604,7 +2604,7 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_status get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, - PyObject *py_op_dict, bool *was_cdt_ctx_not_set, + PyObject *py_op_dict, bool *was_cdt_ctx_initialized, as_static_pool *static_pool, int serializer_type) { PyObject *py_ctx_list = PyDict_GetItemString(py_op_dict, CTX_KEY); @@ -2614,7 +2614,7 @@ as_status get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( return err->code; } - *was_cdt_ctx_not_set = !py_ctx_list || Py_IsNone(py_ctx_list); + *was_cdt_ctx_initialized = py_ctx_list && PyList_Check(py_ctx_list); return AEROSPIKE_OK; } From 470421e7c3447d5350b2d769d8daebda0605b5e2 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 9 Jan 2026 13:58:34 -0800 Subject: [PATCH 47/57] refactor --- src/include/conversions.h | 26 +- src/main/client/cdt_list_operate.c | 464 ++++++++++++++-------------- src/main/client/cdt_map_operate.c | 58 ++-- src/main/client/get_cdtctx_base64.c | 6 +- src/main/client/operate.c | 2 +- src/main/client/sec_index.c | 6 +- src/main/conversions.c | 107 +++---- src/main/convert_expressions.c | 14 +- src/main/query/where.c | 4 +- 9 files changed, 317 insertions(+), 370 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index c8f54e4122..5c8ba7f30e 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -169,9 +169,11 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, // Sets err on error. Return value can be NULL if as_cdt_ctx is optional // Returns as_cdt_ctx * value to be passed to the C client API -as_cdt_ctx *as_cdt_ctx_create_from_pyobject( - AerospikeClient *self, as_error *err, PyObject *py_ctx_list, - as_static_pool *static_pool, int serializer_type, bool is_cdt_ctx_optional); +as_cdt_ctx *as_cdt_ctx_create_from_pyobject(AerospikeClient *self, + as_error *err, + PyObject *py_ctx_list, + as_static_pool *static_pool, + int serializer_type); // This function takes in a python list of contexts from aerospike_helpers.cdt_ctx // and converts it to an as_cdt_ctx object for use with the c-client. @@ -181,17 +183,15 @@ as_cdt_ctx *as_cdt_ctx_create_from_pyobject( // must do it themselves when they are done with the object. // // The API calls that take in a Python list of contexts doesn't check the parameter's type, so we check it here. -as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, - as_cdt_ctx *cdt_ctx, - PyObject *py_cdt_ctx, - as_static_pool *static_pool, - int serializer_type, - bool is_cdt_ctx_optional); - -as_status get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( +as_cdt_ctx *as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, + as_cdt_ctx *cdt_ctx, + PyObject *py_cdt_ctx, + as_static_pool *static_pool, + int serializer_type); + +as_cdt_ctx *get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, - PyObject *py_op_dict, bool *was_cdt_ctx_initialized, - as_static_pool *static_pool, int serializer_type); + PyObject *py_op_dict, as_static_pool *static_pool, int serializer_type); // allow_base64_encoded_exprs: can the Python object also be a Python unicode object (base64 encoded)? // if false, the Python object should only be a compiled Python expression object from aerospike_helpers diff --git a/src/main/client/cdt_list_operate.c b/src/main/client/cdt_list_operate.c index ee15d9d9f7..c7911ac697 100644 --- a/src/main/client/cdt_list_operate.c +++ b/src/main/client/cdt_list_operate.c @@ -434,7 +434,7 @@ static as_status add_op_list_get_by_index(AerospikeClient *self, as_error *err, { int64_t index; int return_type = AS_LIST_RETURN_VALUE; - bool ctx_in_use = false; + as_cdt_ctx ctx; /* Get the index*/ @@ -446,19 +446,19 @@ static as_status add_op_list_get_by_index(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } - if (!as_operations_list_get_by_index(ops, bin, (ctx_in_use ? &ctx : NULL), - index, return_type)) { + if (!as_operations_list_get_by_index(ops, bin, ctx_ref, index, + return_type)) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to add get_by_list_index operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -476,7 +476,7 @@ add_op_list_get_by_index_range(AerospikeClient *self, as_error *err, char *bin, bool range_specified = false; bool success = false; int return_type = AS_LIST_RETURN_VALUE; - bool ctx_in_use = false; + as_cdt_ctx ctx; /* Get the index*/ @@ -494,20 +494,19 @@ add_op_list_get_by_index_range(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } if (range_specified) { success = as_operations_list_get_by_index_range( - ops, bin, (ctx_in_use ? &ctx : NULL), index, (uint64_t)count, - return_type); + ops, bin, ctx_ref, index, (uint64_t)count, return_type); } else { success = as_operations_list_get_by_index_range_to_end( - ops, bin, (ctx_in_use ? &ctx : NULL), index, return_type); + ops, bin, ctx_ref, index, return_type); } if (!success) { @@ -515,7 +514,7 @@ add_op_list_get_by_index_range(AerospikeClient *self, as_error *err, char *bin, "Failed to add get_by_list_index_range operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -531,7 +530,7 @@ static as_status add_op_list_get_by_rank(AerospikeClient *self, as_error *err, { int64_t rank; int return_type = AS_LIST_RETURN_VALUE; - bool ctx_in_use = false; + as_cdt_ctx ctx; /* Get the index*/ @@ -543,19 +542,18 @@ static as_status add_op_list_get_by_rank(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } - if (!as_operations_list_get_by_rank(ops, bin, (ctx_in_use ? &ctx : NULL), - rank, return_type)) { + if (!as_operations_list_get_by_rank(ops, bin, ctx_ref, rank, return_type)) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to add get_by_list_index operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -573,7 +571,7 @@ add_op_list_get_by_rank_range(AerospikeClient *self, as_error *err, char *bin, bool range_specified = false; bool success = false; int return_type = AS_LIST_RETURN_VALUE; - bool ctx_in_use = false; + as_cdt_ctx ctx; /* Get the index*/ @@ -590,20 +588,19 @@ add_op_list_get_by_rank_range(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } if (range_specified) { success = as_operations_list_get_by_rank_range( - ops, bin, (ctx_in_use ? &ctx : NULL), rank, (uint64_t)count, - return_type); + ops, bin, ctx_ref, rank, (uint64_t)count, return_type); } else { success = as_operations_list_get_by_rank_range_to_end( - ops, bin, (ctx_in_use ? &ctx : NULL), rank, return_type); + ops, bin, ctx_ref, rank, return_type); } if (!success) { @@ -611,7 +608,7 @@ add_op_list_get_by_rank_range(AerospikeClient *self, as_error *err, char *bin, "Failed to add list_get_by_rank_range operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -626,7 +623,7 @@ static as_status add_op_list_get_by_value(AerospikeClient *self, as_error *err, { as_val *val = NULL; int return_type = AS_LIST_RETURN_VALUE; - bool ctx_in_use = false; + as_cdt_ctx ctx; if (get_list_return_type(err, op_dict, &return_type) != AEROSPIKE_OK) { @@ -638,20 +635,19 @@ static as_status add_op_list_get_by_value(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to convert ctx list"); } - if (!as_operations_list_get_by_value(ops, bin, (ctx_in_use ? &ctx : NULL), - val, return_type)) { + if (!as_operations_list_get_by_value(ops, bin, ctx_ref, val, return_type)) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to add list_get_by_value operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -666,7 +662,7 @@ add_op_list_get_by_value_list(AerospikeClient *self, as_error *err, char *bin, { as_list *value_list = NULL; int return_type = AS_LIST_RETURN_VALUE; - bool ctx_in_use = false; + as_cdt_ctx ctx; if (get_list_return_type(err, op_dict, &return_type) != AEROSPIKE_OK) { @@ -678,23 +674,23 @@ add_op_list_get_by_value_list(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { /* Failed to add the operation, we need to destroy the list of values*/ as_val_destroy(value_list); return err->code; } - if (!as_operations_list_get_by_value_list( - ops, bin, (ctx_in_use ? &ctx : NULL), value_list, return_type)) { + if (!as_operations_list_get_by_value_list(ops, bin, ctx_ref, value_list, + return_type)) { /* Failed to add the operation, we need to destroy the list of values*/ as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to add list_get_by_value_list operation"); as_val_destroy(value_list); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -709,7 +705,7 @@ add_op_list_get_by_value_range(AerospikeClient *self, as_error *err, char *bin, { as_val *val_begin = NULL; as_val *val_end = NULL; - bool ctx_in_use = false; + as_cdt_ctx ctx; int return_type = AS_LIST_RETURN_VALUE; @@ -728,21 +724,20 @@ add_op_list_get_by_value_range(AerospikeClient *self, as_error *err, char *bin, goto error; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { goto error; } - if (!as_operations_list_get_by_value_range( - ops, bin, (ctx_in_use ? &ctx : NULL), val_begin, val_end, - return_type)) { + if (!as_operations_list_get_by_value_range(ops, bin, ctx_ref, val_begin, + val_end, return_type)) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to add list_get_by_value_range operation"); goto error; } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -758,7 +753,7 @@ add_op_list_get_by_value_range(AerospikeClient *self, as_error *err, char *bin, as_val_destroy(val_end); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -773,7 +768,7 @@ add_op_list_remove_by_index(AerospikeClient *self, as_error *err, char *bin, { int64_t index; int return_type = AS_LIST_RETURN_VALUE; - bool ctx_in_use = false; + as_cdt_ctx ctx; /* Get the index*/ @@ -785,19 +780,19 @@ add_op_list_remove_by_index(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } - if (!as_operations_list_remove_by_index( - ops, bin, (ctx_in_use ? &ctx : NULL), index, return_type)) { + if (!as_operations_list_remove_by_index(ops, bin, ctx_ref, index, + return_type)) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to add remove_by_list_index operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -814,7 +809,7 @@ static as_status add_op_list_remove_by_index_range( bool range_specified = false; bool success = false; int return_type = AS_LIST_RETURN_VALUE; - bool ctx_in_use = false; + as_cdt_ctx ctx; /* Get the index*/ @@ -832,20 +827,19 @@ static as_status add_op_list_remove_by_index_range( return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } if (range_specified) { success = as_operations_list_remove_by_index_range( - ops, bin, (ctx_in_use ? &ctx : NULL), index, (uint64_t)count, - return_type); + ops, bin, ctx_ref, index, (uint64_t)count, return_type); } else { success = as_operations_list_remove_by_index_range_to_end( - ops, bin, (ctx_in_use ? &ctx : NULL), index, return_type); + ops, bin, ctx_ref, index, return_type); } if (!success) { @@ -853,7 +847,7 @@ static as_status add_op_list_remove_by_index_range( "Failed to add remove_by_list_index_range operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -868,7 +862,7 @@ add_op_list_remove_by_rank(AerospikeClient *self, as_error *err, char *bin, { int64_t rank; int return_type = AS_LIST_RETURN_VALUE; - bool ctx_in_use = false; + as_cdt_ctx ctx; /* Get the index*/ @@ -880,19 +874,19 @@ add_op_list_remove_by_rank(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } - if (!as_operations_list_remove_by_rank(ops, bin, (ctx_in_use ? &ctx : NULL), - rank, return_type)) { + if (!as_operations_list_remove_by_rank(ops, bin, ctx_ref, rank, + return_type)) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to add list_remove_by_rank operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -909,7 +903,7 @@ static as_status add_op_list_remove_by_rank_range( bool range_specified = false; bool success = false; int return_type = AS_LIST_RETURN_VALUE; - bool ctx_in_use = false; + as_cdt_ctx ctx; /* Get the index*/ @@ -926,20 +920,19 @@ static as_status add_op_list_remove_by_rank_range( return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } if (range_specified) { success = as_operations_list_remove_by_rank_range( - ops, bin, (ctx_in_use ? &ctx : NULL), rank, (uint64_t)count, - return_type); + ops, bin, ctx_ref, rank, (uint64_t)count, return_type); } else { success = as_operations_list_remove_by_rank_range_to_end( - ops, bin, (ctx_in_use ? &ctx : NULL), rank, return_type); + ops, bin, ctx_ref, rank, return_type); } if (!success) { @@ -947,7 +940,7 @@ static as_status add_op_list_remove_by_rank_range( "Failed to add list_remove_by_rank_range operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -962,7 +955,7 @@ add_op_list_remove_by_value(AerospikeClient *self, as_error *err, char *bin, { as_val *val = NULL; int return_type = AS_LIST_RETURN_VALUE; - bool ctx_in_use = false; + as_cdt_ctx ctx; if (get_list_return_type(err, op_dict, &return_type) != AEROSPIKE_OK) { @@ -974,20 +967,20 @@ add_op_list_remove_by_value(AerospikeClient *self, as_error *err, char *bin, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } - if (!as_operations_list_remove_by_value( - ops, bin, (ctx_in_use ? &ctx : NULL), val, return_type)) { + if (!as_operations_list_remove_by_value(ops, bin, ctx_ref, val, + return_type)) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to add list_remove_by_value operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1001,7 +994,7 @@ static as_status add_op_list_remove_by_value_list( { as_list *value_list = NULL; int return_type = AS_LIST_RETURN_VALUE; - bool ctx_in_use = false; + as_cdt_ctx ctx; if (get_list_return_type(err, op_dict, &return_type) != AEROSPIKE_OK) { @@ -1013,23 +1006,23 @@ static as_status add_op_list_remove_by_value_list( return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { /* Failed to convert ctx, we need to destroy the list of values*/ as_val_destroy(value_list); return err->code; } - if (!as_operations_list_remove_by_value_list( - ops, bin, (ctx_in_use ? &ctx : NULL), value_list, return_type)) { + if (!as_operations_list_remove_by_value_list(ops, bin, ctx_ref, value_list, + return_type)) { /* Failed to add the operation, we need to destroy the list of values*/ as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to add list_get_by_value_list operation"); as_val_destroy(value_list); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1042,7 +1035,7 @@ static as_status add_op_list_remove_by_value_range( { as_val *val_begin = NULL; as_val *val_end = NULL; - bool ctx_in_use = false; + as_cdt_ctx ctx; int return_type = AS_LIST_RETURN_VALUE; @@ -1060,21 +1053,20 @@ static as_status add_op_list_remove_by_value_range( goto error; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { goto error; } - if (!as_operations_list_remove_by_value_range( - ops, bin, (ctx_in_use ? &ctx : NULL), val_begin, val_end, - return_type)) { + if (!as_operations_list_remove_by_value_range(ops, bin, ctx_ref, val_begin, + val_end, return_type)) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to add list_remove_by_value_range operation"); goto error; } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1090,7 +1082,7 @@ static as_status add_op_list_remove_by_value_range( as_val_destroy(val_end); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1104,7 +1096,7 @@ static as_status add_op_list_set_order(AerospikeClient *self, as_error *err, int serializer_type) { int64_t order_type_int; - bool ctx_in_use = false; + as_cdt_ctx ctx; if (get_int64_t(err, AS_PY_LIST_ORDER, op_dict, &order_type_int) != @@ -1112,20 +1104,20 @@ static as_status add_op_list_set_order(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } - if (!as_operations_list_set_order(ops, bin, (ctx_in_use ? &ctx : NULL), + if (!as_operations_list_set_order(ops, bin, ctx_ref, (as_list_order)order_type_int)) { as_cdt_ctx_destroy(&ctx); return as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to add list_set_order operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1139,7 +1131,7 @@ static as_status add_op_list_sort(AerospikeClient *self, as_error *err, int serializer_type) { int64_t sort_flags; - bool ctx_in_use = false; + as_cdt_ctx ctx; if (get_int64_t(err, AS_PY_LIST_SORT_FLAGS, op_dict, &sort_flags) != @@ -1147,20 +1139,20 @@ static as_status add_op_list_sort(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } - if (!as_operations_list_sort(ops, bin, (ctx_in_use ? &ctx : NULL), + if (!as_operations_list_sort(ops, bin, ctx_ref, (as_list_sort_flags)sort_flags)) { as_cdt_ctx_destroy(&ctx); return as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to add list_sort operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1175,7 +1167,7 @@ static as_status add_op_list_create(AerospikeClient *self, as_error *err, { int64_t order_type_int; as_cdt_ctx ctx; - bool ctx_in_use = false; + bool pad, persist_index; if (get_int64_t(err, AS_PY_LIST_ORDER, op_dict, &order_type_int) != @@ -1192,17 +1184,16 @@ static as_status add_op_list_create(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } bool add_op_successful = as_operations_list_create_all( - ops, bin, (ctx_in_use ? &ctx : NULL), (as_list_order)order_type_int, - pad, persist_index); + ops, bin, ctx_ref, (as_list_order)order_type_int, pad, persist_index); - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1224,7 +1215,7 @@ static as_status add_op_list_append(AerospikeClient *self, as_error *err, as_val *val = NULL; as_list_policy list_policy; bool policy_in_use = false; - bool ctx_in_use = false; + as_cdt_ctx ctx; if (get_list_policy(err, op_dict, &list_policy, &policy_in_use, @@ -1237,23 +1228,22 @@ static as_status add_op_list_append(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } - if (!as_operations_list_append(ops, bin, (ctx_in_use ? &ctx : NULL), - (policy_in_use ? &list_policy : NULL), - val)) { + if (!as_operations_list_append( + ops, bin, ctx_ref, (policy_in_use ? &list_policy : NULL), val)) { as_val_destroy(val); as_cdt_ctx_destroy(&ctx); return as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to add list_append operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1269,7 +1259,7 @@ static as_status add_op_list_append_items(AerospikeClient *self, as_error *err, as_list *items_list = NULL; as_list_policy list_policy; bool policy_in_use = false; - bool ctx_in_use = false; + as_cdt_ctx ctx; if (get_list_policy(err, op_dict, &list_policy, &policy_in_use, @@ -1282,14 +1272,14 @@ static as_status add_op_list_append_items(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { as_val_destroy(items_list); return err->code; } - if (!as_operations_list_append_items(ops, bin, (ctx_in_use ? &ctx : NULL), + if (!as_operations_list_append_items(ops, bin, ctx_ref, (policy_in_use ? &list_policy : NULL), items_list)) { as_val_destroy(items_list); @@ -1298,7 +1288,7 @@ static as_status add_op_list_append_items(AerospikeClient *self, as_error *err, "Failed to add list_append_items operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1315,7 +1305,7 @@ static as_status add_op_list_insert(AerospikeClient *self, as_error *err, int64_t index; as_list_policy list_policy; bool policy_in_use = false; - bool ctx_in_use = false; + as_cdt_ctx ctx; if (get_int64_t(err, AS_PY_INDEX_KEY, op_dict, &index) != AEROSPIKE_OK) { @@ -1332,14 +1322,14 @@ static as_status add_op_list_insert(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } - if (!as_operations_list_insert(ops, bin, (ctx_in_use ? &ctx : NULL), + if (!as_operations_list_insert(ops, bin, ctx_ref, (policy_in_use ? &list_policy : NULL), index, val)) { as_val_destroy(val); @@ -1348,7 +1338,7 @@ static as_status add_op_list_insert(AerospikeClient *self, as_error *err, "Failed to add list_insert operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1365,7 +1355,7 @@ static as_status add_op_list_insert_items(AerospikeClient *self, as_error *err, int64_t index; as_list_policy list_policy; bool policy_in_use = false; - bool ctx_in_use = false; + as_cdt_ctx ctx; if (get_int64_t(err, AS_PY_INDEX_KEY, op_dict, &index) != AEROSPIKE_OK) { @@ -1382,14 +1372,14 @@ static as_status add_op_list_insert_items(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { as_val_destroy(items_list); return err->code; } - if (!as_operations_list_insert_items(ops, bin, (ctx_in_use ? &ctx : NULL), + if (!as_operations_list_insert_items(ops, bin, ctx_ref, (policy_in_use ? &list_policy : NULL), index, items_list)) { as_val_destroy(items_list); @@ -1398,7 +1388,7 @@ static as_status add_op_list_insert_items(AerospikeClient *self, as_error *err, "Failed to add list_insert_items operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1415,7 +1405,7 @@ static as_status add_op_list_increment(AerospikeClient *self, as_error *err, int64_t index; as_list_policy list_policy; bool policy_in_use = false; - bool ctx_in_use = false; + as_cdt_ctx ctx; if (get_list_policy(err, op_dict, &list_policy, &policy_in_use, @@ -1432,14 +1422,14 @@ static as_status add_op_list_increment(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { as_val_destroy(incr); return err->code; } - if (!as_operations_list_increment(ops, bin, (ctx_in_use ? &ctx : NULL), + if (!as_operations_list_increment(ops, bin, ctx_ref, (policy_in_use ? &list_policy : NULL), index, incr)) { as_val_destroy(incr); @@ -1448,7 +1438,7 @@ static as_status add_op_list_increment(AerospikeClient *self, as_error *err, "Failed to add list_increment operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1462,7 +1452,7 @@ static as_status add_op_list_pop(AerospikeClient *self, as_error *err, int serializer_type) { int64_t index; - bool ctx_in_use = false; + as_cdt_ctx ctx; /* Get the index*/ @@ -1470,18 +1460,18 @@ static as_status add_op_list_pop(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } - if (!as_operations_list_pop(ops, bin, (ctx_in_use ? &ctx : NULL), index)) { + if (!as_operations_list_pop(ops, bin, ctx_ref, index)) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to add list_pop operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1496,7 +1486,7 @@ static as_status add_op_list_pop_range(AerospikeClient *self, as_error *err, { int64_t index; int64_t count; - bool ctx_in_use = false; + as_cdt_ctx ctx; /* Get the index*/ @@ -1509,19 +1499,19 @@ static as_status add_op_list_pop_range(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } - if (!as_operations_list_pop_range(ops, bin, (ctx_in_use ? &ctx : NULL), - index, (uint64_t)count)) { + if (!as_operations_list_pop_range(ops, bin, ctx_ref, index, + (uint64_t)count)) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to list_pop_range operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1535,28 +1525,27 @@ static as_status add_op_list_remove(AerospikeClient *self, as_error *err, int serializer_type) { int64_t index; - bool ctx_in_use = false; + as_cdt_ctx ctx; if (get_int64_t(err, AS_PY_INDEX_KEY, op_dict, &index) != AEROSPIKE_OK) { return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { ; return err->code; } - if (!as_operations_list_remove(ops, bin, (ctx_in_use ? &ctx : NULL), - index)) { + if (!as_operations_list_remove(ops, bin, ctx_ref, index)) { as_cdt_ctx_destroy(&ctx); return as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to add list_remove operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1571,7 +1560,7 @@ static as_status add_op_list_remove_range(AerospikeClient *self, as_error *err, { int64_t index; int64_t count; - bool ctx_in_use = false; + as_cdt_ctx ctx; /* Get the index*/ @@ -1584,19 +1573,19 @@ static as_status add_op_list_remove_range(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } - if (!as_operations_list_remove_range(ops, bin, (ctx_in_use ? &ctx : NULL), - index, (uint64_t)count)) { + if (!as_operations_list_remove_range(ops, bin, ctx_ref, index, + (uint64_t)count)) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to list_remove_range operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1609,22 +1598,22 @@ static as_status add_op_list_clear(AerospikeClient *self, as_error *err, as_static_pool *static_pool, int serializer_type) { - bool ctx_in_use = false; + as_cdt_ctx ctx; - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } - if (!as_operations_list_clear(ops, bin, (ctx_in_use ? &ctx : NULL))) { + if (!as_operations_list_clear(ops, bin, ctx_ref)) { as_cdt_ctx_destroy(&ctx); return as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to add list_clear operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1641,7 +1630,7 @@ static as_status add_op_list_set(AerospikeClient *self, as_error *err, int64_t index; as_list_policy list_policy; bool policy_in_use = false; - bool ctx_in_use = false; + as_cdt_ctx ctx; if (get_list_policy(err, op_dict, &list_policy, &policy_in_use, @@ -1658,14 +1647,14 @@ static as_status add_op_list_set(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { as_val_destroy(val); return err->code; } - if (!as_operations_list_set(ops, bin, (ctx_in_use ? &ctx : NULL), + if (!as_operations_list_set(ops, bin, ctx_ref, (policy_in_use ? &list_policy : NULL), index, val)) { as_val_destroy(val); @@ -1674,7 +1663,7 @@ static as_status add_op_list_set(AerospikeClient *self, as_error *err, "Failed to add list_set operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1688,26 +1677,26 @@ static as_status add_op_list_get(AerospikeClient *self, as_error *err, int serializer_type) { int64_t index; - bool ctx_in_use = false; + as_cdt_ctx ctx; if (get_int64_t(err, AS_PY_INDEX_KEY, op_dict, &index) != AEROSPIKE_OK) { return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } - if (!as_operations_list_get(ops, bin, (ctx_in_use ? &ctx : NULL), index)) { + if (!as_operations_list_get(ops, bin, ctx_ref, index)) { as_cdt_ctx_destroy(&ctx); return as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to add list_get operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1722,7 +1711,7 @@ static as_status add_op_list_get_range(AerospikeClient *self, as_error *err, { int64_t index; int64_t count; - bool ctx_in_use = false; + as_cdt_ctx ctx; /* Get the index*/ @@ -1735,19 +1724,19 @@ static as_status add_op_list_get_range(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } - if (!as_operations_list_get_range(ops, bin, (ctx_in_use ? &ctx : NULL), - index, (uint64_t)count)) { + if (!as_operations_list_get_range(ops, bin, ctx_ref, index, + (uint64_t)count)) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to list_get_range operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1762,7 +1751,7 @@ static as_status add_op_list_trim(AerospikeClient *self, as_error *err, { int64_t index; int64_t count; - bool ctx_in_use = false; + as_cdt_ctx ctx; /* Get the index*/ @@ -1775,19 +1764,18 @@ static as_status add_op_list_trim(AerospikeClient *self, as_error *err, return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } - if (!as_operations_list_trim(ops, bin, (ctx_in_use ? &ctx : NULL), index, - (uint64_t)count)) { + if (!as_operations_list_trim(ops, bin, ctx_ref, index, (uint64_t)count)) { as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to list_trim operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1800,22 +1788,22 @@ static as_status add_op_list_size(AerospikeClient *self, as_error *err, as_static_pool *static_pool, int serializer_type) { - bool ctx_in_use = false; + as_cdt_ctx ctx; - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } - if (!as_operations_list_size(ops, bin, (ctx_in_use ? &ctx : NULL))) { + if (!as_operations_list_size(ops, bin, ctx_ref)) { as_cdt_ctx_destroy(&ctx); return as_error_update(err, AEROSPIKE_ERR_CLIENT, "Failed to add list_size operation"); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1831,7 +1819,7 @@ static as_status add_add_op_list_remove_by_value_rel_rank_range( int return_type; int64_t rank; as_val *value = NULL; - bool ctx_in_use = false; + as_cdt_ctx ctx; if (get_list_return_type(err, op_dict, &return_type) != AEROSPIKE_OK) { @@ -1852,16 +1840,15 @@ static as_status add_add_op_list_remove_by_value_rel_rank_range( return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } if (count_present) { if (!as_operations_list_remove_by_value_rel_rank_range( - ops, bin, (ctx_in_use ? &ctx : NULL), value, rank, - (uint64_t)count, return_type)) { + ops, bin, ctx_ref, value, rank, (uint64_t)count, return_type)) { as_cdt_ctx_destroy(&ctx); return as_error_update( err, AEROSPIKE_ERR_CLIENT, @@ -1870,8 +1857,7 @@ static as_status add_add_op_list_remove_by_value_rel_rank_range( } else { if (!as_operations_list_remove_by_value_rel_rank_range_to_end( - ops, bin, (ctx_in_use ? &ctx : NULL), value, rank, - return_type)) { + ops, bin, ctx_ref, value, rank, return_type)) { as_cdt_ctx_destroy(&ctx); return as_error_update( err, AEROSPIKE_ERR_CLIENT, @@ -1879,7 +1865,7 @@ static as_status add_add_op_list_remove_by_value_rel_rank_range( } } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -1896,7 +1882,7 @@ static as_status add_add_op_list_get_by_value_rel_rank_range( int return_type; int64_t rank; as_val *value = NULL; - bool ctx_in_use = false; + as_cdt_ctx ctx; if (get_list_return_type(err, op_dict, &return_type) != AEROSPIKE_OK) { @@ -1917,16 +1903,15 @@ static as_status add_add_op_list_get_by_value_rel_rank_range( return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } if (count_present) { if (!as_operations_list_get_by_value_rel_rank_range( - ops, bin, (ctx_in_use ? &ctx : NULL), value, rank, - (uint64_t)count, return_type)) { + ops, bin, ctx_ref, value, rank, (uint64_t)count, return_type)) { as_cdt_ctx_destroy(&ctx); return as_error_update( err, AEROSPIKE_ERR_CLIENT, @@ -1935,8 +1920,7 @@ static as_status add_add_op_list_get_by_value_rel_rank_range( } else { if (!as_operations_list_get_by_value_rel_rank_range_to_end( - ops, bin, (ctx_in_use ? &ctx : NULL), value, rank, - return_type)) { + ops, bin, ctx_ref, value, rank, return_type)) { as_cdt_ctx_destroy(&ctx); return as_error_update( err, AEROSPIKE_ERR_CLIENT, @@ -1944,7 +1928,7 @@ static as_status add_add_op_list_get_by_value_rel_rank_range( } } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } diff --git a/src/main/client/cdt_map_operate.c b/src/main/client/cdt_map_operate.c index a4976ca8e3..bb89986568 100644 --- a/src/main/client/cdt_map_operate.c +++ b/src/main/client/cdt_map_operate.c @@ -104,7 +104,6 @@ static as_status add_op_map_remove_by_value_rel_rank_range( int return_type = AS_MAP_RETURN_VALUE; int64_t rank; as_val *value = NULL; - bool ctx_in_use = false; as_cdt_ctx ctx; if (get_map_return_type(err, op_dict, &return_type) != AEROSPIKE_OK) { @@ -125,16 +124,15 @@ static as_status add_op_map_remove_by_value_rel_rank_range( return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } if (count_present) { if (!as_operations_map_remove_by_value_rel_rank_range( - ops, bin, (ctx_in_use ? &ctx : NULL), value, rank, - (uint64_t)count, return_type)) { + ops, bin, ctx_ref, value, rank, (uint64_t)count, return_type)) { as_cdt_ctx_destroy(&ctx); return as_error_update( err, AEROSPIKE_ERR_CLIENT, @@ -143,8 +141,7 @@ static as_status add_op_map_remove_by_value_rel_rank_range( } else { if (!as_operations_map_remove_by_value_rel_rank_range_to_end( - ops, bin, (ctx_in_use ? &ctx : NULL), value, rank, - return_type)) { + ops, bin, ctx_ref, value, rank, return_type)) { as_cdt_ctx_destroy(&ctx); return as_error_update( err, AEROSPIKE_ERR_CLIENT, @@ -152,7 +149,7 @@ static as_status add_op_map_remove_by_value_rel_rank_range( } } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -168,7 +165,6 @@ static as_status add_op_map_get_by_value_rel_rank_range( int return_type = AS_MAP_RETURN_VALUE; int64_t rank; as_val *value = NULL; - bool ctx_in_use = false; as_cdt_ctx ctx; if (get_map_return_type(err, op_dict, &return_type) != AEROSPIKE_OK) { @@ -189,16 +185,15 @@ static as_status add_op_map_get_by_value_rel_rank_range( return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } if (count_present) { if (!as_operations_map_get_by_value_rel_rank_range( - ops, bin, (ctx_in_use ? &ctx : NULL), value, rank, - (uint64_t)count, return_type)) { + ops, bin, ctx_ref, value, rank, (uint64_t)count, return_type)) { as_cdt_ctx_destroy(&ctx); return as_error_update( err, AEROSPIKE_ERR_CLIENT, @@ -207,8 +202,7 @@ static as_status add_op_map_get_by_value_rel_rank_range( } else { if (!as_operations_map_get_by_value_rel_rank_range_to_end( - ops, bin, (ctx_in_use ? &ctx : NULL), value, rank, - return_type)) { + ops, bin, ctx_ref, value, rank, return_type)) { as_cdt_ctx_destroy(&ctx); return as_error_update( err, AEROSPIKE_ERR_CLIENT, @@ -216,7 +210,7 @@ static as_status add_op_map_get_by_value_rel_rank_range( } } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -232,7 +226,6 @@ static as_status add_op_map_remove_by_key_rel_index_range( int return_type = AS_MAP_RETURN_VALUE; int64_t rank; as_val *key = NULL; - bool ctx_in_use = false; as_cdt_ctx ctx; if (get_map_return_type(err, op_dict, &return_type) != AEROSPIKE_OK) { @@ -253,16 +246,15 @@ static as_status add_op_map_remove_by_key_rel_index_range( return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } if (count_present) { if (!as_operations_map_remove_by_key_rel_index_range( - ops, bin, (ctx_in_use ? &ctx : NULL), key, rank, - (uint64_t)count, return_type)) { + ops, bin, ctx_ref, key, rank, (uint64_t)count, return_type)) { as_cdt_ctx_destroy(&ctx); return as_error_update( err, AEROSPIKE_ERR_CLIENT, @@ -271,7 +263,7 @@ static as_status add_op_map_remove_by_key_rel_index_range( } else { if (!as_operations_map_remove_by_key_rel_index_range_to_end( - ops, bin, (ctx_in_use ? &ctx : NULL), key, rank, return_type)) { + ops, bin, ctx_ref, key, rank, return_type)) { as_cdt_ctx_destroy(&ctx); return as_error_update( err, AEROSPIKE_ERR_CLIENT, @@ -279,7 +271,7 @@ static as_status add_op_map_remove_by_key_rel_index_range( } } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } @@ -295,7 +287,6 @@ static as_status add_op_map_get_by_key_rel_index_range( int return_type = AS_MAP_RETURN_VALUE; int64_t rank; as_val *key = NULL; - bool ctx_in_use = false; as_cdt_ctx ctx; if (get_map_return_type(err, op_dict, &return_type) != AEROSPIKE_OK) { @@ -316,16 +307,15 @@ static as_status add_op_map_get_by_key_rel_index_range( return err->code; } - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + self, err, &ctx, op_dict, static_pool, serializer_type); + if (err->code != AEROSPIKE_OK) { return err->code; } if (count_present) { if (!as_operations_map_get_by_key_rel_index_range( - ops, bin, (ctx_in_use ? &ctx : NULL), key, rank, - (uint64_t)count, return_type)) { + ops, bin, ctx_ref, key, rank, (uint64_t)count, return_type)) { as_cdt_ctx_destroy(&ctx); return as_error_update( err, AEROSPIKE_ERR_CLIENT, @@ -334,7 +324,7 @@ static as_status add_op_map_get_by_key_rel_index_range( } else { if (!as_operations_map_get_by_key_rel_index_range_to_end( - ops, bin, (ctx_in_use ? &ctx : NULL), key, rank, return_type)) { + ops, bin, ctx_ref, key, rank, return_type)) { as_cdt_ctx_destroy(&ctx); return as_error_update( err, AEROSPIKE_ERR_CLIENT, @@ -342,7 +332,7 @@ static as_status add_op_map_get_by_key_rel_index_range( } } - if (ctx_in_use) { //add these spaces + if (ctx_ref) { //add these spaces as_cdt_ctx_destroy(&ctx); } diff --git a/src/main/client/get_cdtctx_base64.c b/src/main/client/get_cdtctx_base64.c index b873676413..7936f0ed47 100644 --- a/src/main/client/get_cdtctx_base64.c +++ b/src/main/client/get_cdtctx_base64.c @@ -73,9 +73,9 @@ PyObject *AerospikeClient_GetCDTCTXBase64(AerospikeClient *self, PyObject *args, as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); - if (as_cdt_ctx_init_from_pyobject(self, &err, &ctx, py_cdtctx, &static_pool, - SERIALIZER_PYTHON, - false) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = as_cdt_ctx_init_from_pyobject( + self, &err, &ctx, py_cdtctx, &static_pool, SERIALIZER_PYTHON); + if (ctx_ref == NULL) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "cdt ctx must be valid " ", generated by aerospike cdt context helper"); diff --git a/src/main/client/operate.c b/src/main/client/operate.c index 2b20d91a0c..cc39cacd4a 100644 --- a/src/main/client/operate.c +++ b/src/main/client/operate.c @@ -422,7 +422,7 @@ as_status add_op(AerospikeClient *self, as_error *err, } else if (strcmp(name, "ctx") == 0) { CONVERT_PY_CTX_TO_AS_CTX(); - ctx_ref = (ctx_in_use ? &ctx : NULL); + ctx_ref = ctx_ref; } else if (strcmp(name, "map_order") == 0) { py_map_order = value; diff --git a/src/main/client/sec_index.c b/src/main/client/sec_index.c index 39373be7b0..4c33cd8210 100644 --- a/src/main/client/sec_index.c +++ b/src/main/client/sec_index.c @@ -249,9 +249,9 @@ PyObject *AerospikeClient_Index_Cdt_Create(AerospikeClient *self, as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); - if (as_cdt_ctx_init_from_pyobject(self, &err, &ctx, py_ctx, &static_pool, - SERIALIZER_PYTHON, - false) != AEROSPIKE_OK) { + as_cdt_ctx *ctx_ref = as_cdt_ctx_init_from_pyobject( + self, &err, &ctx, py_ctx, &static_pool, SERIALIZER_PYTHON); + if (ctx_ref == NULL) { goto CLEANUP; } diff --git a/src/main/conversions.c b/src/main/conversions.c index 5834b802da..418e8e163b 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2397,22 +2397,20 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, return as_error_update(err, AEROSPIKE_ERR_PARAM, "String value required"); } -as_cdt_ctx *as_cdt_ctx_create_from_pyobject( - AerospikeClient *self, as_error *err, PyObject *py_ctx_list, - as_static_pool *static_pool, int serializer_type, bool is_cdt_ctx_optional) +as_cdt_ctx *as_cdt_ctx_create_from_pyobject(AerospikeClient *self, + as_error *err, + PyObject *py_ctx_list, + as_static_pool *static_pool, + int serializer_type) { if (!py_ctx_list || Py_IsNone(py_ctx_list)) { - if (!is_cdt_ctx_optional) { - as_error_update(err, AEROSPIKE_ERR_PARAM, - "ctx must be a list of cdt_ctx"); - } return NULL; } as_cdt_ctx *cdt_ctx = cf_malloc(sizeof(as_cdt_ctx)); as_cdt_ctx_init_from_pyobject(self, err, cdt_ctx, py_ctx_list, static_pool, - serializer_type, is_cdt_ctx_optional); + serializer_type); if (err->code != AEROSPIKE_OK) { cf_free(cdt_ctx); return NULL; @@ -2421,26 +2419,19 @@ as_cdt_ctx *as_cdt_ctx_create_from_pyobject( return cdt_ctx; } -as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, - as_cdt_ctx *cdt_ctx, - PyObject *py_ctx_list, - as_static_pool *static_pool, - int serializer_type, - bool is_cdt_ctx_optional) +as_cdt_ctx *as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, + as_cdt_ctx *cdt_ctx, + PyObject *py_ctx_list, + as_static_pool *static_pool, + int serializer_type) { - as_status status = 0; - if (!py_ctx_list || Py_IsNone(py_ctx_list)) { - if (!is_cdt_ctx_optional) { - as_error_update(err, AEROSPIKE_ERR_PARAM, - "Ctx must be a list of contexts"); - } - goto CLEANUP5; + goto RETURN_NULL; } else if (!PyList_Check(py_ctx_list)) { - status = as_error_update(err, AEROSPIKE_ERR_PARAM, - "Failed to convert %s", CTX_KEY); - goto CLEANUP5; + as_error_update(err, AEROSPIKE_ERR_PARAM, "Failed to convert %s", + CTX_KEY); + goto RETURN_NULL; } long int_val = 0; @@ -2458,30 +2449,29 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, py_id = PyObject_GetAttrString(py_cdt_ctx, "id"); if (PyErr_Occurred()) { - status = as_error_update(err, AEROSPIKE_ERR_PARAM, - "Failed to convert %s, id", CTX_KEY); + as_error_update(err, AEROSPIKE_ERR_PARAM, + "Failed to convert %s, id", CTX_KEY); goto CLEANUP4; } py_value = PyObject_GetAttrString(py_cdt_ctx, "value"); if (PyErr_Occurred()) { - status = as_error_update(err, AEROSPIKE_ERR_PARAM, - "Failed to convert %s, value", CTX_KEY); + as_error_update(err, AEROSPIKE_ERR_PARAM, + "Failed to convert %s, value", CTX_KEY); goto CLEANUP3; } py_extra_args = PyObject_GetAttrString(py_cdt_ctx, "extra_args"); if (PyErr_Occurred()) { - status = as_error_update(err, AEROSPIKE_ERR_PARAM, - "Failed to convert %s", CTX_KEY); + as_error_update(err, AEROSPIKE_ERR_PARAM, "Failed to convert %s", + CTX_KEY); goto CLEANUP2; } uint64_t item_type = PyLong_AsUnsignedLongLong(py_id); if (PyErr_Occurred()) { - status = as_error_update(err, AEROSPIKE_ERR_PARAM, - "Failed to convert %s, id to uint64_t", - CTX_KEY); + as_error_update(err, AEROSPIKE_ERR_PARAM, + "Failed to convert %s, id to uint64_t", CTX_KEY); goto CLEANUP1; } @@ -2489,9 +2479,8 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, if (requires_int(item_type)) { int_val = PyLong_AsLong(py_value); if (PyErr_Occurred()) { - status = as_error_update(err, AEROSPIKE_ERR_PARAM, - "Failed to convert %s, value to long", - CTX_KEY); + as_error_update(err, AEROSPIKE_ERR_PARAM, + "Failed to convert %s, value to long", CTX_KEY); goto CLEANUP1; } switch (item_type) { @@ -2517,9 +2506,9 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, pad); break; default: - status = as_error_update( - err, AEROSPIKE_ERR_PARAM, - "Failed to convert, unknown ctx operation %s", CTX_KEY); + as_error_update(err, AEROSPIKE_ERR_PARAM, + "Failed to convert, unknown ctx operation %s", + CTX_KEY); goto CLEANUP1; } } @@ -2532,14 +2521,13 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, int retval = PyDict_GetItemStringRef( py_extra_args, _CDT_CTX_FILTER_EXPR_KEY, &py_expr); if (retval != 1) { - status = as_error_update(err, AEROSPIKE_ERR_PARAM, - "Invalid cdt_ctx_exp"); + as_error_update(err, AEROSPIKE_ERR_PARAM, + "Invalid cdt_ctx_exp"); goto CLEANUP1; } as_exp *expr = NULL; - status = - as_exp_new_from_pyobject(self, py_expr, &expr, err, false); + as_exp_new_from_pyobject(self, py_expr, &expr, err, false); Py_DECREF(py_expr); if (err->code != AEROSPIKE_OK) { goto CLEANUP1; @@ -2553,9 +2541,9 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, else { if (as_val_new_from_pyobject(self, err, py_value, &val, static_pool, serializer_type) != AEROSPIKE_OK) { - status = as_error_update( - err, AEROSPIKE_ERR_PARAM, - "Failed to convert %s, value to as_val", CTX_KEY); + as_error_update(err, AEROSPIKE_ERR_PARAM, + "Failed to convert %s, value to as_val", + CTX_KEY); goto CLEANUP1; } @@ -2576,9 +2564,9 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_cdt_ctx_add_map_key_create(cdt_ctx, val, map_order); break; default: - status = as_error_update( - err, AEROSPIKE_ERR_PARAM, - "Failed to convert, unknown ctx operation %s", CTX_KEY); + as_error_update(err, AEROSPIKE_ERR_PARAM, + "Failed to convert, unknown ctx operation %s", + CTX_KEY); goto CLEANUP1; } } @@ -2588,7 +2576,7 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, Py_DECREF(py_extra_args); } - return AEROSPIKE_OK; + return cdt_ctx; CLEANUP1: Py_DECREF(py_extra_args); @@ -2598,24 +2586,17 @@ as_status as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, Py_DECREF(py_id); CLEANUP4: as_cdt_ctx_destroy(cdt_ctx); -CLEANUP5: - return status; +RETURN_NULL: + return NULL; } -as_status get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( +as_cdt_ctx *get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, - PyObject *py_op_dict, bool *was_cdt_ctx_initialized, - as_static_pool *static_pool, int serializer_type) + PyObject *py_op_dict, as_static_pool *static_pool, int serializer_type) { PyObject *py_ctx_list = PyDict_GetItemString(py_op_dict, CTX_KEY); - as_cdt_ctx_init_from_pyobject(self, err, cdt_ctx, py_ctx_list, static_pool, - serializer_type, true); - if (err->code != AEROSPIKE_OK) { - return err->code; - } - - *was_cdt_ctx_initialized = py_ctx_list && PyList_Check(py_ctx_list); - return AEROSPIKE_OK; + return as_cdt_ctx_init_from_pyobject(self, err, cdt_ctx, py_ctx_list, + static_pool, serializer_type); } static bool requires_int(uint64_t op) diff --git a/src/main/convert_expressions.c b/src/main/convert_expressions.c index 24282fac6e..c76c442bb2 100644 --- a/src/main/convert_expressions.c +++ b/src/main/convert_expressions.c @@ -1835,17 +1835,9 @@ as_status as_exp_new_from_pyobject(AerospikeClient *self, PyObject *py_expr, //TODO Could it be moved somewhere else? py_ctx_list_p = PyDict_GetItemString(temp_expr.pydict, CTX_KEY); if (py_ctx_list_p != NULL) { - temp_expr.ctx = malloc(sizeof(as_cdt_ctx)); - if (temp_expr.ctx == NULL) { - as_error_update(err, AEROSPIKE_ERR, - "Could not malloc mem for temp_expr.ctx."); - goto CLEANUP; - } - - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( - self, err, temp_expr.ctx, temp_expr.pydict, - &is_ctx_initialized, &static_pool, - SERIALIZER_PYTHON) != AEROSPIKE_OK) { + temp_expr.ctx = as_cdt_ctx_create_from_pyobject( + self, err, temp_expr.pydict, &static_pool, SERIALIZER_PYTHON); + if (err->code != AEROSPIKE_OK) { goto CLEANUP; } } diff --git a/src/main/query/where.c b/src/main/query/where.c index b5ba7fe047..4b40839687 100644 --- a/src/main/query/where.c +++ b/src/main/query/where.c @@ -65,8 +65,8 @@ static int AerospikeQuery_Where_Add(AerospikeQuery *self, PyObject *py_ctx, as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); - pctx = as_cdt_ctx_create_from_pyobject( - self->client, &err, py_ctx, &static_pool, SERIALIZER_PYTHON, true); + pctx = as_cdt_ctx_create_from_pyobject(self->client, &err, py_ctx, + &static_pool, SERIALIZER_PYTHON); if (err.code != AEROSPIKE_OK) { goto CLEANUP_CTX_ON_ERROR; } From 50c1add59bf53af724bfd1bf8c216f6b22536990 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Mon, 12 Jan 2026 08:56:59 -0800 Subject: [PATCH 48/57] fix --- src/main/client/cdt_list_operate.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/client/cdt_list_operate.c b/src/main/client/cdt_list_operate.c index c7911ac697..811b02a351 100644 --- a/src/main/client/cdt_list_operate.c +++ b/src/main/client/cdt_list_operate.c @@ -707,7 +707,7 @@ add_op_list_get_by_value_range(AerospikeClient *self, as_error *err, char *bin, as_val *val_end = NULL; as_cdt_ctx ctx; - + as_cdt_ctx *ctx_ref = NULL; int return_type = AS_LIST_RETURN_VALUE; if (get_list_return_type(err, op_dict, &return_type) != AEROSPIKE_OK) { @@ -724,7 +724,7 @@ add_op_list_get_by_value_range(AerospikeClient *self, as_error *err, char *bin, goto error; } - as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, static_pool, serializer_type); if (err->code != AEROSPIKE_OK) { goto error; @@ -1037,6 +1037,7 @@ static as_status add_op_list_remove_by_value_range( as_val *val_end = NULL; as_cdt_ctx ctx; + as_cdt_ctx *ctx_ref = NULL; int return_type = AS_LIST_RETURN_VALUE; if (get_list_return_type(err, op_dict, &return_type) != AEROSPIKE_OK) { @@ -1053,7 +1054,7 @@ static as_status add_op_list_remove_by_value_range( goto error; } - as_cdt_ctx *ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( + ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( self, err, &ctx, op_dict, static_pool, serializer_type); if (err->code != AEROSPIKE_OK) { goto error; From e5972212a7960eb675e2432c37785dce755a2c31 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 27 Jan 2026 16:05:01 -0800 Subject: [PATCH 49/57] fix --- src/main/client/operate.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/client/operate.c b/src/main/client/operate.c index cc39cacd4a..b09abfb0c3 100644 --- a/src/main/client/operate.c +++ b/src/main/client/operate.c @@ -107,9 +107,9 @@ static inline bool isExprOp(int op); } #define CONVERT_PY_CTX_TO_AS_CTX() \ - if (get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( \ - self, err, &ctx, py_operation_dict, &ctx_in_use, static_pool, \ - SERIALIZER_PYTHON) != AEROSPIKE_OK) { \ + ctx_ref = get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( \ + self, err, &ctx, py_operation_dict, static_pool, SERIALIZER_PYTHON); \ + if (err->code != AEROSPIKE_OK) { \ return err->code; \ } @@ -320,7 +320,6 @@ as_status add_op(AerospikeClient *self, as_error *err, as_val *put_range = NULL; as_cdt_ctx ctx; as_cdt_ctx *ctx_ref = NULL; - bool ctx_in_use = false; char *bin = NULL; char *val = NULL; long offset = 0; @@ -422,7 +421,6 @@ as_status add_op(AerospikeClient *self, as_error *err, } else if (strcmp(name, "ctx") == 0) { CONVERT_PY_CTX_TO_AS_CTX(); - ctx_ref = ctx_ref; } else if (strcmp(name, "map_order") == 0) { py_map_order = value; @@ -880,7 +878,7 @@ as_status add_op(AerospikeClient *self, as_error *err, if (mod_exp) { as_exp_destroy(mod_exp); } - if (ctx_in_use) { + if (ctx_ref) { as_cdt_ctx_destroy(&ctx); } From bbbdb2ab1b74c66603c3d6a4a52e77c246685422 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 27 Jan 2026 16:28:24 -0800 Subject: [PATCH 50/57] Clean up docstrings --- src/include/conversions.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index 5c8ba7f30e..43e6957824 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -167,21 +167,21 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, PyObject **pyuni_r, char **c_str_ptr, as_error *err); -// Sets err on error. Return value can be NULL if as_cdt_ctx is optional -// Returns as_cdt_ctx * value to be passed to the C client API +// Returns a reference to as_cdt_ctx to be passed to the C client API +// This assumes that the C client API's ctx parameter is optional and can accept a NULL value +// Sets err on error. +// The API calls that take in a Python list of contexts doesn't check the parameter's type, so we check it here. as_cdt_ctx *as_cdt_ctx_create_from_pyobject(AerospikeClient *self, as_error *err, PyObject *py_ctx_list, as_static_pool *static_pool, int serializer_type); -// This function takes in a python list of contexts from aerospike_helpers.cdt_ctx -// and converts it to an as_cdt_ctx object for use with the c-client. -// -// The cdt_ctx parameter should point to an uninitialized as_cdt_ctx -// object. This function will initialize it, and call as_cdt_ctx_destroy on it IF an error occurs. Otherwise, the caller -// must do it themselves when they are done with the object. +// This returns the as_cdt_ctx* value to be passed to the C client API // +// If the cdt_ctx argument is non-NULL, it should point to an uninitialized as_cdt_ctx object. +// If this call succeeds and returns a non-NULL as_cdt_ctx reference, the user is responsible for destroying it. +// Sets err on error. // The API calls that take in a Python list of contexts doesn't check the parameter's type, so we check it here. as_cdt_ctx *as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, From 6d1d5dc33c49a145d9bb469714b87563ebd16876 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 27 Jan 2026 16:34:01 -0800 Subject: [PATCH 51/57] Polish --- src/include/conversions.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index 43e6957824..67c91f720f 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -167,7 +167,9 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, PyObject **pyuni_r, char **c_str_ptr, as_error *err); -// Returns a reference to as_cdt_ctx to be passed to the C client API +// This takes in a Python "list of contexts" argument from an API, +// and returns the as_cdt_ctx* value to be passed to the C client API +// // This assumes that the C client API's ctx parameter is optional and can accept a NULL value // Sets err on error. // The API calls that take in a Python list of contexts doesn't check the parameter's type, so we check it here. @@ -177,18 +179,26 @@ as_cdt_ctx *as_cdt_ctx_create_from_pyobject(AerospikeClient *self, as_static_pool *static_pool, int serializer_type); -// This returns the as_cdt_ctx* value to be passed to the C client API +// This takes in a Python "list of contexts" argument from an API, +// and returns the as_cdt_ctx* value to be passed to the C client API // -// If the cdt_ctx argument is non-NULL, it should point to an uninitialized as_cdt_ctx object. +// The cdt_ctx argument *must* point to an uninitialized as_cdt_ctx object in order to initialize it. // If this call succeeds and returns a non-NULL as_cdt_ctx reference, the user is responsible for destroying it. // Sets err on error. // The API calls that take in a Python list of contexts doesn't check the parameter's type, so we check it here. as_cdt_ctx *as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, - PyObject *py_cdt_ctx, + PyObject *py_ctx_list, as_static_pool *static_pool, int serializer_type); +// This takes in a Python operations dictionary created from aerospike_helpers.operations, +// and returns the as_cdt_ctx* value to be passed to the C client API that adds operations +// +// The cdt_ctx argument *must* point to an uninitialized as_cdt_ctx object in order to initialize it. +// If this call succeeds and returns a non-NULL as_cdt_ctx reference, the user is responsible for destroying it. +// Sets err on error. +// The API calls that take in a Python list of contexts doesn't check the parameter's type, so we check it here. as_cdt_ctx *get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_op_dict, as_static_pool *static_pool, int serializer_type); From a1a4389b6b32568e0664c074e6bf3001347c5624 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 27 Jan 2026 16:40:52 -0800 Subject: [PATCH 52/57] fix --- src/main/convert_expressions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/convert_expressions.c b/src/main/convert_expressions.c index c76c442bb2..22fc2358d0 100644 --- a/src/main/convert_expressions.c +++ b/src/main/convert_expressions.c @@ -1836,7 +1836,7 @@ as_status as_exp_new_from_pyobject(AerospikeClient *self, PyObject *py_expr, py_ctx_list_p = PyDict_GetItemString(temp_expr.pydict, CTX_KEY); if (py_ctx_list_p != NULL) { temp_expr.ctx = as_cdt_ctx_create_from_pyobject( - self, err, temp_expr.pydict, &static_pool, SERIALIZER_PYTHON); + self, err, py_ctx_list_p, &static_pool, SERIALIZER_PYTHON); if (err->code != AEROSPIKE_OK) { goto CLEANUP; } From 0019f21f548a2c2cfb41fdbdedb95b128d56fa50 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 28 Jan 2026 09:49:51 -0800 Subject: [PATCH 53/57] clear up --- src/include/conversions.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/include/conversions.h b/src/include/conversions.h index 67c91f720f..894a26a97d 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -183,6 +183,7 @@ as_cdt_ctx *as_cdt_ctx_create_from_pyobject(AerospikeClient *self, // and returns the as_cdt_ctx* value to be passed to the C client API // // The cdt_ctx argument *must* point to an uninitialized as_cdt_ctx object in order to initialize it. +// This method is only used for stack allocated as_cdt_ctx objects where the C client API only needs to use it once. // If this call succeeds and returns a non-NULL as_cdt_ctx reference, the user is responsible for destroying it. // Sets err on error. // The API calls that take in a Python list of contexts doesn't check the parameter's type, so we check it here. From 4b750678d9fa74ef21964f9b7cf9adcda929558e Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 28 Jan 2026 09:51:35 -0800 Subject: [PATCH 54/57] DRY --- src/include/conversions.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index 894a26a97d..ba8478cc20 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -186,7 +186,7 @@ as_cdt_ctx *as_cdt_ctx_create_from_pyobject(AerospikeClient *self, // This method is only used for stack allocated as_cdt_ctx objects where the C client API only needs to use it once. // If this call succeeds and returns a non-NULL as_cdt_ctx reference, the user is responsible for destroying it. // Sets err on error. -// The API calls that take in a Python list of contexts doesn't check the parameter's type, so we check it here. +// The Python client's API calls that take in a Python list of contexts don't check the parameter's type, so we check it here. as_cdt_ctx *as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_ctx_list, @@ -196,10 +196,7 @@ as_cdt_ctx *as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, // This takes in a Python operations dictionary created from aerospike_helpers.operations, // and returns the as_cdt_ctx* value to be passed to the C client API that adds operations // -// The cdt_ctx argument *must* point to an uninitialized as_cdt_ctx object in order to initialize it. -// If this call succeeds and returns a non-NULL as_cdt_ctx reference, the user is responsible for destroying it. -// Sets err on error. -// The API calls that take in a Python list of contexts doesn't check the parameter's type, so we check it here. +// See second paragraph of docstring for "as_cdt_ctx_init_from_pyobject" as_cdt_ctx *get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_op_dict, as_static_pool *static_pool, int serializer_type); From 1628950ea593e690bd2acfd7b6c361cd51280aaa Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 28 Jan 2026 10:24:21 -0800 Subject: [PATCH 55/57] Reduce repetition in comments --- src/include/conversions.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/include/conversions.h b/src/include/conversions.h index ba8478cc20..c979ae9637 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -171,6 +171,7 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string, // and returns the as_cdt_ctx* value to be passed to the C client API // // This assumes that the C client API's ctx parameter is optional and can accept a NULL value +// If this call succeeds and returns a non-NULL as_cdt_ctx reference, the user is responsible for destroying it. // Sets err on error. // The API calls that take in a Python list of contexts doesn't check the parameter's type, so we check it here. as_cdt_ctx *as_cdt_ctx_create_from_pyobject(AerospikeClient *self, @@ -179,14 +180,10 @@ as_cdt_ctx *as_cdt_ctx_create_from_pyobject(AerospikeClient *self, as_static_pool *static_pool, int serializer_type); -// This takes in a Python "list of contexts" argument from an API, -// and returns the as_cdt_ctx* value to be passed to the C client API +// See docstring for as_cdt_ctx_create_from_pyobject // // The cdt_ctx argument *must* point to an uninitialized as_cdt_ctx object in order to initialize it. // This method is only used for stack allocated as_cdt_ctx objects where the C client API only needs to use it once. -// If this call succeeds and returns a non-NULL as_cdt_ctx reference, the user is responsible for destroying it. -// Sets err on error. -// The Python client's API calls that take in a Python list of contexts don't check the parameter's type, so we check it here. as_cdt_ctx *as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_ctx_list, @@ -196,7 +193,7 @@ as_cdt_ctx *as_cdt_ctx_init_from_pyobject(AerospikeClient *self, as_error *err, // This takes in a Python operations dictionary created from aerospike_helpers.operations, // and returns the as_cdt_ctx* value to be passed to the C client API that adds operations // -// See second paragraph of docstring for "as_cdt_ctx_init_from_pyobject" +// See docstring for as_cdt_ctx_init_from_pyobject as_cdt_ctx *get_optional_cdt_ctx_from_py_dict_and_as_cdt_ctx_init( AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx, PyObject *py_op_dict, as_static_pool *static_pool, int serializer_type); From c6858ac819fb62bd6fce559729c8db53d5b83eb9 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 28 Jan 2026 10:30:10 -0800 Subject: [PATCH 56/57] Fix memory error where as_cdt_ctx_destroy is called on an uninitialized as_cdt_ctx obj --- src/main/client/get_cdtctx_base64.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/client/get_cdtctx_base64.c b/src/main/client/get_cdtctx_base64.c index 7936f0ed47..0edff4b22d 100644 --- a/src/main/client/get_cdtctx_base64.c +++ b/src/main/client/get_cdtctx_base64.c @@ -75,11 +75,14 @@ PyObject *AerospikeClient_GetCDTCTXBase64(AerospikeClient *self, PyObject *args, as_cdt_ctx *ctx_ref = as_cdt_ctx_init_from_pyobject( self, &err, &ctx, py_cdtctx, &static_pool, SERIALIZER_PYTHON); - if (ctx_ref == NULL) { + if (err.code != AEROSPIKE_OK) { + goto CLEANUP; + } + else if (ctx_ref == NULL) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "cdt ctx must be valid " ", generated by aerospike cdt context helper"); - goto CLEANUP2; + goto CLEANUP; } //convert cdtctx to base64 From c9f60f857e47605fa6fd87b5c7831051762a416f Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 28 Jan 2026 17:05:29 -0800 Subject: [PATCH 57/57] Fix --- src/main/client/sec_index.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/client/sec_index.c b/src/main/client/sec_index.c index accb0846f3..5b0a5acbbc 100644 --- a/src/main/client/sec_index.c +++ b/src/main/client/sec_index.c @@ -255,6 +255,8 @@ PyObject *AerospikeClient_Index_Cdt_Create(AerospikeClient *self, as_cdt_ctx *ctx_ref = as_cdt_ctx_init_from_pyobject( self, &err, &ctx, py_ctx, &static_pool, SERIALIZER_PYTHON); if (ctx_ref == NULL) { + as_error_update(&err, AEROSPIKE_ERR_PARAM, + "ctx is a required argument and must not be None"); goto CLEANUP; }