@@ -185,13 +185,13 @@ static CTypeDescrObject *_ffi_type(FFIObject *ffi, PyObject *arg,
185185 /* Returns the CTypeDescrObject from the user-supplied 'arg'.
186186 Does not return a new reference!
187187 */
188- if ((accept & ACCEPT_STRING ) && PyText_Check (arg )) {
188+ if ((accept & ACCEPT_STRING ) && PyUnicode_Check (arg )) {
189189 PyObject * types_dict = ffi -> types_builder .types_dict ;
190190 /* The types_dict keeps the reference alive. Items are never removed */
191191 PyObject * x = PyDict_GetItem (types_dict , arg );
192192
193193 if (x == NULL ) {
194- const char * input_text = PyText_AS_UTF8 (arg );
194+ const char * input_text = PyUnicode_AsUTF8 (arg );
195195 struct _cffi_parse_info_s info ;
196196 info .ctx = & ffi -> types_builder .ctx ;
197197 info .output_size = FFI_COMPLEXITY_OUTPUT ;
@@ -241,17 +241,6 @@ static CTypeDescrObject *_ffi_type(FFIObject *ffi, PyObject *arg,
241241 else if ((accept & ACCEPT_CDATA ) && CData_Check (arg )) {
242242 return ((CDataObject * )arg )-> c_type ;
243243 }
244- #if PY_MAJOR_VERSION < 3
245- else if (PyUnicode_Check (arg )) {
246- CTypeDescrObject * result ;
247- arg = PyUnicode_AsASCIIString (arg );
248- if (arg == NULL )
249- return NULL ;
250- result = _ffi_type (ffi , arg , accept );
251- Py_DECREF (arg );
252- return result ;
253- }
254- #endif
255244 else {
256245 const char * m1 = (accept & ACCEPT_STRING ) ? "string" : "" ;
257246 const char * m2 = (accept & ACCEPT_CTYPE ) ? "ctype object" : "" ;
@@ -291,7 +280,7 @@ static PyObject *ffi_sizeof(FFIObject *self, PyObject *arg)
291280 return NULL ;
292281 }
293282 }
294- return PyInt_FromSsize_t (size );
283+ return PyLong_FromSsize_t (size );
295284}
296285
297286PyDoc_STRVAR (ffi_alignof_doc ,
@@ -308,7 +297,7 @@ static PyObject *ffi_alignof(FFIObject *self, PyObject *arg)
308297 align = get_alignment (ct );
309298 if (align < 0 )
310299 return NULL ;
311- return PyInt_FromLong (align );
300+ return PyLong_FromLong (align );
312301}
313302
314303PyDoc_STRVAR (ffi_typeof_doc ,
@@ -526,7 +515,7 @@ static PyObject *ffi_offsetof(FFIObject *self, PyObject *args)
526515 return NULL ;
527516 offset += ofs1 ;
528517 }
529- return PyInt_FromSsize_t (offset );
518+ return PyLong_FromSsize_t (offset );
530519}
531520
532521PyDoc_STRVAR (ffi_addressof_doc ,
@@ -639,9 +628,7 @@ static PyObject *ffi_getctype(FFIObject *self, PyObject *args, PyObject *kwds)
639628 CTypeDescrObject * ct ;
640629 size_t replace_with_len ;
641630 static char * keywords [] = {"cdecl" , "replace_with" , NULL };
642- #if PY_MAJOR_VERSION >= 3
643631 PyObject * u ;
644- #endif
645632
646633 if (!PyArg_ParseTupleAndKeywords (args , kwds , "O|s:getctype" , keywords ,
647634 & c_decl , & replace_with ))
@@ -675,14 +662,12 @@ static PyObject *ffi_getctype(FFIObject *self, PyObject *args, PyObject *kwds)
675662 if (add_paren )
676663 p [replace_with_len ] = ')' ;
677664
678- #if PY_MAJOR_VERSION >= 3
679665 /* bytes -> unicode string */
680666 u = PyUnicode_DecodeLatin1 (PyBytes_AS_STRING (res ),
681667 PyBytes_GET_SIZE (res ),
682668 NULL );
683669 Py_DECREF (res );
684670 res = u ;
685- #endif
686671
687672 return res ;
688673}
@@ -931,7 +916,7 @@ static PyObject *ffi_list_types(FFIObject *self, PyObject *noargs)
931916 goto error ;
932917
933918 for (i = 0 ; i < n1 ; i ++ ) {
934- o = PyText_FromString (self -> types_builder .ctx .typenames [i ].name );
919+ o = PyUnicode_FromString (self -> types_builder .ctx .typenames [i ].name );
935920 if (o == NULL )
936921 goto error ;
937922 PyList_SET_ITEM (lst [0 ], i , o );
@@ -945,7 +930,7 @@ static PyObject *ffi_list_types(FFIObject *self, PyObject *noargs)
945930 if (s -> name [0 ] == '$' )
946931 continue ;
947932
948- o = PyText_FromString (s -> name );
933+ o = PyUnicode_FromString (s -> name );
949934 if (o == NULL )
950935 goto error ;
951936 index = (s -> flags & _CFFI_F_UNION ) ? 2 : 1 ;
@@ -990,22 +975,13 @@ PyDoc_STRVAR(ffi_init_once_doc,
990975"of function() is done. If function() raises an exception, it is\n"
991976"propagated and nothing is cached." );
992977
993- #if PY_MAJOR_VERSION < 3
994- /* PyCapsule_New is redefined to be PyCObject_FromVoidPtr in _cffi_backend,
995- which gives 2.6 compatibility; but the destructor signature is different */
996- static void _free_init_once_lock (void * lock )
997- {
998- PyThread_free_lock ((PyThread_type_lock )lock );
999- }
1000- #else
1001978static void _free_init_once_lock (PyObject * capsule )
1002979{
1003980 PyThread_type_lock lock ;
1004981 lock = PyCapsule_GetPointer (capsule , "cffi_init_once_lock" );
1005982 if (lock != NULL )
1006983 PyThread_free_lock (lock );
1007984}
1008- #endif
1009985
1010986static PyObject * ffi_init_once (FFIObject * self , PyObject * args , PyObject * kwds )
1011987{
0 commit comments