Index: Python/graminit.c =================================================================== --- Python/graminit.c (revision 67176) +++ Python/graminit.c (working copy) @@ -2064,3 +2064,9 @@ {167, labels}, 256 }; + +grammar * +get_PyParserGrammar(void) +{ + return(&_PyParser_Grammar); +} Index: Python/pythonrun.c =================================================================== --- Python/pythonrun.c (revision 67176) +++ Python/pythonrun.c (working copy) @@ -48,8 +48,6 @@ extern wchar_t *Py_GetPath(void); -extern grammar _PyParser_Grammar; /* From graminit.c */ - /* Forward */ static void initmain(void); static void initsite(void); @@ -497,7 +495,7 @@ - whatever various modules and libraries allocate */ - PyGrammar_RemoveAccelerators(&_PyParser_Grammar); + PyGrammar_RemoveAccelerators(get_PyParserGrammar()); #ifdef Py_TRACE_REFS /* Display addresses (& refcnts) of all objects still alive. @@ -1693,7 +1691,7 @@ int iflags = PARSER_FLAGS(flags); node *n = PyParser_ParseStringFlagsFilenameEx(s, filename, - &_PyParser_Grammar, start, &err, + get_PyParserGrammar(), start, &err, &iflags); if (flags == NULL) { localflags.cf_flags = 0; @@ -1723,7 +1721,7 @@ int iflags = PARSER_FLAGS(flags); node *n = PyParser_ParseFileFlagsEx(fp, filename, enc, - &_PyParser_Grammar, + get_PyParserGrammar(), start, ps1, ps2, &err, &iflags); if (flags == NULL) { localflags.cf_flags = 0; @@ -1750,7 +1748,7 @@ { perrdetail err; node *n = PyParser_ParseFileFlags(fp, filename, NULL, - &_PyParser_Grammar, + get_PyParserGrammar(), start, NULL, NULL, &err, flags); if (n == NULL) err_input(&err); @@ -1764,7 +1762,7 @@ PyParser_SimpleParseStringFlags(const char *str, int start, int flags) { perrdetail err; - node *n = PyParser_ParseStringFlags(str, &_PyParser_Grammar, + node *n = PyParser_ParseStringFlags(str, get_PyParserGrammar(), start, &err, flags); if (n == NULL) err_input(&err); @@ -1777,7 +1775,8 @@ { perrdetail err; node *n = PyParser_ParseStringFlagsFilename(str, filename, - &_PyParser_Grammar, start, &err, flags); + get_PyParserGrammar(), + start, &err, flags); if (n == NULL) err_input(&err); return n; Index: Include/grammar.h =================================================================== --- Include/grammar.h (revision 67176) +++ Include/grammar.h (working copy) @@ -87,6 +87,15 @@ void printgrammar(grammar *g, FILE *fp); void printnonterminals(grammar *g, FILE *fp); +/* + * This function resides in graminit.c. The header file, graminit.h declares + * only defines etc. So to reduce issues relating to header creep - declare + * it here. + * + * It is an attempt to hide the underlying grammar structure. + */ +grammar *get_PyParserGrammar(void); + #ifdef __cplusplus } #endif Index: setup.py =================================================================== --- setup.py (revision 67176) +++ setup.py (working copy) @@ -493,7 +493,12 @@ exts.append( Extension('select', ['selectmodule.c']) ) # Fred Drake's interface to the Python parser - exts.append( Extension('parser', ['parsermodule.c']) ) + # For Cygwin it is necessary to add in graminit.c to + # find the grammar information + parser_src_list = ['parsermodule.c'] + if platform == 'cygwin': + parser_src_list.append('Python/graminit.c') + exts.append( Extension('parser', parser_src_list) ) # Memory-mapped files (also works on Win32). if platform not in ['atheos', 'mac']: Index: Parser/pgenmain.c =================================================================== --- Parser/pgenmain.c (revision 67176) +++ Parser/pgenmain.c (working copy) @@ -57,6 +57,13 @@ if (Py_DebugFlag) printf("Writing %s ...\n", graminit_c); printgrammar(g, fp); + + fprintf(fp, "\ngrammar *\n"); + fprintf(fp, "get_PyParserGrammar(void)\n"); + fprintf(fp, "{\n"); + fprintf(fp, " return(&_PyParser_Grammar);\n"); + fprintf(fp, "}\n"); + fclose(fp); fp = fopen(graminit_h, "w"); if (fp == NULL) { Index: Modules/parsermodule.c =================================================================== --- Modules/parsermodule.c (revision 67176) +++ Modules/parsermodule.c (working copy) @@ -39,8 +39,6 @@ #include "ast.h" #include "pyarena.h" -extern grammar _PyParser_Grammar; /* From graminit.c */ - #ifdef lint #include #else @@ -527,7 +525,7 @@ if (PyArg_ParseTupleAndKeywords(args, kw, argspec, keywords, &string)) { node* n = PyParser_ParseStringFlagsFilenameEx(string, NULL, - &_PyParser_Grammar, + get_PyParserGrammar(), (type == PyST_EXPR) ? eval_input : file_input, &err, &flags);