python-pycparser/pycparser-ply-post-3.11-compat.patch
2026-01-15 01:56:18 +01:00

92 lines
3.2 KiB
Diff

From 823653a55b9c426813c85f075bcd28d412ba4d36 Mon Sep 17 00:00:00 2001
From: Charalampos Stratakis <cstratak@redhat.com>
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