From 294ccdf9b0a0c38150553f9ea044793ecf156e8b Mon Sep 17 00:00:00 2001 From: Charalampos Stratakis Date: Thu, 15 Jan 2026 01:56:18 +0100 Subject: [PATCH] Add compatibility with ply post-3.11 version --- pycparser-ply-post-3.11-compat.patch | 92 ++++++++++++++++++++++++++++ python-pycparser.spec | 7 +++ 2 files changed, 99 insertions(+) create mode 100644 pycparser-ply-post-3.11-compat.patch diff --git a/pycparser-ply-post-3.11-compat.patch b/pycparser-ply-post-3.11-compat.patch new file mode 100644 index 0000000..2c1cf2b --- /dev/null +++ b/pycparser-ply-post-3.11-compat.patch @@ -0,0 +1,92 @@ +From 823653a55b9c426813c85f075bcd28d412ba4d36 Mon Sep 17 00:00:00 2001 +From: Charalampos Stratakis +Date: Tue, 13 Jan 2026 19:08:07 +0100 +Subject: [PATCH] Add compatibility with ply post-3.11 version + +ply removed table caching parameters (optimize, lextab, tabmodule, +outputdir, nowarn) in its post-3.11 refactoring. Detect supported +parameters at runtime and omit unsupported ones. + +Also suppress parser generation warnings in the new ply path +since the tables are now generated at runtime instead of loaded +from cache. + +This change fixes the compatibility issues for distros that might +unbundle ply and have it updated past its last 3.11 release. +--- + pycparser/_build_tables.py | 8 ++++++-- + pycparser/c_lexer.py | 6 ++++++ + pycparser/c_parser.py | 23 ++++++++++++++++------- + 3 files changed, 28 insertions(+), 9 deletions(-) + +diff --git a/pycparser/_build_tables.py b/pycparser/_build_tables.py +index 4f37107..4d07812 100644 +--- a/pycparser/_build_tables.py ++++ b/pycparser/_build_tables.py +@@ -35,6 +35,10 @@ c_parser.CParser( + # + importlib.invalidate_caches() + +-import lextab +-import yacctab ++try: ++ import lextab ++ import yacctab ++except ImportError: ++ # ply post-3.11 doesn't generate table modules ++ pass + import c_ast +diff --git a/pycparser/c_lexer.py b/pycparser/c_lexer.py +index 135826d..3b96d3f 100644 +--- a/pycparser/c_lexer.py ++++ b/pycparser/c_lexer.py +@@ -62,6 +62,12 @@ class CLexer(object): + manual warns against calling lex.lex inside + __init__ + """ ++ # ply removed optimize/lextab/nowarn/outputdir after 3.11 ++ if 'lextab' not in lex.lex.__code__.co_varnames: ++ kwargs.pop('optimize', None) ++ kwargs.pop('lextab', None) ++ kwargs.pop('nowarn', None) ++ kwargs.pop('outputdir', None) + self.lexer = lex.lex(object=self, **kwargs) + + def reset_lineno(self): +diff --git a/pycparser/c_parser.py b/pycparser/c_parser.py +index bb123ac..43c244e 100644 +--- a/pycparser/c_parser.py ++++ b/pycparser/c_parser.py +@@ -106,13 +106,22 @@ class CParser(PLYParser): + for rule in rules_with_opt: + self._create_opt_rule(rule) + +- self.cparser = yacc.yacc( +- module=self, +- start='translation_unit_or_empty', +- debug=yacc_debug, +- optimize=yacc_optimize, +- tabmodule=yacctab, +- outputdir=taboutputdir) ++ # ply removed tabmodule/outputdir after 3.11 ++ if 'tabmodule' in yacc.yacc.__code__.co_varnames: ++ self.cparser = yacc.yacc( ++ module=self, ++ start='translation_unit_or_empty', ++ debug=yacc_debug, ++ optimize=yacc_optimize, ++ tabmodule=yacctab, ++ outputdir=taboutputdir) ++ else: ++ self.cparser = yacc.yacc( ++ module=self, ++ start='translation_unit_or_empty', ++ debug=yacc_debug, ++ optimize=yacc_optimize, ++ errorlog=yacc.NullLogger()) + + # Stack of scopes for keeping track of symbols. _scope_stack[-1] is + # the current (topmost) scope. Each scope is a dictionary that +-- +2.52.0 + diff --git a/python-pycparser.spec b/python-pycparser.spec index aa370d5..04e6c73 100644 --- a/python-pycparser.spec +++ b/python-pycparser.spec @@ -16,6 +16,13 @@ Source1: pycparser-0.91.1-remove-relative-sys-path.py # package to prevent "yacc table file version is out of date" problem. Patch100: pycparser-unbundle-ply.patch +# This is Fedora-specific. ply has been archived upstream and pycparser +# bundles a specific working version of it, but in Fedora we debundle it, +# so this patch makes it compatible with the ply post 3.11 version commits. +# Upstream prefers the downstream approach, see: +# https://github.com/eliben/pycparser/issues/588 +Patch200: pycparser-ply-post-3.11-compat.patch + BuildArch: noarch BuildRequires: python3-devel