Commit Graph

3800 Commits

Author SHA1 Message Date
Brian Curtin 09b86d1196 Fix #14600. Correct reference handling and naming of ImportError convenience function 2012-04-17 16:57:09 -05:00
Brett Cannon 16475adcbb Issue #13959: Re-implement imp.load_source() in imp.py. 2012-04-16 22:11:25 -04:00
Antoine Pitrou 22a1d17bb5 Fix another refleak 2012-04-16 22:06:21 +02:00
Antoine Pitrou 538ba2afb5 Fix a refleak 2012-04-16 21:52:45 +02:00
Antoine Pitrou 71382cb64b Fix reference loss on Py_None when None is encountered in sys.modules. 2012-04-16 18:48:49 +02:00
Antoine Pitrou a938c74751 Avoid compiler warning due to stray \x00 2012-04-16 18:30:54 +02:00
Brian Curtin b206a80dab Fix #10854. Make use of the new path and name attributes on ImportError
for extension modules on Windows.
2012-04-16 00:10:17 -05:00
Brett Cannon 2ee61422ed Issue #13959: Re-implement imp.load_package() in imp.py.
Thanks to Eric Snow for helping with imp.load_module() (previous
commit) which led to the removal of a bunch of C code.
2012-04-15 22:28:28 -04:00
Brett Cannon 01a76171a0 Issue #13959: Re-implement imp.load_module() in imp.py. 2012-04-15 20:25:23 -04:00
Brett Cannon c1b3f63653 Try to get hg to treat importlib.h as binary. 2012-04-15 19:05:31 -04:00
Brett Cannon 8a1d04c643 Issue #13959: Simplify imp.reload() by relying on a module's
__loader__.

Since import now sets __loader__ on all modules it creates and
imp.reload() already relied on the attribute for modules that import
didn't create, the only potential compatibility issue is if people
were deleting the attribute on modules and expecting imp.reload() to
continue to work.
2012-04-15 17:56:09 -04:00
Brett Cannon 7ceedb8c1e Update importlib.h 2012-04-15 17:47:19 -04:00
Brett Cannon 6f44d66bc4 Issue #13959: Rename imp to _imp and add Lib/imp.py and begin
rewriting functionality in pure Python.

To start, imp.new_module() has been rewritten in pure Python, put into
importlib (privately) and then publicly exposed in imp.
2012-04-15 16:08:47 -04:00
Brett Cannon 881535b726 Issue #14582: Import returns the module returned by a loader instead
of sys.modules when possible.

