diff --git a/cffibuilder/api.py b/cffibuilder/api.py index edb977a..065ebfa 100644 --- a/cffibuilder/api.py +++ b/cffibuilder/api.py @@ -2,6 +2,10 @@ from .lock import allocate_lock from .error import CDefError from .typeresolver import TypeResolver +import sys + +if sys.version_info > (3,): + basestring = str class FFI(object): diff --git a/cffibuilder/builder.py b/cffibuilder/builder.py index 5a7232f..b3828e3 100644 --- a/cffibuilder/builder.py +++ b/cffibuilder/builder.py @@ -387,28 +387,32 @@ def setter(library, value): type(library)._cffi_dir.append(name) -class FFILibrary(object): - __metaclass__ = FFILibraryMeta - - def __init__(self): - # Build FFILibrary instance and call _cffi_setup(). - # this will set up some fields like '_cffi_types', and only then - # it will invoke the chained list of functions that will really - # build (notably) the constant objects, as if they are - # pointers, and store them as attributes on the 'library' object. - super(FFILibrary, self).__init__() - if _libmodule._cffi_setup(FFILibrary._ctypes_ordered, - ffiplatform.VerificationError, - self): - import warnings - warnings.warn("reimporting %r might overwrite older definitions" - % (_libmodule.__name__)) - # finally, call the loaded_cpy_xxx() functions. This will perform - # the final adjustments, like copying the Python->C wrapper - # functions from the module to the 'library' object, and setting - # up the FFILibrary class with properties for the global C variables. - with ffi._lock: - FFILibrary._load('loaded', library=self) +def ffi_library_init(self): + # Build FFILibrary instance and call _cffi_setup(). + # this will set up some fields like '_cffi_types', and only then + # it will invoke the chained list of functions that will really + # build (notably) the constant objects, as if they are + # pointers, and store them as attributes on the 'library' object. + super(FFILibrary, self).__init__() + if _libmodule._cffi_setup(FFILibrary._ctypes_ordered, + ffiplatform.VerificationError, + self): + import warnings + warnings.warn("reimporting %r might overwrite older definitions" + % (_libmodule.__name__)) + # finally, call the loaded_cpy_xxx() functions. This will perform + # the final adjustments, like copying the Python->C wrapper + # functions from the module to the 'library' object, and setting + # up the FFILibrary class with properties for the global C variables. + with ffi._lock: + FFILibrary._load('loaded', library=self) + + +FFILibrary = FFILibraryMeta( + str('FFILibrary'), + (), + {'__init__': ffi_library_init} +) lib = FFILibrary()