Commit Graph

4292 Commits

Author SHA1 Message Date
Benjamin Peterson 1ff2e35e84 simplify by shortcutting when the kind of the needle is larger than the haystack 2012-05-11 17:41:20 -05:00
Antoine Pitrou ca5f91b888 Issue #14738: Speed-up UTF-8 decoding on non-ASCII data. Patch by Serhiy Storchaka. 2012-05-10 16:36:02 +02:00
Victor Stinner 3b1a74a9c3 Rename unicode_write_t structure and its methods to "_PyUnicodeWriter" 2012-05-09 22:25:00 +02:00
Victor Stinner ee4544c920 Issue #14744: Inline unicode_writer_write_char() and unicode_write_str()
Optimize also PyUnicode_Format(): call unicode_writer_prepare() only once
per argument.
2012-05-09 22:24:08 +02:00
Victor Stinner f59c28c930 unicode_writer_finish() checks string consistency 2012-05-09 03:24:14 +02:00
Benjamin Peterson 1cffbac2cb merge 3.2 (#14752) 2012-05-08 09:22:45 -04:00
Benjamin Peterson 89a6e9a27b fix possible refleak (closes #14752) 2012-05-08 09:22:24 -04:00
Victor Stinner 106802547c Backout ab500b297900: the check for integer overflow is wrong
Issue #14716: Change integer overflow check in unicode_writer_prepare()
to compute the limit at compile time instead of runtime. Patch writen by Serhiy
Storchaka.
2012-05-07 23:50:05 +02:00
Victor Stinner 0576f9b4cf Issue #14716: Change integer overflow check in unicode_writer_prepare()
to compute the limit at compile time instead of runtime. Patch writen by Serhiy
Storchaka.
2012-05-07 13:02:44 +02:00
Victor Stinner 202fdca133 Close #14716: str.format() now uses the new "unicode writer" API instead of the
PyAccu API. For example, it makes str.format() from 25% to 30% faster on Linux.
2012-05-07 12:47:02 +02:00
Mark Dickinson 99e2e5552a Issue #14700: Fix two broken and undefined-behaviour-inducing overflow checks in old-style string formatting. Thanks Serhiy Storchaka for report and original patch. 2012-05-07 11:20:50 +01:00
Victor Stinner d0dba6eee8 unicode_writer: don't force inline when it is not necessary
Keep inline for performance critical functions (functions used in loops)
2012-05-04 01:19:15 +02:00
Benjamin Peterson 9cd8853d45 merge 3.2 (#14717) 2012-05-03 18:44:33 -04:00
Benjamin Peterson ab3da290fe close() doesn't take any args (closes #14717) 2012-05-03 18:44:09 -04:00
Benjamin Peterson b63f49f2b4 if the kind of the string to count is larger than the string to search, shortcut to 0 2012-05-03 18:31:07 -04:00
Victor Stinner a7b654be30 unicode_writer: add finish() method and assertions to write_str() method
* The write_str() method does nothing if the length is zero.
 * Replace "struct unicode_writer_t" with "unicode_writer_t"
2012-05-03 23:58:55 +02:00
Victor Stinner bf4e266397 Issue #14687: Remove redundant length attribute of unicode_write_t
The length can be read directly from the buffer
2012-05-03 19:27:14 +02:00
Victor Stinner 7989157e49 Issue #14687: Cleanup unicode_writer_prepare()
"Inline" PyUnicode_Resize(): call directly resize_compact()
2012-05-03 13:43:07 +02:00
Victor Stinner f2c76aa6cb Issue #14687: str%tuple now uses an optimistic "unicode writer" instead of an
accumulator. Directly write characters into the output (don't use a temporary
list): resize and widen the string on demand.
2012-05-03 13:10:40 +02:00
Victor Stinner 1b487b467b Issue #14624, #14687: Optimize unicode_widen()
Don't convert uninitialized characters. Patch written by Serhiy Storchaka.
2012-05-03 12:29:04 +02:00
Victor Stinner 3a7f7977f1 Remove buggy assertion in PyUnicode_Substring()
Use also directly unicode_empty, instead of PyUnicode_New(0,0).
2012-05-03 03:36:40 +02:00
Victor Stinner 684d5fd420 Fix PyUnicode_Substring() for start >= length and start > end
Remove the fast-path for 1-character string: unicode_fromascii() and
_PyUnicode_FromUCS*() now have their own fast-path for 1-character strings.
2012-05-03 02:32:34 +02:00
Victor Stinner b6cd014d75 Unicode: optimize creating of 1-character strings 2012-05-03 02:17:04 +02:00
Victor Stinner bff7c96834 Issue #14687: Optimize str%tuple for the "%(name)s" syntax
Avoid an useless and expensive call to PyUnicode_READ().
2012-05-03 01:44:59 +02:00
Victor Stinner e6abb488c9 unicodeobject.c: Add MAX_MAXCHAR() macro to (micro-)optimize the computation
of the second argument of PyUnicode_New().

 * Create also align_maxchar() function
 * Optimize fix_decimal_and_space_to_ascii(): don't compute the maximum
   character when ch <= 127 (it is ASCII)
2012-05-02 01:15:40 +02:00
Victor Stinner 438106b66e Issue #14687: Cleanup PyUnicode_Format() 2012-05-02 00:41:57 +02:00
Victor Stinner b5c3ea3af3 Issue #14687: Optimize str%args
* formatfloat() uses unicode_fromascii() instead of PyUnicode_DecodeASCII()
   to not have to check characters, we know that it is really ASCII
 * Use PyUnicode_FromOrdinal() instead of _PyUnicode_FromUCS4() to format
   a character: if avoids a call to ucs4lib_find_max_char() to compute
   the maximum character (whereas we already know it, it is just the character
   itself)
2012-05-02 00:29:36 +02:00
Benjamin Peterson 8fbd295458 merge 3.2 (#14699) 2012-05-01 09:51:46 -04:00
Benjamin Peterson 7295c6a871 fix calling the classmethod descriptor directly (closes #14699) 2012-05-01 09:51:09 -04:00
Benjamin Peterson a6f195e48e change insertdict to not steal references (#13903) 2012-04-30 10:23:40 -04:00
Victor Stinner b80e46eca4 Issue #14687: Avoid an useless duplicated string in PyUnicode_Format() 2012-04-30 05:21:52 +02:00
Victor Stinner aff3cc659b Issue #14687: Cleanup PyUnicode_Format() 2012-04-30 05:19:21 +02:00
Brett Cannon 62228dbd6c Issues #13959, 14647: Re-implement imp.reload() in Lib/imp.py.
Thanks to Eric Snow for the patch.
2012-04-29 14:38:11 -04:00
Victor Stinner b11d91d969 Fix my previous commit: bool is a long, restore the specical case for bool 2012-04-28 00:25:34 +02:00
Victor Stinner d0880d57b0 Simplify and optimize formatlong()
* Remove _PyBytes_FormatLong(): inline it into formatlong()
 * the input type is always a long, so remove the code for bool
 * don't duplicate the string if the length does not change
 * Use PyUnicode_DATA() instead of _PyUnicode_AsString()
2012-04-27 23:40:13 +02:00
Victor Stinner 94d558b063 Optimize _PyUnicode_FindMaxChar() find pure ASCII strings 2012-04-27 22:26:58 +02:00
Benjamin Peterson 64acccf46d decref cached keys on type deallocation (#13903) 2012-04-27 15:07:36 -04:00
Victor Stinner 8f825060f1 Check newly created consistency using _PyUnicode_CheckConsistency(str, 1)
* In debug mode, fill the string data with invalid characters
 * Simplify also reference counting in PyCodec_BackslashReplaceErrors()
   and PyCodec_XMLCharRefReplaceError()
2012-04-27 13:55:39 +02:00
Victor Stinner 718fbf078c _PyUnicode_CheckConsistency() ensures that the unicode string ends with a
null character
2012-04-26 00:39:37 +02:00
Victor Stinner 3065093bb3 long_to_decimal_string() and _PyLong_Format() check the consistency of newly
created strings using _PyUnicode_CheckConsistency() in debug mode
2012-04-26 00:37:21 +02:00
Benjamin Peterson 15ee821eb5 distiguish between refusing to creating shared keys and error (#13903) 2012-04-24 14:44:18 -04:00
Martin v. Loewis 4f2f3b6217 Account for shared keys in type's __sizeof__ (#13903). 2012-04-24 19:13:57 +02:00
Benjamin Peterson 42f58818d6 merge 3.2 (#14658) 2012-04-24 11:09:20 -04:00
Benjamin Peterson 7b1668735a don't use a slot wrapper from a different special method (closes #14658)
This also alters the fix to #11603. Specifically, setting __repr__ to
object.__str__ now raises a recursion RuntimeError when str() or repr() is
called instead of silently bypassing the recursion. I believe this behavior is
more correct.
2012-04-24 11:06:25 -04:00
Benjamin Peterson 7ce67e45f8 fix dict gc tracking (#13903) 2012-04-24 10:32:57 -04:00
Benjamin Peterson b9f4c9daad make pointer arith c89 2012-04-23 21:45:40 -04:00
Benjamin Peterson f3b7d86e25 use correct base ptr 2012-04-23 18:07:01 -04:00
Benjamin Peterson 2844a7a6d3 simplify and reformat 2012-04-23 18:00:25 -04:00
Victor Stinner ece58deb9f Close #14648: Compute correctly maxchar in str.format() for substrin 2012-04-23 23:36:38 +02:00
Benjamin Peterson db780d0d13 fix instance dicts with str subclasses (#13903) 2012-04-23 13:44:32 -04:00
Benjamin Peterson 53b977127f don't make shared keys with dict subclasses 2012-04-23 11:50:47 -04:00
Benjamin Peterson 7d95e40721 Implement PEP 412: Key-sharing dictionaries (closes #13903)
Patch from Mark Shannon.
2012-04-23 11:24:50 -04:00
Mark Dickinson 9a359bd97f Issue #14630: Merge fix from 3.2. 2012-04-20 21:44:09 +01:00
Mark Dickinson bcc17eefd2 Issue #14630: Fix an incorrect access of ob_digit[0] for a zero instance of an int subclass. 2012-04-20 21:42:49 +01:00
Mark Dickinson e28465482c Issue #14339: Improve speed of bin, oct and hex builtins. Patch by Serhiy Storchaka (with minor modifications). 2012-04-20 21:21:24 +01:00
Victor Stinner b0b224233e Issue #14385: Support other types than dict for __builtins__
It is now possible to use a custom type for the __builtins__ namespace, instead
of a dict. It can be used for sandboxing for example.  Raise also a NameError
instead of ImportError if __build_class__ name if not found in __builtins__.
2012-04-19 00:57:45 +02:00
Benjamin Peterson 6e3358a1d5 merge 3.2 (#14612) 2012-04-18 11:19:00 -04:00
Benjamin Peterson e42fb307ed SETUP_WITH acts like SETUP_FINALLY for the purposes of setting f_lineno (closes #14612) 2012-04-18 11:14:31 -04:00
Victor Stinner 0db176f8f6 Issue #14386: Expose the dict_proxy internal type as types.MappingProxyType 2012-04-16 00:16:30 +02: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
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
Benjamin Peterson 64ed576de8 merge 3.2 (#14509) 2012-04-09 15:04:39 -04:00
Benjamin Peterson ca819c3c9d merge 3.1 (#14509) 2012-04-09 15:01:02 -04:00
Benjamin Peterson f6622c8a3e fix build without Py_DEBUG and DNDEBUG (closes #14509) 2012-04-09 14:53:07 -04:00
Victor Stinner afb5205c48 Close #14249: Use bit shifts instead of an union, it's more efficient.
Patch written by Serhiy Storchaka
2012-04-05 22:54:49 +02:00
Victor Stinner e7eee01f36 Close #14249: Use an union instead of a long to short pointer to avoid aliasing
issue. Speed up UTF-16 by 20%.
2012-04-05 13:44:34 +02:00
Antoine Pitrou a701388de1 Rename _PyIter_GetBuiltin to _PyObject_GetBuiltin, and do not include it in the stable ABI. 2012-04-05 00:04:20 +02:00
Kristján Valur Jónsson 31668b8f7a Issue #14288: Serialization support for builtin iterators. 2012-04-03 10:49:41 +00:00
Benjamin Peterson 9ee601e197 merge 3.2 2012-04-01 18:51:37 -04:00
Benjamin Peterson b6af60c2a9 adjust formatting 2012-04-01 18:49:54 -04:00
Benjamin Peterson 3471bb67e7 remove extraneous condition 2012-04-01 18:48:40 -04:00
Benjamin Peterson 29f843816b merge heads 2012-04-01 18:48:11 -04:00
Benjamin Peterson ab3c1c1994 be consistent with rest of function 2012-04-01 18:48:02 -04:00
Antoine Pitrou 29b964d0dd Issue #13019: Fix potential reference leaks in bytearray.extend().
Patch by Suman Saha.
2012-04-01 16:08:11 +02:00
Antoine Pitrou 58bb82e7b4 Issue #13019: Fix potential reference leaks in bytearray.extend().
Patch by Suman Saha.
2012-04-01 16:05:46 +02:00
Kristján Valur Jónsson daa06544c8 Issue #14435: Remove special block allocation code from floatobject.c
PyFloatObjects are now allocated using PyObject_MALLOC like all other
internal types, but maintain a limited freelist of objects at hand for
performance.  This will result in more consistent memory usage by Python.
2012-03-30 09:18:15 +00: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
Benjamin Peterson 0df542985a grammar 2012-03-26 14:50:32 -04:00
Benjamin Peterson c067d6661f merge 3.2 2012-03-25 22:41:16 -04:00
Benjamin Peterson a8755c586e kill this terribly outdated comment 2012-03-25 22:40:54 -04:00
Antoine Pitrou d0acb411ef Issue #14387: Do not include accu.h from Python.h. 2012-03-22 14:42:18 +01:00
Antoine Pitrou 0197ff97d0 Issue #14387: Do not include accu.h from Python.h. 2012-03-22 14:38:16 +01:00
Victor Stinner 59af08f545 Micro-optimize PyObject_GetAttrString()
w cannot be NULL so use Py_DECREF() instead of Py_XDECREF().
2012-03-22 02:09:08 +01:00
Benjamin Peterson 520e8508a0 long() -> int() 2012-03-21 14:51:14 -04:00
Benjamin Peterson b7f1da5a3c make _PyNumber_ConvertIntegralToInt static, since it's only used in abstract.c 2012-03-21 14:44:43 -04:00
Benjamin Peterson d614e707ca rewrite this function, which was still accounting for classic classes 2012-03-21 14:38:11 -04:00
Benjamin Peterson 1b1a8e7cb5 correctly lookup __trunc__ in int() constructor 2012-03-20 23:48:11 -04:00
Benjamin Peterson 9fc9bf465a some more identifier goodness 2012-03-20 23:26:41 -04:00
Benjamin Peterson 96384b93aa make extra arguments to object.__init__/__new__ to errors in most cases (finishes #1683368) 2012-03-17 00:05:44 -05:00
Benjamin Peterson 9a03ecfa50 simply this slightly 2012-03-16 20:15:54 -05:00
Benjamin Peterson de394543b4 merge 3.2 (#14334) 2012-03-16 09:35:38 -05:00
Benjamin Peterson 16d84ac355 check to make sure the attribute is a string (#14334) 2012-03-16 09:32:59 -05:00
Benjamin Peterson f50af113ab space 2012-03-15 15:37:54 -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
Victor Stinner ba108823b6 Close #14232: catch mmap() failure in new_arena() of obmalloc 2012-03-10 00:21:44 +01:00
Benjamin Peterson 74529ad3f4 refactor and avoid warnings 2012-03-09 07:25:32 -08:00
Victor Stinner 2d01dc00bc Issue #14211: _PyObject_GenericSetAttrWithDict() keeps a strong reference to
the descriptor because it may be destroyed before being used, destroyed during
the update of the dict for example.
2012-03-09 00:44:13 +01:00
Victor Stinner d74782b0ac Close #14199: _PyType_Lookup() and super_getattro() keep a strong reference to
the type MRO to avoid a crash if the MRO is changed during the lookup.
2012-03-09 00:39:08 +01:00
Benjamin Peterson 9a6338651e merge 3.2 (#3787e896dbe9) 2012-03-07 18:52:52 -06:00
Benjamin Peterson 52c424343d allow cycles throught the __dict__ slot to be cleared (closes #1469629)
Patch from Armin, test from me.
2012-03-07 18:41:11 -06:00