Skip to content

Commit 7643845

Browse files
committed
Properly support extern global variable
1 parent 4401055 commit 7643845

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

ctypeslib/codegen/codegenerator.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,25 @@ def Variable(self, tp):
337337
self.print_comment(tp)
338338

339339
# 2021-02 give me a test case for this. it breaks all extern variables otherwise.
340-
if tp.extern and self.find_library_with_func(tp):
340+
# if tp.extern and self.find_library_with_func(tp):
341+
if tp.extern:
341342
dll_library = self.find_library_with_func(tp)
343+
if not dll_library:
344+
class LibraryStub:
345+
_filepath = "FIXME_STUB"
346+
_name = "FIXME_STUB"
347+
dll_library = LibraryStub()
348+
342349
self._generate(tp.typ)
343350
# calling convention does not matter for in_dll...
344351
libname = self.get_sharedlib(dll_library, "cdecl")
345-
print("%s = (%s).in_dll(%s, '%s')" % (tp.name, self.type_name(tp.typ), libname, tp.name), file=self.stream)
352+
#print("%s = (%s).in_dll(%s, '%s')" % (tp.name, self.type_name(tp.typ), libname, tp.name), file=self.stream)
353+
decl = "{tp} = ({type_name}).in_dll({libname}, '{tp}') if getattr({libname}, '{tp}', None) else None".format(
354+
tp=tp.name,
355+
type_name=self.type_name(tp.typ),
356+
libname=libname,
357+
)
358+
print(decl, file=self.stream)
346359
self.names.append(tp.name)
347360
# wtypes.h contains IID_IProcessInitControl, for example
348361
return

0 commit comments

Comments
 (0)