2626
2727AerospikeQuery * AerospikeQuery_Apply (AerospikeQuery * self , PyObject * args , PyObject * kwds )
2828{
29- as_error err ;
3029
31- // Initialize error
30+ // Python function arguments
31+ PyObject * py_module = NULL ;
32+ PyObject * py_function = NULL ;
33+ PyObject * py_args = NULL ;
34+ PyObject * py_policy = NULL ;
35+
36+ // Python function keyword arguments
37+ static char * kwlist [] = {"module" , "function" , "arguments" , "policy" , NULL };
38+
39+ if ( PyArg_ParseTupleAndKeywords (args , kwds , "OO|OO:apply" , kwlist , & py_module , & py_function , & py_args , & py_policy ) == false ){
40+ return NULL ;
41+ }
42+
43+ // Aerospike error object
44+ as_error err ;
45+ // Initialize error object
3246 as_error_init (& err );
3347
34- int nargs = (int ) PyTuple_Size (args );
48+ if ( !self || !self -> client -> as ){
49+ as_error_update (& err , AEROSPIKE_ERR_PARAM , "Invalid query object" );
50+ goto CLEANUP ;
51+ }
3552
3653 // Aerospike API Arguments
3754 char * module = NULL ;
3855 char * function = NULL ;
3956 as_arraylist * arglist = NULL ;
4057
41- // too few args
42- if ( nargs < 2 ) {
43- as_error_update (& err , AEROSPIKE_ERR_CLIENT , "udf module and function names are required." );
44- goto CLEANUP ;
45- }
46-
47- // Python Arguments
48- PyObject * py_module = PyTuple_GetItem (args , 0 );
49- PyObject * py_function = PyTuple_GetItem (args , 1 );
50-
5158 if ( PyString_Check (py_module ) ) {
5259 module = PyString_AsString (py_module );
5360 }
@@ -64,10 +71,13 @@ AerospikeQuery * AerospikeQuery_Apply(AerospikeQuery * self, PyObject * args, Py
6471 goto CLEANUP ;
6572 }
6673
67- if ( nargs > 2 ) {
68- arglist = as_arraylist_new (nargs - 2 , 0 );
69- for ( int i = 2 ; i < nargs ; i ++ ) {
70- PyObject * py_val = PyTuple_GetItem (args , i );
74+ if ( py_args && PyList_Check (py_args ) ){
75+ Py_ssize_t size = PyList_Size (py_args );
76+
77+ arglist = as_arraylist_new (size , 0 );
78+
79+ for ( int i = 0 ; i < size ; i ++ ) {
80+ PyObject * py_val = PyList_GetItem (py_args , (Py_ssize_t )i );
7181 as_val * val = NULL ;
7282 pyobject_to_val (& err , py_val , & val );
7383 if ( err .code != AEROSPIKE_OK ) {
0 commit comments