Skip to content

Commit

Permalink
Fix function macros with empty params list (ctypesgen#189)
Browse files Browse the repository at this point in the history
This fixes a bug in compiling function macros without params that was
present in ctypesgen since at least 2010 according to git blame.

Prior to this fix, e.g. Py_UNREACHABLE from pymacro.h would translate to
Py_UNREACHABLE = Py_FatalError("Unreachable C code path reached")
which would promptly raise an exception on import time.
  • Loading branch information
mara004 authored Dec 17, 2023
1 parent 17b7a25 commit 3b56564
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ctypesgen/printer_python/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,12 @@ def print_variable(self, variable):
)

def print_macro(self, macro):
if macro.params:
self.print_func_macro(macro)
else:
# important: must check precisely against None because params may be
# an empty list for a func macro
if macro.params is None:
self.print_simple_macro(macro)
else:
self.print_func_macro(macro)

def print_simple_macro(self, macro):
# The macro translator makes heroic efforts but it occasionally fails.
Expand Down

0 comments on commit 3b56564

Please sign in to comment.