@@ -183,12 +183,12 @@ static CTypeDescrObject *_ffi_type(FFIObject *ffi, PyObject *arg,
183183 /* Returns the CTypeDescrObject from the user-supplied 'arg'.
184184 Does not return a new reference!
185185 */
186- if ((accept & ACCEPT_STRING ) && PyText_Check (arg )) {
186+ if ((accept & ACCEPT_STRING ) && PyUnicode_Check (arg )) {
187187 PyObject * types_dict = ffi -> types_builder .types_dict ;
188188 PyObject * x = PyDict_GetItem (types_dict , arg );
189189
190190 if (x == NULL ) {
191- const char * input_text = PyText_AS_UTF8 (arg );
191+ const char * input_text = PyUnicode_AsUTF8 (arg );
192192 int err , index = parse_c_type (& ffi -> info , input_text );
193193 if (index < 0 )
194194 return _ffi_bad_type (ffi , input_text );
@@ -226,17 +226,6 @@ static CTypeDescrObject *_ffi_type(FFIObject *ffi, PyObject *arg,
226226 else if ((accept & ACCEPT_CDATA ) && CData_Check (arg )) {
227227 return ((CDataObject * )arg )-> c_type ;
228228 }
229- #if PY_MAJOR_VERSION < 3
230- else if (PyUnicode_Check (arg )) {
231- CTypeDescrObject * result ;
232- arg = PyUnicode_AsASCIIString (arg );
233- if (arg == NULL )
234- return NULL ;
235- result = _ffi_type (ffi , arg , accept );
236- Py_DECREF (arg );
237- return result ;
238- }
239- #endif
240229 else {
241230 const char * m1 = (accept & ACCEPT_STRING ) ? "string" : "" ;
242231 const char * m2 = (accept & ACCEPT_CTYPE ) ? "ctype object" : "" ;
@@ -272,7 +261,7 @@ static PyObject *ffi_sizeof(FFIObject *self, PyObject *arg)
272261 return NULL ;
273262 }
274263 }
275- return PyInt_FromSsize_t (size );
264+ return PyLong_FromSsize_t (size );
276265}
277266
278267PyDoc_STRVAR (ffi_alignof_doc ,
@@ -289,7 +278,7 @@ static PyObject *ffi_alignof(FFIObject *self, PyObject *arg)
289278 align = get_alignment (ct );
290279 if (align < 0 )
291280 return NULL ;
292- return PyInt_FromLong (align );
281+ return PyLong_FromLong (align );
293282}
294283
295284PyDoc_STRVAR (ffi_typeof_doc ,
@@ -507,7 +496,7 @@ static PyObject *ffi_offsetof(FFIObject *self, PyObject *args)
507496 return NULL ;
508497 offset += ofs1 ;
509498 }
510- return PyInt_FromSsize_t (offset );
499+ return PyLong_FromSsize_t (offset );
511500}
512501
513502PyDoc_STRVAR (ffi_addressof_doc ,
@@ -620,9 +609,7 @@ static PyObject *ffi_getctype(FFIObject *self, PyObject *args, PyObject *kwds)
620609 CTypeDescrObject * ct ;
621610 size_t replace_with_len ;
622611 static char * keywords [] = {"cdecl" , "replace_with" , NULL };
623- #if PY_MAJOR_VERSION >= 3
624612 PyObject * u ;
625- #endif
626613
627614 if (!PyArg_ParseTupleAndKeywords (args , kwds , "O|s:getctype" , keywords ,
628615 & c_decl , & replace_with ))
@@ -656,14 +643,12 @@ static PyObject *ffi_getctype(FFIObject *self, PyObject *args, PyObject *kwds)
656643 if (add_paren )
657644 p [replace_with_len ] = ')' ;
658645
659- #if PY_MAJOR_VERSION >= 3
660646 /* bytes -> unicode string */
661647 u = PyUnicode_DecodeLatin1 (PyBytes_AS_STRING (res ),
662648 PyBytes_GET_SIZE (res ),
663649 NULL );
664650 Py_DECREF (res );
665651 res = u ;
666- #endif
667652
668653 return res ;
669654}
@@ -912,7 +897,7 @@ static PyObject *ffi_list_types(FFIObject *self, PyObject *noargs)
912897 goto error ;
913898
914899 for (i = 0 ; i < n1 ; i ++ ) {
915- o = PyText_FromString (self -> types_builder .ctx .typenames [i ].name );
900+ o = PyUnicode_FromString (self -> types_builder .ctx .typenames [i ].name );
916901 if (o == NULL )
917902 goto error ;
918903 PyList_SET_ITEM (lst [0 ], i , o );
@@ -926,7 +911,7 @@ static PyObject *ffi_list_types(FFIObject *self, PyObject *noargs)
926911 if (s -> name [0 ] == '$' )
927912 continue ;
928913
929- o = PyText_FromString (s -> name );
914+ o = PyUnicode_FromString (s -> name );
930915 if (o == NULL )
931916 goto error ;
932917 index = (s -> flags & _CFFI_F_UNION ) ? 2 : 1 ;
@@ -971,22 +956,13 @@ PyDoc_STRVAR(ffi_init_once_doc,
971956"of function() is done. If function() raises an exception, it is\n"
972957"propagated and nothing is cached." );
973958
974- #if PY_MAJOR_VERSION < 3
975- /* PyCapsule_New is redefined to be PyCObject_FromVoidPtr in _cffi_backend,
976- which gives 2.6 compatibility; but the destructor signature is different */
977- static void _free_init_once_lock (void * lock )
978- {
979- PyThread_free_lock ((PyThread_type_lock )lock );
980- }
981- #else
982959static void _free_init_once_lock (PyObject * capsule )
983960{
984961 PyThread_type_lock lock ;
985962 lock = PyCapsule_GetPointer (capsule , "cffi_init_once_lock" );
986963 if (lock != NULL )
987964 PyThread_free_lock (lock );
988965}
989- #endif
990966
991967static PyObject * ffi_init_once (FFIObject * self , PyObject * args , PyObject * kwds )
992968{
0 commit comments