Index: ctypesgencore/processor/operations.py =================================================================== --- ctypesgencore/processor/operations.py (revision 47) +++ ctypesgencore/processor/operations.py (working copy) @@ -27,6 +27,7 @@ data.typedefs.append(typedef) data.all.insert(data.all.index(struct)+1,typedef) + data.output_order.append(("typedef", typedef)) def remove_descriptions_in_system_headers(data,opts): """remove_descriptions_in_system_headers() removes descriptions if they came Index: ctypesgencore/libraryloader.py =================================================================== --- ctypesgencore/libraryloader.py (revision 47) +++ ctypesgencore/libraryloader.py (working copy) @@ -79,6 +79,9 @@ for path in self.getplatformpaths(libname): yield path + + def getplatformpaths(self, libname): + return [] # Darwin (Mac OS X) @@ -145,7 +148,7 @@ # # We assume the DT_RPATH and DT_RUNPATH binary sections are omitted. - directories = self.other_paths.copy() + directories = self.other_dirs[:] directories.append(".") directories.extend(_environ_path('LD_LIBRARY_PATH')) @@ -217,17 +220,21 @@ # Platform switching +# If your value of sys.platform does not appear in this dict, please contact +# the Ctypesgen maintainers. + loaderclass = { "darwin": DarwinLibraryLoader, "cygwin": WindowsLibraryLoader, - "linux": LinuxLibraryLoader, + "linux2": LinuxLibraryLoader, "win32": WindowsLibraryLoader } -loader = loaderclass[sys.platform]() +loader = loaderclass.get(sys.platform, LibraryLoader)() + def add_library_search_dirs(other_dirs): loader.other_dirs = other_dirs load_library = loader.load_library -del loaderclass \ No newline at end of file +del loaderclass Index: ctypesgencore/expressions.py =================================================================== --- ctypesgencore/expressions.py (revision 47) +++ ctypesgencore/expressions.py (working copy) @@ -260,12 +260,15 @@ return '((%s (%s)).value)' % (function,", ".join(arguments)) # There seems not to be any reasonable way to translate C typecasts -# into Python. Ctypesgen doesn't try. +# into Python. Ctypesgen doesn't try, except for the special case of NULL. class TypeCastExpressionNode(ExpressionNode): def __init__(self, base, ctype): ExpressionNode.__init__(self) self.base = base self.ctype = ctype + self.isnull = isinstance(ctype, CtypesPointer) and \ + isinstance(base, ConstantExpressionNode) and \ + base.value == 0 def visit(self,visitor): # No need to visit ctype because it isn't actually used @@ -273,10 +276,16 @@ ExpressionNode.visit(self,visitor) def evaluate(self,context): - return self.base.evaluate(context) + if self.isnull: + return None + else: + return self.base.evaluate(context) def py_string(self, can_be_ctype): - return self.base.py_string(can_be_ctype) + if self.isnull: + return "None" + else: + return self.base.py_string(can_be_ctype) class UnsupportedExpressionNode(ExpressionNode): def __init__(self,message): Index: ctypesgencore/parser/datacollectingparser.py =================================================================== --- ctypesgencore/parser/datacollectingparser.py (revision 47) +++ ctypesgencore/parser/datacollectingparser.py (working copy) @@ -42,6 +42,7 @@ nullmacro = ConstantDescription("NULL",null,("",1)) self.constants.append(nullmacro) self.all.append(nullmacro) + self.output_order.append(("constant", nullmacro)) # A list of tuples describing macros; saved to be processed after # everything else has been parsed