From 3b5656487a5116d24bbed98617eadff0f540e239 Mon Sep 17 00:00:00 2001 From: mara004 Date: Sun, 17 Dec 2023 20:45:00 +0100 Subject: [PATCH] Fix function macros with empty params list (#189) 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. --- ctypesgen/printer_python/printer.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ctypesgen/printer_python/printer.py b/ctypesgen/printer_python/printer.py index bdfca279..1f1cec43 100755 --- a/ctypesgen/printer_python/printer.py +++ b/ctypesgen/printer_python/printer.py @@ -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.