/** ******************************************************************************************************** * Scan the map and apply a predicate filter. * * @param self AerospikeLMap object * @param args The args is a tuple object containing an argument * list passed from Python to a C function * @param kwds Dictionary of keywords * * Returns a list of elements from the map after applying predicate. * In case of error,appropriate exceptions will be raised. ******************************************************************************************************** */ PyObject * AerospikeLMap_Filter(AerospikeLMap * self, PyObject * args, PyObject * kwds) { char* filter_name = NULL; PyObject * py_args = NULL; PyObject* py_policy = NULL; as_policy_apply apply_policy; as_policy_apply* apply_policy_p = NULL; as_list* arg_list = NULL; as_map* elements = NULL; as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); as_error err; as_error_init(&err); static char * kwlist[] = {"udf_function_name", "args", "policy", NULL}; // Python Function Argument Parsing if ( PyArg_ParseTupleAndKeywords(args, kwds, "|sOO:filter", kwlist, &filter_name, &py_args, &py_policy) == false ) { return NULL; } if (!self || !self->client->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->client->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } // Convert python policy object to as_policy_apply pyobject_to_policy_apply(&err, py_policy, &apply_policy, &apply_policy_p, &self->client->as->config.policies.apply); if ( err.code != AEROSPIKE_OK ) { goto CLEANUP; } if ( py_args && !filter_name) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Filter arguments without filter name"); goto CLEANUP; } if ( py_args && !PyList_Check(py_args)) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid filter argument(type)"); goto CLEANUP; } if (py_args) { pyobject_to_list(&err, py_args, &arg_list, &static_pool, SERIALIZER_PYTHON); } aerospike_lmap_filter(self->client->as, &err, apply_policy_p, &self->key, &self->lmap, filter_name, arg_list, &elements); if (err.code != AEROSPIKE_OK) { as_error_update(&err, err.code, NULL); goto CLEANUP; } PyObject* py_map = NULL; map_to_pyobject(&err, elements, &py_map); CLEANUP: if (elements) { as_map_destroy(elements); } if (arg_list) { as_list_destroy(arg_list); } if ( err.code != AEROSPIKE_OK ) { PyObject * py_err = NULL, *py_key = NULL; PyObject *exception_type = raise_exception(&err); error_to_pyobject(&err, &py_err); if(PyObject_HasAttrString(exception_type, "key")) { key_to_pyobject(&err, &self->key, &py_key); PyObject_SetAttrString(exception_type, "key", py_key); Py_DECREF(py_key); } if(PyObject_HasAttrString(exception_type, "bin")) { PyObject *py_bins = PyString_FromString((char *)&self->bin_name); PyObject_SetAttrString(exception_type, "bin", py_bins); Py_DECREF(py_bins); } PyErr_SetObject(exception_type, py_err); Py_DECREF(py_err); return NULL; } return py_map; }
/** ******************************************************************************************************* * This function applies a registered udf module on a particular record. * * @param self AerospikeClient object * @param py_key The key under which to store the record. * @param py_module The module name. * @param py_function The UDF function to be applied on a record. * @param py_arglist The arguments to the UDF function * @param py_policy The optional policy parameters * * Returns the result of UDF function. ******************************************************************************************************* */ PyObject * AerospikeClient_Apply_Invoke( AerospikeClient * self, PyObject * py_key, PyObject * py_module, PyObject * py_function, PyObject * py_arglist, PyObject * py_policy) { // Python Return Value PyObject * py_result = NULL; // Aerospike Client Arguments as_error err; as_policy_apply apply_policy; as_policy_apply * apply_policy_p = NULL; as_key key; char * module = NULL; char * function = NULL; as_list * arglist = NULL; as_val * result = NULL; PyObject * py_umodule = NULL; PyObject * py_ufunction = NULL; // Initialisation flags bool key_initialised = false; // Initialize error as_error_init(&err); if( !PyList_Check(py_arglist) ) { PyErr_SetString(PyExc_TypeError, "expected UDF method arguments in a 'list'"); return NULL; } if (!self || !self->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } // Convert python key object to as_key pyobject_to_key(&err, py_key, &key); if ( err.code != AEROSPIKE_OK ) { goto CLEANUP; } // Key is initialiased successfully key_initialised = true; // Convert python list to as_list pyobject_to_list(self, &err, py_arglist, &arglist, NULL, -1); if ( err.code != AEROSPIKE_OK ) { goto CLEANUP; } // Convert python policy object to as_policy_apply pyobject_to_policy_apply(&err, py_policy, &apply_policy, &apply_policy_p, &self->as->config.policies.apply); if ( err.code != AEROSPIKE_OK ) { goto CLEANUP; } if ( PyUnicode_Check(py_module) ) { py_umodule = PyUnicode_AsUTF8String(py_module); module = PyStr_AsString(py_umodule); } else if ( PyStr_Check(py_module) ) { module = PyStr_AsString(py_module); } else { as_error_update(&err, AEROSPIKE_ERR_CLIENT, "udf module argument must be a string or unicode string"); goto CLEANUP; } if ( PyUnicode_Check(py_function) ) { py_ufunction = PyUnicode_AsUTF8String(py_function); function = PyStr_AsString(py_ufunction); } else if ( PyStr_Check(py_function) ) { function = PyStr_AsString(py_function); } else { as_error_update(&err, AEROSPIKE_ERR_CLIENT, "function name must be a string or unicode string"); goto CLEANUP; } // Invoke operation aerospike_key_apply(self->as, &err, apply_policy_p, &key, module, function, arglist, &result); if ( err.code == AEROSPIKE_OK ) { val_to_pyobject(&err, result, &py_result); } else { as_error_update(&err, err.code, NULL); } CLEANUP: if (py_umodule) { Py_DECREF(py_umodule); } if (py_ufunction) { Py_DECREF(py_ufunction); } if (key_initialised == true) { // Destroy the key if it is initialised successfully. as_key_destroy(&key); } as_list_destroy(arglist); as_val_destroy(result); if ( err.code != AEROSPIKE_OK ) { PyObject * py_err = NULL; error_to_pyobject(&err, &py_err); PyObject *exception_type = raise_exception(&err); if(PyObject_HasAttrString(exception_type, "key")) { PyObject_SetAttrString(exception_type, "key", py_key); } if(PyObject_HasAttrString(exception_type, "bin")) { PyObject_SetAttrString(exception_type, "bin", Py_None); } if(PyObject_HasAttrString(exception_type, "module")) { PyObject_SetAttrString(exception_type, "module", py_module); } if(PyObject_HasAttrString(exception_type, "func")) { PyObject_SetAttrString(exception_type, "func", py_function); } PyErr_SetObject(exception_type, py_err); Py_DECREF(py_err); return NULL; } return py_result; }
/** ******************************************************************************************************** * Add a list of objects to the set. * * @param self AerospikeLSet object * @param args The args is a tuple object containing an argument * list passed from Python to a C function * @param kwds Dictionary of keywords * * Returns an integer status. 0(Zero) is success value. * In case of error,appropriate exceptions will be raised. ******************************************************************************************************** */ PyObject * AerospikeLSet_Add_Many(AerospikeLSet * self, PyObject * args, PyObject * kwds) { PyObject* py_arglist = NULL; PyObject* py_policy = NULL; as_policy_apply apply_policy; as_policy_apply* apply_policy_p = NULL; as_list* arglist = NULL; as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); as_error err; as_error_init(&err); static char * kwlist[] = {"values", "policy", NULL}; // Python Function Argument Parsing if ( PyArg_ParseTupleAndKeywords(args, kwds, "O|O:add_many", kwlist, &py_arglist, &py_policy)== false ) { return NULL; } if (!self || !self->client->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->client->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } // Convert python policy object to as_policy_apply pyobject_to_policy_apply(&err, py_policy, &apply_policy, &apply_policy_p, &self->client->as->config.policies.apply); if ( err.code != AEROSPIKE_OK ) { goto CLEANUP; } /* * Convert python list to as list */ if ( !PyList_Check(py_arglist)) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid argument(type)"); goto CLEANUP; } pyobject_to_list(&err, py_arglist, &arglist, &static_pool, SERIALIZER_PYTHON); if (err.code != AEROSPIKE_OK) { goto CLEANUP; } aerospike_lset_add_all(self->client->as, &err, apply_policy_p, &self->key, &self->lset, arglist); if( err.code != AEROSPIKE_OK ) { as_error_update(&err, err.code, NULL); } CLEANUP: if (arglist) { as_list_destroy(arglist); } if ( err.code != AEROSPIKE_OK ) { PyObject * py_err = NULL, *py_key = NULL; PyObject *exception_type = raise_exception(&err); error_to_pyobject(&err, &py_err); if(PyObject_HasAttrString(exception_type, "key")) { key_to_pyobject(&err, &self->key, &py_key); PyObject_SetAttrString(exception_type, "key", py_key); Py_DECREF(py_key); } if(PyObject_HasAttrString(exception_type, "bin")) { PyObject *py_bins = PyString_FromString((char *)&self->bin_name); PyObject_SetAttrString(exception_type, "bin", py_bins); Py_DECREF(py_bins); } PyErr_SetObject(exception_type, py_err); Py_DECREF(py_err); return NULL; } return PyLong_FromLong(0); }
/** * Scans a set in the Aerospike DB and applies UDF on it. * * @param self The c client's aerospike object. * @param namespace_p The namespace to scan. * @param set_p The set to scan. * @param module_p The name of UDF module containing the * function to execute. * @param function_p The name of the function to be applied * to the record. * @param py_args An array of arguments for the UDF. * @py_policy The optional policy. * @py_options The optional scan options to set. */ static PyObject * AerospikeClient_ScanApply_Invoke( AerospikeClient * self, char* namespace_p, PyObject * py_set, PyObject * py_module, PyObject * py_function, PyObject * py_args, PyObject * py_policy, PyObject * py_options, bool block) { as_list* arglist = NULL; as_policy_scan scan_policy; as_policy_scan* scan_policy_p = NULL; as_policy_info info_policy; as_policy_info* info_policy_p = NULL; as_error err; as_scan scan; uint64_t scan_id = 0; bool is_scan_init = false; PyObject *py_ustr1 = NULL; PyObject *py_ustr2 = NULL; PyObject *py_ustr3 = NULL; as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); // Initialize error as_error_init(&err); if (!self || !self->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } self->is_client_put_serializer = false; if (!(namespace_p) || !(py_set) || !(py_module) || !(py_function)) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Parameter should not be null"); goto CLEANUP; } if (!PyList_Check(py_args)) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Arguments should be a list"); goto CLEANUP; } char *set_p = NULL; if (PyUnicode_Check(py_set)) { py_ustr1 = PyUnicode_AsUTF8String(py_set); set_p = PyString_AsString(py_ustr1); } else if (PyString_Check(py_set)) { set_p = PyString_AsString(py_set); } else if( Py_None != py_set ) { // Scan whole namespace if set is 'None' else error as_error_update(&err, AEROSPIKE_ERR_PARAM, "Set name should be string"); goto CLEANUP; } as_scan_init(&scan, namespace_p, set_p); is_scan_init = true; if (py_policy) { pyobject_to_policy_scan(&err, py_policy, &scan_policy, &scan_policy_p, &self->as->config.policies.scan); if (err.code != AEROSPIKE_OK) { goto CLEANUP; } } if (py_options && PyDict_Check(py_options)) { set_scan_options(&err, &scan, py_options); } if (err.code != AEROSPIKE_OK) { goto CLEANUP; } char *module_p = NULL; if (PyUnicode_Check(py_module)) { py_ustr2 = PyUnicode_AsUTF8String(py_module); module_p = PyString_AsString(py_ustr2); } else if (PyString_Check(py_module)) { module_p = PyString_AsString(py_module); } else { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Module name should be string"); goto CLEANUP; } char *function_p = NULL; if (PyUnicode_Check(py_function)) { py_ustr3 = PyUnicode_AsUTF8String(py_function); function_p = PyString_AsString(py_ustr3); } else if (PyString_Check(py_function)) { function_p = PyString_AsString(py_function); } else { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Function name should be string"); goto CLEANUP; } pyobject_to_list(self, &err, py_args, &arglist, &static_pool, SERIALIZER_PYTHON); if (err.code != AEROSPIKE_OK) { goto CLEANUP; } if (!as_scan_apply_each(&scan, module_p, function_p, arglist)) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Unable to apply UDF on the scan"); goto CLEANUP; } Py_BEGIN_ALLOW_THREADS aerospike_scan_background(self->as, &err, scan_policy_p, &scan, &scan_id); Py_END_ALLOW_THREADS arglist = NULL; if(err.code == AEROSPIKE_OK) { if(block) { if (py_policy) { pyobject_to_policy_info(&err, py_policy, &info_policy, &info_policy_p, &self->as->config.policies.info); if (err.code != AEROSPIKE_OK) { goto CLEANUP; } } Py_BEGIN_ALLOW_THREADS aerospike_scan_wait(self->as, &err, info_policy_p, scan_id, 0); Py_END_ALLOW_THREADS if(err.code != AEROSPIKE_OK) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Unable to perform scan_wait on the scan"); } } } else { goto CLEANUP;
/** ******************************************************************************************************** * Scan the stack and apply a predicate filter. * * @param self AerospikeLStack object * @param args The args is a tuple object containing an argument * list passed from Python to a C function * @param kwds Dictionary of keywords * * Returns a list of elements(peek_count) from the stack after applying predicate. * In case of error, Appropriate exceptions will be raised. ******************************************************************************************************** */ PyObject * AerospikeLStack_Filter(AerospikeLStack * self, PyObject * args, PyObject * kwds) { long peek_count = 0; char* filter_name = NULL; PyObject * py_args = NULL; PyObject* py_policy = NULL; as_policy_apply apply_policy; as_policy_apply* apply_policy_p = NULL; as_list* arg_list = NULL; as_list* elements_list = NULL; as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); as_error err; as_error_init(&err); static char * kwlist[] = {"peek_count", "udf_function_name", "args", "policy", NULL}; // Python Function Argument Parsing if ( PyArg_ParseTupleAndKeywords(args, kwds, "|lsOO:filter", kwlist, &peek_count, &filter_name, &py_args, &py_policy) == false ) { return NULL; } if (!self || !self->client || !self->client->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->client->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } // Convert python policy object to as_policy_apply pyobject_to_policy_apply(&err, py_policy, &apply_policy, &apply_policy_p, &self->client->as->config.policies.apply); if ( err.code != AEROSPIKE_OK ) { goto CLEANUP; } if ( py_args && !filter_name) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Filter arguments without filter name"); goto CLEANUP; } if ( py_args && !PyList_Check(py_args)) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid filter argument(type)"); goto CLEANUP; } if (py_args) { pyobject_to_list(&err, py_args, &arg_list, &static_pool, SERIALIZER_PYTHON); } aerospike_lstack_filter(self->client->as, &err, apply_policy_p, &self->key, &self->lstack, peek_count, filter_name, arg_list, &elements_list); if (err.code != AEROSPIKE_OK) { goto CLEANUP; } PyObject* py_list = NULL; list_to_pyobject(&err, elements_list, &py_list); CLEANUP: if (elements_list) { as_list_destroy(elements_list); } if (arg_list) { as_list_destroy(arg_list); } if ( err.code != AEROSPIKE_OK ) { PyObject * py_err = NULL; error_to_pyobject(&err, &py_err); PyErr_SetObject(PyExc_Exception, py_err); Py_DECREF(py_err); return NULL; } return py_list; }
static void initialize_bin_for_strictypes(AerospikeClient *self, as_error *err, PyObject *py_value, as_binop *binop, char *bin, as_static_pool *static_pool) { as_bin *binop_bin = &binop->bin; if (PyInt_Check(py_value)) { int val = PyInt_AsLong(py_value); as_integer_init((as_integer *) &binop_bin->value, val); binop_bin->valuep = &binop_bin->value; } else if (PyLong_Check(py_value)) { long val = PyLong_AsLong(py_value); as_integer_init((as_integer *) &binop_bin->value, val); binop_bin->valuep = &binop_bin->value; } else if (PyString_Check(py_value)) { char * val = PyString_AsString(py_value); as_string_init((as_string *) &binop_bin->value, val, false); binop_bin->valuep = &binop_bin->value; } else if (PyUnicode_Check(py_value)) { PyObject *py_ustr1 = PyUnicode_AsUTF8String(py_value); char * val = PyString_AsString(py_ustr1); as_string_init((as_string *) &binop_bin->value, val, false); binop_bin->valuep = &binop_bin->value; } else if (PyFloat_Check(py_value)) { int64_t val = PyFloat_AsDouble(py_value); if (aerospike_has_double(self->as)) { as_double_init((as_double *) &binop_bin->value, val); binop_bin->valuep = &binop_bin->value; } else { as_bytes *bytes; GET_BYTES_POOL(bytes, static_pool, err); serialize_based_on_serializer_policy(self, SERIALIZER_PYTHON, &bytes, py_value, err); ((as_val *) &binop_bin->value)->type = AS_UNKNOWN; binop_bin->valuep = (as_bin_value *) bytes; } } else if (PyList_Check(py_value)) { as_list * list = NULL; pyobject_to_list(self, err, py_value, &list, static_pool, SERIALIZER_PYTHON); ((as_val *) &binop_bin->value)->type = AS_UNKNOWN; binop_bin->valuep = (as_bin_value *) list; } else if (PyDict_Check(py_value)) { as_map * map = NULL; pyobject_to_map(self, err, py_value, &map, static_pool, SERIALIZER_PYTHON); ((as_val *) &binop_bin->value)->type = AS_UNKNOWN; binop_bin->valuep = (as_bin_value *) map; } else if (!strcmp(py_value->ob_type->tp_name, "aerospike.Geospatial")) { PyObject* py_data = PyObject_GenericGetAttr(py_value, PyString_FromString("geo_data")); char *geo_value = PyString_AsString(AerospikeGeospatial_DoDumps(py_data, err)); if (aerospike_has_geo(self->as)) { as_geojson_init((as_geojson *) &binop_bin->value, geo_value, false); binop_bin->valuep = &binop_bin->value; } else { as_bytes *bytes; GET_BYTES_POOL(bytes, static_pool, err); serialize_based_on_serializer_policy(self, SERIALIZER_PYTHON, &bytes, py_data, err); ((as_val *) &binop_bin->value)->type = AS_UNKNOWN; binop_bin->valuep = (as_bin_value *) bytes; } } else if (!strcmp(py_value->ob_type->tp_name, "aerospike.null")) { ((as_val *) &binop_bin->value)->type = AS_UNKNOWN; binop_bin->valuep = (as_bin_value *) &as_nil; } else if (PyByteArray_Check(py_value)) { as_bytes *bytes; GET_BYTES_POOL(bytes, static_pool, err); serialize_based_on_serializer_policy(self, SERIALIZER_PYTHON, &bytes, py_value, err); as_bytes_init_wrap((as_bytes *) &binop_bin->value, bytes->value, bytes->size, false); binop_bin->valuep = &binop_bin->value; } else { as_bytes *bytes; GET_BYTES_POOL(bytes, static_pool, err); serialize_based_on_serializer_policy(self, SERIALIZER_PYTHON, &bytes, py_value, err); ((as_val *) &binop_bin->value)->type = AS_UNKNOWN; binop_bin->valuep = (as_bin_value *) bytes; } strcpy(binop_bin->name, bin); }
/** ******************************************************************************************************** * Select values from the beginning of list up to a maximum count after applying * lua filter. * * @param self AerospikeLList object * @param args The args is a tuple object containing an argument * list passed from Python to a C function * @param kwds Dictionary of keywords * * Returns a list of elements from the list after applying predicate. * In case of error,appropriate exceptions will be raised. ******************************************************************************************************** */ PyObject * AerospikeLList_Find_First_Filter(AerospikeLList * self, PyObject * args, PyObject * kwds) { char* filter_name = NULL; PyObject * py_args = NULL; PyObject* py_policy = NULL; PyObject *py_count = NULL; as_policy_apply apply_policy; as_policy_apply* apply_policy_p = NULL; as_list* arg_list = NULL; as_list* elements_list = NULL; as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); as_error err; as_error_init(&err); static char * kwlist[] = {"count", "function", "args", "policy", NULL}; // Python Function Argument Parsing if ( PyArg_ParseTupleAndKeywords(args, kwds, "OsO|O:find_first_filter", kwlist, &py_count, &filter_name, &py_args, &py_policy) == false ) { return NULL; } if (!self || !self->client->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->client->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } // Convert python policy object to as_policy_apply pyobject_to_policy_apply(&err, py_policy, &apply_policy, &apply_policy_p, &self->client->as->config.policies.apply); if ( err.code != AEROSPIKE_OK ) { goto CLEANUP; } if ( py_args && !filter_name) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Filter arguments without filter name"); goto CLEANUP; } if ( py_args && !PyList_Check(py_args) && (py_args != Py_None)) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid filter argument(type)"); goto CLEANUP; } if (PyList_Check(py_args)) { pyobject_to_list(self->client, &err, py_args, &arg_list, &static_pool, SERIALIZER_PYTHON); } uint32_t count = 0; if ( PyInt_Check(py_count)) { count = PyInt_AsLong(py_count); } else if( PyLong_Check(py_count) ) { count = PyLong_AsLong(py_count); if (count == (uint32_t)-1 && PyErr_Occurred()) { if (PyErr_ExceptionMatches(PyExc_OverflowError)) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "integer value exceeds sys.maxsize"); goto CLEANUP; } } } else { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Count should be an integer or long"); goto CLEANUP; } Py_BEGIN_ALLOW_THREADS aerospike_llist_find_first_filter(self->client->as, &err, apply_policy_p, &self->key, &self->llist, count, filter_name, arg_list, &elements_list); Py_END_ALLOW_THREADS if (err.code != AEROSPIKE_OK) { goto CLEANUP; } PyObject* py_list = NULL; list_to_pyobject(self->client, &err, elements_list, &py_list); CLEANUP: if (elements_list) { as_list_destroy(elements_list); } if (arg_list) { as_list_destroy(arg_list); } if ( err.code != AEROSPIKE_OK ) { PyObject * py_err = NULL, *py_key = NULL; PyObject *exception_type = raise_exception(&err); error_to_pyobject(&err, &py_err); if (PyObject_HasAttrString(exception_type, "key")) { key_to_pyobject(&err, &self->key, &py_key); PyObject_SetAttrString(exception_type, "key", py_key); Py_DECREF(py_key); } if (PyObject_HasAttrString(exception_type, "bin")) { PyObject *py_bins = PyStr_FromString((char *)&self->bin_name); PyObject_SetAttrString(exception_type, "bin", py_bins); Py_DECREF(py_bins); } PyErr_SetObject(exception_type, py_err); Py_DECREF(py_err); return NULL; } return py_list; }