[Python-checkins] bpo-36623: Clean parser headers and include files (GH-12253)

Pablo Galindo webhook-mailer at python.org
Sat Apr 13 12:05:20 EDT 2019


https://github.com/python/cpython/commit/f2cf1e3e2892a6326949c2570f1bb6d6c95715fb
commit: f2cf1e3e2892a6326949c2570f1bb6d6c95715fb
branch: master
author: Pablo Galindo <Pablogsal at gmail.com>
committer: GitHub <noreply at github.com>
date: 2019-04-13T17:05:14+01:00
summary:

bpo-36623: Clean parser headers and include files (GH-12253)

After the removal of pgen, multiple header and function prototypes that lack implementation or are unused are still lying around.

files:
A Misc/NEWS.d/next/Core and Builtins/2019-04-13-02-08-44.bpo-36623.HR_xhB.rst
D Include/pgenheaders.h
M Doc/whatsnew/3.8.rst
M Include/bitset.h
M Include/grammar.h
M Makefile.pre.in
M PCbuild/pythoncore.vcxproj
M PCbuild/pythoncore.vcxproj.filters
M Parser/acceler.c
M Parser/grammar1.c
M Parser/listnode.c
M Parser/parser.c
M Parser/parser.h
M Parser/parsetok.c
M Parser/pgen/grammar.py
M Parser/tokenizer.c
M Parser/tokenizer.h
M Python/graminit.c
M Python/strdup.c

diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst
index bf28e5ff4b06..39a0da5e61e9 100644
--- a/Doc/whatsnew/3.8.rst
+++ b/Doc/whatsnew/3.8.rst
@@ -814,6 +814,10 @@ Changes in the Python API
   by the installer).
   (See :issue:`36085`.)
 
+* The header files and functions related to pgen have been removed after its
+  replacement by a pure Python implementation. (Contributed by Pablo Galindo
+  in :issue:`36623`.)
+
 
 Changes in the C API
 --------------------
diff --git a/Include/bitset.h b/Include/bitset.h
index b22fa77815cf..6a2ac9787eab 100644
--- a/Include/bitset.h
+++ b/Include/bitset.h
@@ -8,23 +8,14 @@ extern "C" {
 /* Bitset interface */
 
 #define BYTE            char
-
 typedef BYTE *bitset;
 
-bitset newbitset(int nbits);
-void delbitset(bitset bs);
 #define testbit(ss, ibit) (((ss)[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0)
-int addbit(bitset bs, int ibit); /* Returns 0 if already set */
-int samebitset(bitset bs1, bitset bs2, int nbits);
-void mergebitset(bitset bs1, bitset bs2, int nbits);
 
 #define BITSPERBYTE     (8*sizeof(BYTE))
-#define NBYTES(nbits)   (((nbits) + BITSPERBYTE - 1) / BITSPERBYTE)
-
 #define BIT2BYTE(ibit)  ((ibit) / BITSPERBYTE)
 #define BIT2SHIFT(ibit) ((ibit) % BITSPERBYTE)
 #define BIT2MASK(ibit)  (1 << BIT2SHIFT(ibit))
-#define BYTE2BIT(ibyte) ((ibyte) * BITSPERBYTE)
 
 #ifdef __cplusplus
 }
diff --git a/Include/grammar.h b/Include/grammar.h
index 68b928c97189..7a6182bb76d5 100644
--- a/Include/grammar.h
+++ b/Include/grammar.h
@@ -66,27 +66,11 @@ typedef struct {
 } grammar;
 
 /* FUNCTIONS */
-
-grammar *newgrammar(int start);
-void freegrammar(grammar *g);
-dfa *adddfa(grammar *g, int type, const char *name);
-int addstate(dfa *d);
-void addarc(dfa *d, int from, int to, int lbl);
 dfa *PyGrammar_FindDFA(grammar *g, int type);
-
-int addlabel(labellist *ll, int type, const char *str);
-int findlabel(labellist *ll, int type, const char *str);
 const char *PyGrammar_LabelRepr(label *lb);
-void translatelabels(grammar *g);
-
-void addfirstsets(grammar *g);
-
 void PyGrammar_AddAccelerators(grammar *g);
 void PyGrammar_RemoveAccelerators(grammar *);
 
