Commit graph

684 commits

Author SHA1 Message Date
Victor Stinner 4bb31e90f0 Fix a clang warning in grammar.c
Clang is smarter than GCC and emits a warning for dead code after a function
declared with __attribute__((__noreturn__)) (Py_FatalError).
2016-08-19 15:11:56 +02:00
Berker Peksag 531396c764 Issue #27336: Fix compilation failures --without-threads 2016-06-17 13:25:01 +03:00
Serhiy Storchaka ec39756960 Issue #22570: Renamed Py_SETREF to Py_XSETREF. 2016-04-06 09:50:03 +03:00
Serhiy Storchaka 48842714b9 Issue #22570: Renamed Py_SETREF to Py_XSETREF. 2016-04-06 09:45:48 +03:00
Berker Peksag 2a65ecb780 Issue #26130: Remove redundant variable 's' from Parser/parser.c
Patch by Oren Milman.
2016-03-28 00:45:28 +03:00
Benjamin Peterson 7285d520e0 remove duplicated check for fractions and complex numbers (closes #26076)
Patch by Oren Milman.
2016-03-24 22:43:23 -07:00
Serhiy Storchaka a051bf3afb Issue #26581: Use the first coding cookie on a line, not the last one. 2016-03-20 23:47:48 +02:00
Serhiy Storchaka e431d3c9aa Issue #26581: Use the first coding cookie on a line, not the last one. 2016-03-20 23:36:29 +02:00
Victor Stinner 0611c26a58 On memory error, dump the memory block traceback
Issue #26564: _PyObject_DebugDumpAddress() now dumps the traceback where a
memory block was allocated on memory block. Use the tracemalloc module to get
the traceback.
2016-03-15 22:22:13 +01:00
Victor Stinner 8a1be61849 Add more checks on the GIL
Issue #10915, #15751, #26558:

* PyGILState_Check() now returns 1 (success) before the creation of the GIL and
  after the destruction of the GIL. It allows to use the function early in
  Python initialization and late in Python finalization.
* Add a flag to disable PyGILState_Check(). Disable PyGILState_Check() when
  Py_NewInterpreter() is called
* Add assert(PyGILState_Check()) to: _Py_dup(), _Py_fstat(), _Py_read()
  and _Py_write()
2016-03-14 22:07:55 +01:00
Victor Stinner 25219f596a Issue #26146: remove useless code
obj2ast_constant() code is baesd on obj2ast_object() which has a special case
for Py_None. But in practice, we don't need to have a special case for
constants.

Issue noticed by Joseph Jevnik on a review.
2016-01-27 00:37:59 +01:00
Victor Stinner f2c1aa1661 Add ast.Constant
Issue #26146: Add a new kind of AST node: ast.Constant. It can be used by
external AST optimizers, but the compiler does not emit directly such node.

An optimizer can replace the following AST nodes with ast.Constant:

* ast.NameConstant: None, False, True
* ast.Num: int, float, complex
* ast.Str: str
* ast.Bytes: bytes
* ast.Tuple if items are constants too: tuple
* frozenset

Update code to accept ast.Constant instead of ast.Num and/or ast.Str:

* compiler
* docstrings
* ast.literal_eval()
* Tools/parser/unparse.py
2016-01-26 00:40:57 +01:00
Serhiy Storchaka ef1585eb9a Issue #25923: Added more const qualifiers to signatures of static and private functions. 2015-12-25 20:01:53 +02:00
Serhiy Storchaka 2d06e84455 Issue #25923: Added the const qualifier to static constant arrays. 2015-12-25 19:53:18 +02:00
Serhiy Storchaka f006940351 Issue #20440: Massive replacing unsafe attribute setting code with special
macro Py_SETREF.
2015-12-24 10:39:57 +02:00
Serhiy Storchaka 5a57ade58e Issue #20440: Massive replacing unsafe attribute setting code with special
macro Py_SETREF.
2015-12-24 10:35:59 +02:00
Serhiy Storchaka 0304729ec4 Issue #25388: Fixed tokenizer crash when processing undecodable source code
with a null byte.
2015-11-14 15:12:04 +02:00
Serhiy Storchaka 7e2b870b85 Issue #25388: Fixed tokenizer crash when processing undecodable source code
with a null byte.
2015-11-14 15:11:17 +02:00
Serhiy Storchaka 0d441119f5 Issue #25388: Fixed tokenizer crash when processing undecodable source code
with a null byte.
2015-11-14 15:10:35 +02:00
Victor Stinner f9827ea618 Issue #25555: Fix parser and AST: fill lineno and col_offset of "arg" node when
compiling AST from Python objects.
2015-11-06 17:01:48 +01:00
Victor Stinner c106c68aeb Issue #25555: Fix parser and AST: fill lineno and col_offset of "arg" node when
compiling AST from Python objects.
2015-11-06 17:01:48 +01:00
Benjamin Peterson 860c8a404a merge 3.5 (#25502) 2015-10-28 23:15:22 -07:00
Benjamin Peterson 669ff66c32 remove duplicated imports (closes #25502) 2015-10-28 23:15:13 -07:00
Serhiy Storchaka fc632e3912 Merge with 3.5. 2015-10-06 18:52:52 +03:00
Eric V. Smith 235a6f0984 Issue #24965: Implement PEP 498 "Literal String Interpolation". Documentation is still needed, I'll open an issue for that. 2015-09-19 14:51:32 -04:00
Eric V. Smith 6408dc82fa Fixed indentation. 2015-09-12 18:53:36 -04:00
Serhiy Storchaka 481d3af82e Make asdl_c.py to generate Python-ast.c changed in issue #15989. 2015-09-06 23:29:04 +03:00
Yury Selivanov 96ec934e75 Issue #24619: Simplify async/await tokenization.
This commit simplifies async/await tokenization in tokenizer.c,
tokenize.py & lib2to3/tokenize.py.  Previous solution was to keep
a stack of async-def & def blocks, whereas the new approach is just
to remember position of the outermost async-def block.

This change won't bring any parsing performance improvements, but
it makes the code much easier to read and validate.
2015-07-23 15:01:58 +03:00
Yury Selivanov 8fb307cd65 Issue #24619: New approach for tokenizing async/await.
This commit fixes how one-line async-defs and defs are tracked
by tokenizer.  It allows to correctly parse invalid code such
as:

>>> async def f():
...     def g(): pass
...     async = 10

and valid code such as:

>>> async def f():
...     async def g(): pass
...     await z

As a consequence, is is now possible to have one-line
'async def foo(): await ..' functions:

>>> async def foo(): return await bar()
2015-07-22 13:33:45 +03:00
Yury Selivanov 8085b80c18 Issue 24226: Fix parsing of many sequential one-line 'def' statements. 2015-05-18 12:50:52 -04:00
Yury Selivanov 7544508f02 PEP 0492 -- Coroutines with async and await syntax. Issue #24017. 2015-05-11 22:57:16 -04:00
Benjamin Peterson 025e9ebd0a PEP 448: additional unpacking generalizations (closes #2292)
Patch by Neil Girdhar.
2015-05-05 20:16:41 -04:00
Benjamin Peterson 273a720f87 merge 3.4 (#24022) 2015-04-21 12:07:06 -04:00
Benjamin Peterson d73aca769f do not call into python api if an exception is set (#24022) 2015-04-21 12:05:19 -04:00
Serhiy Storchaka 45ec3288d0 Removed trailing whitespaces in miscalenous files. 2015-04-03 19:42:32 +03:00
Serhiy Storchaka a8cd4d482f Got rid of warnings "suggest braces around empty body in an ‘else’ statement"
in Parser/pgen.c.
2015-04-03 15:24:33 +03:00
Raymond Hettinger df1b699447 Issue #22823: Use set literals instead of creating a set from a list 2014-11-09 15:56:33 -08:00
Serhiy Storchaka 67c719b34b Silenced some warnings about comparison between signed and unsigned integer
expressions.
2014-09-05 10:10:23 +03:00
Guido van Rossum 416b516d46 Fix bootstrapping asdl -- it didn't work with Python 2.7. 2014-07-08 16:22:48 -07:00
Benjamin Peterson 3e439797ba merge 3.4 (#21642) 2014-06-07 12:39:51 -07:00
Benjamin Peterson c416162302 allow the keyword else immediately after (no space) an integer (closes #21642) 2014-06-07 12:36:39 -07:00
Eli Bendersky 5e3d338a74 Issue #19655: Replace the ASDL parser carried with CPython
The new parser does not rely on Spark (which is now removed from our repo),
uses modern 3.x idioms and is significantly smaller and simpler.

It generates exactly the same AST files (.h and .c), so in practice no builds
should be affected.
2014-05-09 17:58:22 -07:00
Benjamin Peterson d51374ed78 PEP 465: a dedicated infix operator for matrix multiplication (closes #21176) 2014-04-09 23:55:56 -04:00
Martin v. Löwis 78f1e4c865 Merge with 3.3 2014-02-28 15:43:36 +01:00
Martin v. Löwis 815b41b1cd Issue #20731: Properly position in source code files even if they
are opened in text mode. Patch by Serhiy Storchaka.
2014-02-28 15:27:29 +01:00
Benjamin Peterson 42ec031fe7 merge 3.3 (#20588) 2014-02-10 22:41:40 -05:00
Benjamin Peterson c2f665e721 don't put runtime values in array initializer for C89 compliance (closes #20588) 2014-02-10 22:19:02 -05:00
Serhiy Storchaka 5940b92909 Do not reset the line number because we already set file position to correct
value.

(fixes error in patch for issue #18960)
2014-01-09 20:13:52 +02:00
Serhiy Storchaka 1064a13bb0 Do not reset the line number because we already set file position to correct
value.

(fixes error in patch for issue #18960)
2014-01-09 20:12:49 +02:00
Serhiy Storchaka 7282ff6d5b Issue #18960: Fix bugs with Python source code encoding in the second line.
* The first line of Python script could be executed twice when the source
encoding (not equal to 'utf-8') was specified on the second line.

* Now the source encoding declaration on the second line isn't effective if
the first line contains anything except a comment.

* As a consequence, 'python -x' works now again with files with the source
encoding declarations specified on the second file, and can be used again
to make Python batch files on Windows.

* The tokenize module now ignore the source encoding declaration on the second
line if the first line contains anything except a comment.

* IDLE now ignores the source encoding declaration on the second line if the
first line contains anything except a comment.

* 2to3 and the findnocoding.py script now ignore the source encoding
declaration on the second line if the first line contains anything except
a comment.
2014-01-09 18:41:59 +02:00
Serhiy Storchaka 768c16ce02 Issue #18960: Fix bugs with Python source code encoding in the second line.
* The first line of Python script could be executed twice when the source
encoding (not equal to 'utf-8') was specified on the second line.

* Now the source encoding declaration on the second line isn't effective if
the first line contains anything except a comment.

* As a consequence, 'python -x' works now again with files with the source
encoding declarations specified on the second file, and can be used again
to make Python batch files on Windows.

* The tokenize module now ignore the source encoding declaration on the second
line if the first line contains anything except a comment.

* IDLE now ignores the source encoding declaration on the second line if the
first line contains anything except a comment.

* 2to3 and the findnocoding.py script now ignore the source encoding
declaration on the second line if the first line contains anything except
a comment.
2014-01-09 18:36:09 +02:00
Christian Heimes af01f66817 Issue #16136: Remove VMS support and VMS-related code 2013-12-21 16:19:10 +01:00
Christian Heimes 724b828e79 upcast int to size_t to silence two autological-constant-out-of-range-compare warnings with clang. 2013-12-04 08:42:46 +01:00
Victor Stinner cad876d542 Fix a compiler warning on Windows 64-bit in parsetok.c
Python parser doesn't support lines longer than INT_MAX bytes yet
2013-11-18 01:09:51 +01:00
Victor Stinner 3a8a333942 Fix compiler warnings on Windows 64-bit in grammar.c
INT_MAX states and labels should be enough for everyone
2013-11-18 01:07:38 +01:00
Serhiy Storchaka c679227e31 Issue #1772673: The type of char* arguments now changed to const char*. 2013-10-19 21:03:34 +03:00
Victor Stinner c548660af5 Issue #16742: My fix on PyOS_StdioReadline() was incomplete, PyMem_FREE() was
not patched
2013-10-19 02:40:16 +02:00
Antoine Pitrou d01d396e7f Issue #4555: All exported C symbols are now prefixed with either "Py" or "_Py".
("make smelly" now clean)
2013-10-12 22:52:43 +02:00
Victor Stinner 2fe9bac4dc Close #16742: Fix misuse of memory allocations in PyOS_Readline()
The GIL must be held to call PyMem_Malloc(), whereas PyOS_Readline() releases
the GIL to read input.

The result of the C callback PyOS_ReadlineFunctionPointer must now be a string
allocated by PyMem_RawMalloc() or PyMem_RawRealloc() (or NULL if an error
occurred), instead of a string allocated by PyMem_Malloc() or PyMem_Realloc().

Fixing this issue was required to setup a hook on PyMem_Malloc(), for example
using the tracemalloc module.

PyOS_Readline() copies the result of PyOS_ReadlineFunctionPointer() into a new
buffer allocated by PyMem_Malloc(). So the public API of PyOS_Readline() does
not change.
2013-10-10 16:18:20 +02:00
Eli Bendersky 1891cff587 Move open outside try/finally 2013-09-26 09:35:39 -07:00
Eli Bendersky 99081238e9 Don't use fancy new Python features like 'with' - some bots don't have them
and can't bootstrap the parser.
2013-09-26 06:41:36 -07:00
Eli Bendersky 58fe1b1307 Normalize whitespace 2013-09-26 06:32:22 -07:00
Eli Bendersky b788a385cd Small fixes in Parser/asdl.py - no change in functionality.
1. Make it work when invoked directly from the command-line. It was failing
   due to a couple of stale function/class usages in the __main__ section.
2. Close the parsed file in the parse() function after opening it.
2013-09-26 06:31:32 -07:00
Victor Stinner daf455554b Issue #18571: Implementation of the PEP 446: file descriptors and file handles
are now created non-inheritable; add functions os.get/set_inheritable(),
os.get/set_handle_inheritable() and socket.socket.get/set_inheritable().
2013-08-28 00:53:59 +02:00
Victor Stinner 14e461d5b9 Close #11619: The parser and the import machinery do not encode Unicode
filenames anymore on Windows.
2013-08-26 22:28:21 +02:00
Ezio Melotti d640fe2af5 #18803: merge with 3.3. 2013-08-26 01:33:30 +03:00
Ezio Melotti 7c4a7e6f3c #18803: fix more typos. Patch by Févry Thibault. 2013-08-26 01:32:56 +03:00
Antoine Pitrou 9ed5f27266 Issue #18722: Remove uses of the "register" keyword in C code. 2013-08-13 20:18:52 +02:00
Christian Heimes 73207e03ad Issue #18368: PyOS_StdioReadline() no longer leaks memory when realloc() fails. 2013-08-06 16:03:33 +02:00
Christian Heimes 9ae513caa7 Issue #18368: PyOS_StdioReadline() no longer leaks memory when realloc() fails. 2013-08-06 15:59:16 +02:00
Christian Heimes 1289565f4b Silence warning about set but unused variable inside compile_atom() in non-debug builds 2013-07-31 23:48:04 +02:00
Christian Heimes 5e4d372524 Silence warning about set but unused variable inside compile_atom() in non-debug builds 2013-07-31 23:47:56 +02:00
Christian Heimes b7f1b38dea Issue #18552: Check return value of PyArena_AddPyObject() in obj2ast_object(). 2013-07-27 00:33:35 +02:00
Christian Heimes 70c94e7896 Issue #18552: Check return value of PyArena_AddPyObject() in obj2ast_object(). 2013-07-27 00:33:13 +02:00
Victor Stinner b318990cac (Merge 3.3) Parser/asdl_c.py: use Py_CLEAR() 2013-07-27 00:04:42 +02:00
Victor Stinner 1acc129d48 Parser/asdl_c.py: use Py_CLEAR() 2013-07-27 00:03:47 +02:00
Victor Stinner ee4b59c0f8 (Merge 3.3) According to the PEP 7, C code must "use 4-space indents"
Replace 8 spaces with 4.
2013-07-27 00:01:35 +02:00
Victor Stinner ce72e1ce6c According to the PEP 7, C code must "use 4-space indents"
Replace 8 spaces with 4.
2013-07-27 00:00:36 +02:00
Christian Heimes 7b3902a20f Some compilers complain about 'control reaches end of non-void function'
because they don't understand that Py_FatalError() terminates the program.
2013-07-22 16:34:28 +02:00
Christian Heimes 1eb0cb12ac Some compilers complain about 'control reaches end of non-void function'
because they don't understand that Py_FatalError() terminates the program.
2013-07-22 16:34:13 +02:00
Christian Heimes 826b754e32 Add sanity check to PyGrammar_LabelRepr() in order to catch invalid tokens when debugging
a new grammar.
CID 715360
2013-07-22 10:30:45 +02:00
Christian Heimes 53d2dc4045 Add sanity check to PyGrammar_LabelRepr() in order to catch invalid tokens when debugging
a new grammar.
CID 715360
2013-07-22 10:30:14 +02:00
Victor Stinner bdf630c4a7 Issue #18408: Fix Python-ast.c: handle init_types() failure (ex: MemoryError) 2013-07-17 00:17:15 +02:00
Benjamin Peterson cb2226cb69 merge 3.3 2013-07-15 20:50:25 -07:00
Benjamin Peterson 265fba40c8 move declaration to top of block 2013-07-15 20:50:22 -07:00
Benjamin Peterson fd9c0203de merge 3.3 (closes #18470) 2013-07-15 20:47:47 -07:00
Benjamin Peterson 2dbfd88245 check the return value of new_string() (closes #18470) 2013-07-15 19:15:34 -07:00
Victor Stinner 526daabf34 Issue #18408: parsetok() must not write into stderr on memory allocation error
The caller gets an error code and can raise a classic Python exception.
2013-07-11 23:17:33 +02:00
Victor Stinner 3bf5f530d9 Issue #18408: parsetok() must not write into stderr on memory allocation error
The caller gets an error code and can raise a classic Python exception.
2013-07-11 22:52:19 +02:00
Christian Heimes 22ed7fe906 Fix resource leak in parser, free node ptr
CID 1028068 (#1 of 1): Resource leak (RESOURCE_LEAK)
leaked_storage: Variable n going out of scope leaks the storage it points to.
2013-06-29 21:03:51 +02:00
Serhiy Storchaka 9670543a00 Issue #18038: SyntaxError raised during compilation sources with illegal
encoding now always contains an encoding name.
2013-06-09 16:53:55 +03:00
Serhiy Storchaka 3af14aaba5 Issue #18038: SyntaxError raised during compilation sources with illegal
encoding now always contains an encoding name.
2013-06-09 16:51:52 +03:00
Victor Stinner 796977360f Issue #9566: Fix compiler warning on Windows 64-bit 2013-06-05 00:44:00 +02:00
Benjamin Peterson 8d89c2aaba change AST codegen to use PyModule_AddIntMacro 2013-05-20 10:28:48 -07:00
Benjamin Peterson 7654ab9ef0 placate msvc 2013-03-18 23:39:53 -07:00
Benjamin Peterson b72406b8fa refactor to fix refleaks 2013-03-18 23:24:41 -07:00
Benjamin Peterson cda75be02a unify some ast.argument's attrs; change Attribute column offset (closes #16795)
Patch from Sven Brauch.
2013-03-18 10:48:58 -07:00
Martin v. Löwis b26a9b10ea Replace WaitForSingleObject with WaitForSingleObjectEx,
for better WinRT compatibility.
2013-01-25 14:25:48 +01:00
Benjamin Peterson 442f20996d create NameConstant AST class for None, True, and False literals (closes #16619) 2012-12-06 17:41:04 -05:00
Mark Dickinson 073f067369 Issue #16546: merge fix from 3.3 2012-11-25 14:37:43 +00:00