55
66#define MAXLENGTH 2048
77
8- #if PY_MAJOR_VERSION >= 3
9- #define PyInt_Type PyLong_Type
10- #define PyInt_Check PyLong_Check
11- #define PyString_Type PyUnicode_Type
12- #define PyString_AsString PyUnicode_AsUTF8
13- #define PyString_Check PyUnicode_Check
14- #define PyString_GET_SIZE PyUnicode_GET_LENGTH
15- #endif
16-
178static PyObject * SpudError ;
189static PyObject * SpudTypeError ;
1910static PyObject * SpudKeyError ;
@@ -229,15 +220,15 @@ libspud_get_option_type(PyObject *self, PyObject *args)
229220 return (PyObject * ) & PyFloat_Type ;
230221 }
231222 else if (type == SPUD_INT ){
232- Py_INCREF (& PyInt_Type );
233- return (PyObject * ) & PyInt_Type ;
223+ Py_INCREF (& PyLong_Type );
224+ return (PyObject * ) & PyLong_Type ;
234225 }
235226 else if (type == SPUD_NONE ){
236227 Py_RETURN_NONE ;
237228 }
238229 else if (type == SPUD_STRING ){
239- Py_INCREF (& PyString_Type );
240- return (PyObject * ) & PyString_Type ;
230+ Py_INCREF (& PyUnicode_Type );
231+ return (PyObject * ) & PyUnicode_Type ;
241232 }
242233
243234 PyErr_SetString (SpudError ,"Error: Get option type function failed" );
@@ -562,7 +553,7 @@ set_option_aux_list_doubles(PyObject *pylist, const char *key, int key_len, int
562553static PyObject *
563554set_option_aux_string (PyObject * pystring , const char * key , int key_len , int type , int rank , int * shape )
564555{ // this function is for setting option when the second argument is of type string
565- const char * val = PyString_AsString (pystring );
556+ const char * val = PyUnicode_AsUTF8 (pystring );
566557 int outcomeSetOption = spud_set_option (key , key_len , val , type , rank , shape );
567558 return error_checking (outcomeSetOption , "set option aux string" );
568559}
@@ -702,18 +693,16 @@ libspud_set_option(PyObject *self, PyObject *args)
702693 int outcomeAddOption = spud_add_option (key , key_len );
703694 error_checking (outcomeAddOption , "set option" );
704695 }
705-
706- if (PyInt_Check (secondArg )){ //just an int
696+ if (PyLong_Check (secondArg )){ //just an int
707697 type = SPUD_INT ;
708698 rank = 0 ;
709699 shape [0 ] = -1 ;
710700 shape [1 ] = -1 ;
711-
712701 }
713- else if (PyString_Check (secondArg )){// a string
702+ else if (PyUnicode_Check (secondArg )){// a Unicode string
714703 type = SPUD_STRING ;
715704 rank = 1 ;
716- shape [0 ] = PyString_GET_SIZE (secondArg );
705+ shape [0 ] = PyUnicode_GET_LENGTH (secondArg );
717706 shape [1 ] = -1 ;
718707 }
719708 else if (PyFloat_Check (secondArg )){// a double
@@ -724,7 +713,7 @@ libspud_set_option(PyObject *self, PyObject *args)
724713 }
725714 else if (PyList_Check (secondArg )){
726715 PyObject * listElement = PyList_GetItem (secondArg , 0 );
727- if (PyInt_Check (listElement )){ //list of ints
716+ if (PyLong_Check (listElement )){ //list of ints
728717 type = SPUD_INT ;
729718 rank = 1 ;
730719 shape [0 ] = 1 ;
@@ -740,7 +729,7 @@ libspud_set_option(PyObject *self, PyObject *args)
740729 int pylistSize = PyList_GET_SIZE (secondArg );
741730 int pysublistSize = PyList_GET_SIZE (listElement );
742731 PyObject * sublistElement = PyList_GetItem (listElement , 0 );
743- if (PyInt_Check (sublistElement )){ //list of lists of ints
732+ if (PyLong_Check (sublistElement )){ //list of lists of ints
744733 type = SPUD_INT ;
745734 }
746735 else if (PyFloat_Check (sublistElement )){//list of lists of doubles
@@ -756,7 +745,7 @@ libspud_set_option(PyObject *self, PyObject *args)
756745 set_option_aux_scalar (secondArg , key , key_len , type , rank , shape );
757746 }
758747 else if (rank == 1 ){ // list or string
759- if (PyString_Check (secondArg )){ // pystring
748+ if (PyUnicode_Check (secondArg )){ // pystring
760749 set_option_aux_string (secondArg , key , key_len , type , rank , shape );
761750 }
762751 else if (type == SPUD_INT ) { // list of ints
0 commit comments