-void printgrammar(grammar *g, FILE *fp);
-void printnonterminals(grammar *g, FILE *fp);
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/Include/pgenheaders.h b/Include/pgenheaders.h
deleted file mode 100644
index dbc5e0a5f139..000000000000
--- a/Include/pgenheaders.h
+++ /dev/null
@@ -1,43 +0,0 @@
-#ifndef Py_PGENHEADERS_H
-#define Py_PGENHEADERS_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* Include files and extern declarations used by most of the parser. */
-
-#include "Python.h"
-
-PyAPI_FUNC(void) PySys_WriteStdout(const char *format, ...)
-                        Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
-PyAPI_FUNC(void) PySys_WriteStderr(const char *format, ...)
-                        Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
-
-#define addarc _Py_addarc
-#define addbit _Py_addbit
-#define adddfa _Py_adddfa
-#define addfirstsets _Py_addfirstsets
-#define addlabel _Py_addlabel
-#define addstate _Py_addstate
-#define delbitset _Py_delbitset
-#define dumptree _Py_dumptree
-#define findlabel _Py_findlabel
-#define freegrammar _Py_freegrammar
-#define mergebitset _Py_mergebitset
-#define meta_grammar _Py_meta_grammar
-#define newbitset _Py_newbitset
-#define newgrammar _Py_newgrammar
-#define pgen _Py_pgen
-#define printgrammar _Py_printgrammar
-#define printnonterminals _Py_printnonterminals
-#define printtree _Py_printtree
-#define samebitset _Py_samebitset
-#define showtree _Py_showtree
-#define tok_dump _Py_tok_dump
-#define translatelabels _Py_translatelabels
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* !Py_PGENHEADERS_H */
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 1cb8a590d45b..05c195767a8b 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1008,7 +1008,6 @@ PYTHON_HEADERS= \
 		$(srcdir)/Include/osdefs.h \
 		$(srcdir)/Include/osmodule.h \
 		$(srcdir)/Include/patchlevel.h \
-		$(srcdir)/Include/pgenheaders.h \
 		$(srcdir)/Include/pyarena.h \
 		$(srcdir)/Include/pycapsule.h \
 		$(srcdir)/Include/pyctype.h \
diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-04-13-02-08-44.bpo-36623.HR_xhB.rst b/Misc/NEWS.d/next/Core and Builtins/2019-04-13-02-08-44.bpo-36623.HR_xhB.rst
new file mode 100644
index 000000000000..cc90973e2964
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2019-04-13-02-08-44.bpo-36623.HR_xhB.rst	
@@ -0,0 +1,2 @@
+Remove parser headers and related function declarations that lack
+implementations after the removal of pgen.
diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
index c9ff2f88d8e0..a980799461a3 100644
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -175,7 +175,6 @@
     <ClInclude Include="..\Include\osmodule.h" />
     <ClInclude Include="..\Include\parsetok.h" />
     <ClInclude Include="..\Include\patchlevel.h" />
-    <ClInclude Include="..\Include\pgenheaders.h" />
     <ClInclude Include="..\Include\pyhash.h" />
     <ClInclude Include="..\Include\py_curses.h" />
     <ClInclude Include="..\Include\pyarena.h" />
diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters
index 5dfa193f048a..f92433e3e0c9 100644
--- a/PCbuild/pythoncore.vcxproj.filters
+++ b/PCbuild/pythoncore.vcxproj.filters
@@ -267,9 +267,6 @@
     <ClInclude Include="..\Include\patchlevel.h">
       <Filter>Include</Filter>
     </ClInclude>
-    <ClInclude Include="..\Include\pgenheaders.h">
-      <Filter>Include</Filter>
-    </ClInclude>
     <ClInclude Include="..\Include\py_curses.h">
       <Filter>Include</Filter>
     </ClInclude>
diff --git a/Parser/acceler.c b/Parser/acceler.c
index 9b14263b461a..3a230c19bb9f 100644
--- a/Parser/acceler.c
+++ b/Parser/acceler.c
@@ -10,7 +10,7 @@
    are not part of the static data structure written on graminit.[ch]
    by the parser generator. */
 
-#include "pgenheaders.h"
+#include "Python.h"
 #include "grammar.h"
 #include "node.h"
 #include "token.h"
