From d8b1cca8d05b4e0a1c7aa26efba2fac19ad9bf73 Mon Sep 17 00:00:00 2001 From: mara004 Date: Tue, 5 Dec 2023 01:14:14 +0100 Subject: [PATCH 1/2] Fix function macros with empty params list 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 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ctypesgen/printer_python/printer.py b/ctypesgen/printer_python/printer.py index bdfca279..f6bab9c3 100755 --- a/ctypesgen/printer_python/printer.py +++ b/ctypesgen/printer_python/printer.py @@ -418,10 +418,11 @@ 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. From 13edf0bcad5d2044928cbc420f8d24aee3548b40 Mon Sep 17 00:00:00 2001 From: Nicklas Larsson Date: Sun, 17 Dec 2023 20:40:40 +0100 Subject: [PATCH 2/2] fix line length --- ctypesgen/printer_python/printer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ctypesgen/printer_python/printer.py b/ctypesgen/printer_python/printer.py index f6bab9c3..1f1cec43 100755 --- a/ctypesgen/printer_python/printer.py +++ b/ctypesgen/printer_python/printer.py @@ -418,7 +418,8 @@ def print_variable(self, variable): ) def print_macro(self, macro): - # important: must check precisely against None because params may be an empty list for a func macro + # 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: