Skip to content

Commit d9e444d

Browse files
authored
gh-106560: Fix redundant declarations in Python/frozen.c (#112612)
Avoid duplicated declarations of "extern" functions in Python/frozen.c. Compiler warnings seen by building Python with gcc -Wredundant-decls.
1 parent 1f2a676 commit d9e444d

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

Python/frozen.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,15 @@ extern PyObject *_Py_get__sitebuiltins_toplevel(void);
8080
extern PyObject *_Py_get_genericpath_toplevel(void);
8181
extern PyObject *_Py_get_ntpath_toplevel(void);
8282
extern PyObject *_Py_get_posixpath_toplevel(void);
83-
extern PyObject *_Py_get_posixpath_toplevel(void);
8483
extern PyObject *_Py_get_os_toplevel(void);
8584
extern PyObject *_Py_get_site_toplevel(void);
8685
extern PyObject *_Py_get_stat_toplevel(void);
8786
extern PyObject *_Py_get_importlib_util_toplevel(void);
8887
extern PyObject *_Py_get_importlib_machinery_toplevel(void);
8988
extern PyObject *_Py_get_runpy_toplevel(void);
9089
extern PyObject *_Py_get___hello___toplevel(void);
91-
extern PyObject *_Py_get___hello___toplevel(void);
92-
extern PyObject *_Py_get___hello___toplevel(void);
93-
extern PyObject *_Py_get___hello___toplevel(void);
94-
extern PyObject *_Py_get___phello___toplevel(void);
9590
extern PyObject *_Py_get___phello___toplevel(void);
9691
extern PyObject *_Py_get___phello___ham_toplevel(void);
97-
extern PyObject *_Py_get___phello___ham_toplevel(void);
9892
extern PyObject *_Py_get___phello___ham_eggs_toplevel(void);
9993
extern PyObject *_Py_get___phello___spam_toplevel(void);
10094
extern PyObject *_Py_get_frozen_only_toplevel(void);

Tools/build/freeze_modules.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,17 @@ def replace_block(lines, start_marker, end_marker, replacements, file):
468468
return lines[:start_pos + 1] + replacements + lines[end_pos:]
469469

470470

471+
class UniqueList(list):
472+
def __init__(self):
473+
self._seen = set()
474+
475+
def append(self, item):
476+
if item in self._seen:
477+
return
478+
super().append(item)
479+
self._seen.add(item)
480+
481+
471482
def regen_frozen(modules):
472483
headerlines = []
473484
parentdir = os.path.dirname(FROZEN_FILE)
@@ -477,7 +488,7 @@ def regen_frozen(modules):
477488
header = relpath_for_posix_display(src.frozenfile, parentdir)
478489
headerlines.append(f'#include "{header}"')
479490

480-
externlines = []
491+
externlines = UniqueList()
481492
bootstraplines = []
482493
stdliblines = []
483494
testlines = []

0 commit comments

Comments
 (0)