diff --git a/Parser/grammar1.c b/Parser/grammar1.c
index 9c323911ab26..fec6d9ec0ee2 100644
--- a/Parser/grammar1.c
+++ b/Parser/grammar1.c
@@ -2,7 +2,6 @@
 /* Grammar subroutines needed by parser */
 
 #include "Python.h"
-#include "pgenheaders.h"
 #include "grammar.h"
 #include "token.h"
 
diff --git a/Parser/listnode.c b/Parser/listnode.c
index 71300ae908ae..8f1a1163b63d 100644
--- a/Parser/listnode.c
+++ b/Parser/listnode.c
@@ -1,7 +1,7 @@
 
 /* List a node on a file */
 
-#include "pgenheaders.h"
+#include "Python.h"
 #include "token.h"
 #include "node.h"
 
diff --git a/Parser/parser.c b/Parser/parser.c
index fa4a8f011ff5..c21b6fdf466d 100644
--- a/Parser/parser.c
+++ b/Parser/parser.c
@@ -6,7 +6,6 @@
 /* XXX To do: error recovery */
 
 #include "Python.h"
-#include "pgenheaders.h"
 #include "token.h"
 #include "grammar.h"
 #include "node.h"
diff --git a/Parser/parser.h b/Parser/parser.h
index aee1c86cb044..ebb06c2b1976 100644
--- a/Parser/parser.h
+++ b/Parser/parser.h
@@ -38,6 +38,11 @@ int PyParser_AddToken(parser_state *ps, int type, char *str,
                       int *expected_ret);
 void PyGrammar_AddAccelerators(grammar *g);
 
+
+#define showtree _Py_showtree
+#define printtree _Py_printtree
+#define dumptree _Py_dumptree
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/Parser/parsetok.c b/Parser/parsetok.c
index ba33a9a0586f..31be0ebbde2d 100644
--- a/Parser/parsetok.c
+++ b/Parser/parsetok.c
@@ -1,7 +1,7 @@
 
 /* Parser-tokenizer link implementation */
 
-#include "pgenheaders.h"
+#include "Python.h"
 #include "tokenizer.h"
 #include "node.h"
 #include "grammar.h"
diff --git a/Parser/pgen/grammar.py b/Parser/pgen/grammar.py
index 340bf64f6d23..1ab9434fa887 100644
--- a/Parser/pgen/grammar.py
+++ b/Parser/pgen/grammar.py
@@ -61,7 +61,6 @@ def produce_graminit_h(self, writer):
     def produce_graminit_c(self, writer):
         writer("/* Generated by Parser/pgen */\n\n")
 
-        writer('#include "pgenheaders.h"\n')
         writer('#include "grammar.h"\n')
         writer("grammar _PyParser_Grammar;\n")
 
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index 58dd1cd30b37..e8068f268074 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -2,7 +2,6 @@
 /* Tokenizer implementation */
 
 #include "Python.h"
-#include "pgenheaders.h"
 
 #include <ctype.h>
 #include <assert.h>
diff --git a/Parser/tokenizer.h b/Parser/tokenizer.h
index 06c7a14b70b0..92669bfd8a16 100644
--- a/Parser/tokenizer.h
+++ b/Parser/tokenizer.h
@@ -80,6 +80,8 @@ extern struct tok_state *PyTokenizer_FromFile(FILE *, const char*,
 extern void PyTokenizer_Free(struct tok_state *);
 extern int PyTokenizer_Get(struct tok_state *, char **, char **);
 
+#define tok_dump _Py_tok_dump
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/Python/graminit.c b/Python/graminit.c
index 441502e90876..cd9003241700 100644
--- a/Python/graminit.c
+++ b/Python/graminit.c
@@ -1,6 +1,5 @@
 /* Generated by Parser/pgen */
 
-#include "pgenheaders.h"
 #include "grammar.h"
 grammar _PyParser_Grammar;
 static arc arcs_0_0[3] = {
diff --git a/Python/strdup.c b/Python/strdup.c
index 99dc77417bd6..6ce171b21fe6 100644
--- a/Python/strdup.c
+++ b/Python/strdup.c
@@ -1,7 +1,5 @@
 /* strdup() replacement (from stdwin, if you must know) */
 
-#include "pgenheaders.h"
-
 char *
 strdup(const char *str)
 {



More information about the Python-checkins mailing list