This is being done for two reasons. One is to gain a little bit of
performance by skipping an unnecessary dict lookup in sys.modules. But
the other (and main) reason is to be a little bit more clear in how
things should work from the perspective of import's interactions with
loaders. Otherwise loaders can easily forget to return the module even
though PEP 302 explicitly states they are expected to return the module
they loaded.
2012-04-15 15:24:04 -04:00
Brett Cannon 27fc52877c Set ImportError.name when raising the exception in the case of None
found in sys.modules.
2012-04-15 14:15:31 -04:00
Brett Cannon fc9ca274b8 Plug a refleak. 2012-04-15 01:35:05 -04:00
Brett Cannon 49f8d8b016 Handle importing pkg.mod by executing
__import__('mod', {'__packaging__': 'pkg', level=1) w/o properly (and
thus not segfaulting).
2012-04-14 21:50:00 -04:00
Brett Cannon 59f9c3affc Rebuild importlib.h to incorporate added comments. 2012-04-14 21:18:48 -04:00
Brian Curtin e6b299faf5 Fix Windows build 2012-04-14 14:19:33 -05:00
Brett Cannon 740fce0e38 Undo a C99 idiom. 2012-04-14 14:23:49 -04:00
Brett Cannon fd0741555b Issue #2377: Make importlib the implementation of __import__().
importlib._bootstrap is now frozen into Python/importlib.h and stored
as _frozen_importlib in sys.modules. Py_Initialize() loads the frozen
code along with sys and imp and then uses _frozen_importlib._install()
to set builtins.__import__() w/ _frozen_importlib.__import__().
2012-04-14 14:10:13 -04:00
Benjamin Peterson 780b66b3e6 merge 3.2 2012-04-13 18:06:42 -04:00
Benjamin Peterson 3bf01757b6 move outside WITH_THREAD conditional 2012-04-13 18:06:36 -04:00
Benjamin Peterson 899ee613f7 merge 3.2 2012-04-13 11:59:52 -04:00
Benjamin Peterson 43162b8a02 take linkage def outside of WITH_THREAD conditional (closes #14569) 2012-04-13 11:58:27 -04:00
Brett Cannon 79ec55e980 Issue #1559549: Add 'name' and 'path' attributes to ImportError.
Currently import does not use these attributes as they are planned
for use by importlib (which will be another commit).

Thanks to Filip Gruszczyński for the initial patch and Brian Curtin
for refining it.
2012-04-12 20:24:54 -04:00
Kristján Valur Jónsson 31668b8f7a Issue #14288: Serialization support for builtin iterators. 2012-04-03 10:49:41 +00:00
Benjamin Peterson 0a9a636302 merge 3.2 2012-04-03 00:35:36 -04:00
Benjamin Peterson 80d50428ce fix parse_syntax_error to clean up its resources 2012-04-03 00:30:38 -04:00
Brett Cannon 368b4b7405 Guard an LLTRACE variable to silence an unused variable warning. 2012-04-02 12:17:59 -04:00
Victor Stinner 3c1e48176e Issue #14383: Add _PyDict_GetItemId() and _PyDict_SetItemId() functions
These functions simplify the usage of static constant Unicode strings.
Generalize the usage of _Py_Identifier in ceval.c and typeobject.c.
2012-03-26 22:10:51 +02:00
Kristján Valur Jónsson 4b0215fd99 Merge with 3.2 2012-03-23 12:52:11 +00:00
Kristján Valur Jónsson c5d47d5ac3 Fix typo when "PyObject*" was changed to "identifier" 2012-03-23 12:50:53 +00:00
Benjamin Peterson cc58031d6a merge 3.2 2012-03-22 10:40:20 -04:00
Benjamin Peterson 9faf5ee750 this should technicaly be identifier 2012-03-22 10:39:16 -04:00
Benjamin Peterson b304764ba2 merge 3.2 2012-03-22 08:56:27 -04:00
Benjamin Peterson ab79c71f39 check for NULL 2012-03-22 08:56:15 -04:00
Benjamin Peterson 98ba753432 merge 3.2 (#14378) 2012-03-22 08:19:50 -04:00
Benjamin Peterson a4e4e35783 check by equality for __future__ not identity (closes #14378) 2012-03-22 08:19:04 -04:00
Benjamin Peterson 302e7902c8 use identifier api 2012-03-20 23:17:04 -04:00
Larry Hastings 83a9f48699 Issue #14328: Add keyword-only parameters to PyArg_ParseTupleAndKeywords.
They're optional-only for now (unlike in pure Python) but that's all
I needed.  The syntax can easily be relaxed if we want to support
required keyword-only arguments for extension types in the future.
2012-03-20 20:06:16 +00:00
Gregory P. Smith c809f98143 Fixes Issue #14331: Use significantly less stack space when importing modules by
allocating path buffers on the heap instead of the stack.
2012-03-18 16:06:53 -07:00
Benjamin Peterson 01feaecbfa plug memory leak (closes #14325) 2012-03-16 13:25:58 -05:00
Benjamin Peterson eb74918685 kill capsule names that we don't need anymore 2012-03-16 12:24:01 -05:00
Benjamin Peterson f7c132158d use memory macros 2012-03-16 12:23:39 -05:00
Benjamin Peterson 7ed67270a8 check result of PyMem_New 2012-03-16 12:21:02 -05:00
Benjamin Peterson f53d20f2cd in 72556ff86828, I should have updated the magic as well as the comment (#14230) 2012-03-16 09:39:12 -05:00
Jean-Paul Calderone c961b4abaa Issue #14325: Stop using python lists, capsules, and the garbage collector to deal with PyArg_Parse* cleanup. 2012-03-16 08:51:42 -04:00
Benjamin Peterson abdb5528c0 fix comment 2012-03-15 15:40:37 -05:00
Benjamin Peterson 2afe6aeae8 perform yield from delegation by repeating YIELD_FROM opcode (closes #14230)
This allows generators that are using yield from to be seen by debuggers. It
also kills the f_yieldfrom field on frame objects.

Patch mostly from Mark Shannon with a few tweaks by me.
2012-03-15 15:37:39 -05:00
Benjamin Peterson 1767e0274b free AST's dict 2012-03-14 21:50:29 -05:00
Ned Deily 577c830531 Issue #14184: merge 2012-03-13 11:31:36 -07:00
Ned Deily 7ca97d5208 Issue #14184: Increase the default stack size for secondary threads on
Mac OS X to prevent interpreter crashes when compiled on 10.7.
2012-03-13 11:18:18 -07:00
Victor Stinner bd273c1ec3 Issue #14180: Fix an invalid rounding when compiler optimization are enabled
Use volatile keyword to disable localy unsafe float optimizations.
2012-03-13 19:12:23 +01:00
Victor Stinner 3a31dd407a Issue #14180: Remove commented code 2012-03-13 13:50:34 +01:00
Victor Stinner 5d272cc6a2 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
time.ctime(), gmtime(), time.localtime(), datetime.date.fromtimestamp(),
datetime.datetime.fromtimestamp() and datetime.datetime.utcfromtimestamp() now
raises an OverflowError, instead of a ValueError, if the timestamp does not fit
in time_t.

datetime.datetime.fromtimestamp() and datetime.datetime.utcfromtimestamp() now
round microseconds towards zero instead of rounding to nearest with ties going
away from zero.
2012-03-13 13:35:55 +01:00
Victor Stinner 45e50de1f5 Try to fix compilation of Python-ast.c on Visual Studio 2008 2012-03-13 01:17:31 +01:00
Benjamin Peterson 518cf94ad7 merge 3.2 2012-03-12 11:16:03 -07:00
Benjamin Peterson 3f3584695e kill this disabled code 2012-03-12 11:15:48 -07:00
Benjamin Peterson bebcd18b75 merge 3.2 2012-03-12 11:02:10 -07:00
Benjamin Peterson bc4665ebcb use correct naming convention 2012-03-12 11:00:41 -07:00
Benjamin Peterson 7e0dbfbbde give the AST class a __dict__ 2012-03-12 09:46:44 -07:00
Georg Brandl f125bf5f94 Update copyright years and version name. 2012-03-04 16:26:19 +01:00
Armin Ronacher 6ecf77b3f8 Basic support for PEP 414 without docs or tests. 2012-03-04 12:04:06 +00:00
Antoine Pitrou 0d3a003f24 - Issue #14177: marshal.loads() now raises TypeError when given an unicode
string.  Patch by Guilherme Gonçalves.
2012-03-03 02:38:37 +01:00
Antoine Pitrou 4a90ef0363 Issue #14177: marshal.loads() now raises TypeError when given an unicode string.
Patch by Guilherme Gonçalves.
2012-03-03 02:35:32 +01:00
Victor Stinner 643cd68ea4 Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Add a private API to convert an int or float to a C timespec structure.
2012-03-02 22:54:03 +01:00
Antoine Pitrou 1c13f84f55 Simplify code in marshal.c. 2012-03-02 18:22:23 +01:00
Antoine Pitrou b2677c7397 Issue #14172: Fix reference leak when marshalling a buffer-like object (other than a bytes object). 2012-03-02 18:16:38 +01:00
Antoine Pitrou 679e9d36f7 Issue #14172: Fix reference leak when marshalling a buffer-like object (other than a bytes object). 2012-03-02 18:12:43 +01:00
Brett Cannon efb00c0cc1 Issue #14153 Create _Py_device_encoding() to prevent _io from having to import
the os module.
2012-02-29 18:31:31 -05:00
Nick Coghlan ab7bf2143e Close issue #6210: Implement PEP 409 2012-02-26 17:49:52 +10:00
Victor Stinner 90f50d4df9 Issue #13706: Fix format(float, "n") for locale with non-ASCII decimal point (e.g. ps_aF) 2012-02-24 01:44:47 +01:00
Victor Stinner 41a863cb81 Issue #13706: Fix format(int, "n") for locale with non-ASCII thousands separator
* Decode thousands separator and decimal point using PyUnicode_DecodeLocale()
   (from the locale encoding), instead of decoding them implicitly from latin1
 * Remove _PyUnicode_InsertThousandsGroupingLocale(), it was not used
 * Change _PyUnicode_InsertThousandsGrouping() API to return the maximum
   character if unicode is NULL
 * Replace MIN/MAX macros by Py_MIN/Py_MAX
 * stringlib/undef.h undefines STRINGLIB_IS_UNICODE
 * stringlib/localeutil.h only supports Unicode
2012-02-24 00:37:51 +01:00
Antoine Pitrou cf1c8339f9 Issue #14084: Fix a file descriptor leak when importing a module with a bad encoding. 2012-02-22 18:08:30 +01:00
Antoine Pitrou 4f22a8d739 Issue #14084: Fix a file descriptor leak when importing a module with a bad encoding. 2012-02-22 18:05:43 +01:00
Antoine Pitrou 7214612443 In find_module(), do not silence fileno() and dup() errors. 2012-02-22 18:03:04 +01:00
Benjamin Peterson c9f54cf512 enable hash randomization by default 2012-02-21 16:08:05 -05:00
Antoine Pitrou 528b54b263 Fix test failure in test_cmd_line by initializing the hash secret at the earliest point. 2012-02-21 19:08:26 +01:00
Antoine Pitrou 86838b02f0 Fix test failure in test_cmd_line by initializing the hash secret at the earliest point. 2012-02-21 19:03:47 +01:00
Benjamin Peterson d9a3591ed1 merge 3.2 2012-02-21 11:12:14 -05:00
Benjamin Peterson e249dcab7a merge 3.2 2012-02-21 11:09:13 -05:00
Benjamin Peterson 69e9727657 ensure no one tries to hash things before the random seed is found 2012-02-21 11:08:50 -05:00
Georg Brandl 2fb477c0f0 Merge 3.2: Issue #13703 plus some related test suite fixes. 2012-02-21 00:33:36 +01:00
Georg Brandl 91e5c08fe8 Fix typo in conditional. 2012-02-20 23:49:29 +01:00
Georg Brandl 12897d7d39 Fix typo in conditional. 2012-02-20 23:49:29 +01:00
Georg Brandl 09a7c72cad Merge from 3.1: Issue #13703: add a way to randomize the hash values of basic types (str, bytes, datetime)
in order to make algorithmic complexity attacks on (e.g.) web apps much more complicated.

The environment variable PYTHONHASHSEED and the new command line flag -R control this
behavior.
2012-02-20 21:31:46 +01:00
Georg Brandl 2daf6ae249 Issue #13703: add a way to randomize the hash values of basic types (str, bytes, datetime)
in order to make algorithmic complexity attacks on (e.g.) web apps much more complicated.

The environment variable PYTHONHASHSEED and the new command line flag -R control this
behavior.
2012-02-20 19:54:16 +01:00
Antoine Pitrou c229e6e8ff Issue #14040: Remove rarely used file name suffixes for C extensions (under POSIX mainly).
This will improve import performance a bit (especially under importlib).
2012-02-20 19:41:11 +01:00
Victor Stinner 4195b5caea Backout f8409b3d6449: the PEP 410 is not accepted yet 2012-02-08 23:03:19 +01:00
Victor Stinner ccd5715a14 PEP 410 2012-02-08 14:31:50 +01:00
Victor Stinner 09225b73c1 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
to have a resolution of 100 ns instead of 1 ms (the clock accuracy is between
0.5 ms and 15 ms).
2012-02-07 23:41:01 +01:00
Petri Lehtinen 4b0eab62f0 Merge branch 3.2
Closes #13402.
2012-02-02 21:23:15 +02:00
Petri Lehtinen 9713321f46 Document absoluteness of sys.executable
Closes #13402.
2012-02-02 20:59:50 +02:00
Victor Stinner ed27785b32 Issue #13706: Add assertions to detect bugs earlier 2012-02-01 00:22:23 +01:00
Victor Stinner a3dd409b52 Remove now useless arbitrary limit of module name length 2012-01-26 00:31:49 +01:00
Antoine Pitrou 581616624d Port import fixes from 2.7. 2012-01-25 18:06:07 +01:00
Antoine Pitrou 33d15f7c85 Port import fixes from 2.7. 2012-01-25 18:01:45 +01:00
Antoine Pitrou abaf89b2be Issue #11235: Fix OverflowError when trying to import a source file whose modification time doesn't fit in a 32-bit timestamp. 2012-01-24 17:45:50 +01:00
Antoine Pitrou 2be60afb7e Issue #11235: Fix OverflowError when trying to import a source file whose modification time doesn't fit in a 32-bit timestamp. 2012-01-24 17:44:06 +01:00