summaryrefslogtreecommitdiff
path: root/Objects/intobject.c
Commit message (Collapse)AuthorAgeFilesLines
* Issue #3439: add bit_length method to int and long.Mark Dickinson2008-12-171-0/+36
| | | | | Thanks Fredrik Johansson and Victor Stinner for code, Raymond Hettinger for review.
* - Issue #2862: Make int and float freelist management consistent with otherGregory P. Smith2008-07-061-35/+25
| | | | | freelists. Changes their CompactFreeList apis into ClearFreeList apis and calls them via gc.collect().
* Revert 64424, 64438, and 64439.Raymond Hettinger2008-06-241-7/+0
|
* Make bin() implementation parallel oct() and hex() so that int/long ↵Raymond Hettinger2008-06-201-0/+7
| | | | subclasses can override or so that other classes can support.
* This reverts r63675 based on the discussion in this thread:Gregory P. Smith2008-06-091-7/+7
| | | | | | | http://mail.python.org/pipermail/python-dev/2008-June/079988.html Python 2.6 should stick with PyString_* in its codebase. The PyBytes_* names in the spirit of 3.0 are available via a #define only. See the email thread.
* Refactor and clean up str.format() code (and helpers) in advance of ↵Eric Smith2008-05-301-16/+11
| | | | optimizations.
* Renamed PyString to PyBytesChristian Heimes2008-05-261-8/+8
|
* I finally got the time to update and merge Mark's and my trunk-math branch. ↵Christian Heimes2008-04-181-0/+12
| | | | | | The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math. The patch also adds acosh, asinh, atanh, log1p and copysign to all platforms. Finally it fixes differences between platforms like different results or exceptions for edge cases. Have fun :)
* Pluralss only need one s, not 2 (intss -> ints)Neal Norwitz2008-03-271-1/+1
|
* Fix build on platforms that don't have intptr_t. Patch by Joseph Armbruster.Jeffrey Yasskin2008-03-181-1/+1
|
* Backport of PEP 3101, Advanced String Formatting, from py3k.Eric Smith2008-02-171-0/+36
| | | | | | | | | | | | | | | Highlights: - Adding PyObject_Format. - Adding string.Format class. - Adding __format__ for str, unicode, int, long, float, datetime. - Adding builtin format. - Adding ''.format and u''.format. - str/unicode fixups for formatters. The files in Objects/stringlib that implement PEP 3101 (stringdefs.h, unicodedefs.h, formatter.h, string_format.h) are identical in trunk and py3k. Any changes from here on should be made to trunk, and changes will propogate to py3k).
* Added PyNumber_ToBase and supporting routines _PyInt_Format andEric Smith2008-02-101-19/+71
| | | | | | | | | | | | | | | | | _PyLong_Format. In longobject.c, changed long_format to _PyLong_Format. In intobject.c, changed uses of PyOS_snprintf to _PyInt_Format instead. _PyLong_Format is similar to py3k's routine of the same name, except it has 2 additional parameters: addL and newstyle. addL was existing in long_format, and controls adding the trailing "L". This is unneeded in py3k. newstyle is used to control whether octal prepends "0" (the pre-2.6 style), or "0o" (the 3.0 sytle). PyNumber_ToBase is needed for PEP 3127 (Integer Literal Support and Syntax) and PEP 3101 (Advanced String Formatting). This changeset does not need merging into py3k.
* Patch #1953Christian Heimes2008-02-041-18/+34
| | | | | I implemented the function sys._compact_freelists() and C API functions PyInt_/PyFloat_CompactFreeList() to compact the pre-allocated blocks of ints and floats. They allow the user to reduce the memory usage of a Python process that deals with lots of numbers. The patch also renames sys._cleartypecache to sys._clear_type_cache
* Continue rolling back pep-3141 changes that changed behavior from 2.5. ThisJeffrey Yasskin2008-01-051-32/+0
| | | | | | | | | | | | round included: * Revert round to its 2.6 behavior (half away from 0). * Because round, floor, and ceil always return float again, it's no longer necessary to have them delegate to __xxx___, so I've ripped that out of their implementations and the Real ABC. This also helps in implementing types that work in both 2.6 and 3.0: you return int from the __xxx__ methods, and let it get enabled by the version upgrade. * Make pow(-1, .5) raise a ValueError again.
* Make math.{floor,ceil}({int,long}) return float again for backwardsJeffrey Yasskin2008-01-041-2/+2
| | | | compatibility after r59671 made them return integral types.
* Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (justJeffrey Yasskin2008-01-031-16/+68
| | | | | | | the complex_pow part), r56649, r56652, r56715, r57296, r57302, r57359, r57361, r57372, r57738, r57739, r58017, r58039, r58040, and r59390, and new documentation. The only significant difference is that round(x) returns a float to preserve backward-compatibility. See http://bugs.python.org/issue1689.
* #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and ↵Christian Heimes2007-12-191-12/+12
| | | | Py_REFCNT. Macros for b/w compatibility are available.
* Add a bunch of GIL release/acquire points in tp_print implementations and forBrett Cannon2007-09-171-1/+4
| | | | | | PyObject_Print(). Closes issue #1164.
* PEP 3123: Provide forward compatibility with Python 3.0, while keepingMartin v. Löwis2007-07-211-14/+13
| | | | | backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and PyVarObject_HEAD_INIT.
* Port rev 55353 from Guido:Neal Norwitz2007-05-161-1/+1
| | | | | | | Add what looks like a necessary call to PyErr_NoMemory() when PyMem_MALLOC() fails. Will backport.
* As per Armin Rigo's suggestion, remove special handing from intobject.c to ↵Kristján Valur Jónsson2007-05-071-7/+2
| | | | deal with the peculiarities of classobject's implementation of the number protocol. The nb_long method of classobject now falls back to nb_int if there is no __long__ attribute present.
* Fix problems in x64 build that were discovered by the testsuite:Kristján Valur Jónsson2007-05-031-0/+4
| | | | | | | | | | | | - Reenable modules on x64 that had been disabled aeons ago for Itanium. - Cleared up confusion about compilers for 64 bit windows. There is only Itanium and x64. Added macros MS_WINI64 and MS_WINX64 for those rare cases where it matters, such as the disabling of modules above. - Set target platform (_WIN32_WINNT and WINVER) to 0x0501 (XP) for x64, and 0x0400 (NT 4.0) otherwise, which are the targeted minimum platforms. - Fixed thread_nt.h. The emulated InterlockedCompareExchange function didn´t work on x64, probaby due to the lack of a "volatile" specifier. Anyway, win95 is no longer a target platform. - Itertools module used wrong constant to check for overflow in count() - PyInt_AsSsize_t couldn't deal with attribute error when accessing the __long__ member. - PyLong_FromSsize_t() incorrectly specified that the operand were unsigned. With these changes, the x64 passes the testsuite, for those modules present.
* Variation of patch # 1624059 to speed up checking if an object is a subclassNeal Norwitz2007-02-251-1/+1
| | | | | | | | | | | | | | | | | | of some of the common builtin types. Use a bit in tp_flags for each common builtin type. Check the bit to determine if any instance is a subclass of these common types. The check avoids a function call and O(n) search of the base classes. The check is done in the various Py*_Check macros rather than calling PyType_IsSubtype(). All the bits are set in tp_flags when the type is declared in the Objects/*object.c files because PyType_Ready() is not called for all the types. Should PyType_Ready() be called for all types? If so and the change is made, the changes to the Objects/*object.c files can be reverted (remove setting the tp_flags). Objects/typeobject.c would also have to be modified to add conditions for Py*_CheckExact() in addition to each the PyType_IsSubtype check.
* Minor change in int() docstring for proper spacing.Gustavo Niemeyer2007-01-101-1/+1
|
* Mention in the int() docstring that a base zero has meaning, asGustavo Niemeyer2007-01-101-2/+3
| | | | stated in http://docs.python.org/lib/built-in-funcs.html as well.
* Bug #1545497: when given an explicit base, int() did ignore NULsGeorg Brandl2006-10-121-2/+19
| | | | embedded in the string to convert.
* Forward-port of r52136,52138: a review of overflow-detecting code.Armin Rigo2006-10-041-2/+14
| | | | | | | | | | | | | | | | | | | | | | | * unified the way intobject, longobject and mystrtoul handle values around -sys.maxint-1. * in general, trying to entierely avoid overflows in any computation involving signed ints or longs is extremely involved. Fixed a few simple cases where a compiler might be too clever (but that's all guesswork). * more overflow checks against bad data in marshal.c. * 2.5 specific: fixed a number of places that were still confusing int and Py_ssize_t. Some of them could potentially have caused "real-world" breakage. * list.pop(x): fixing overflow issues on x was messy. I just reverted to PyArg_ParseTuple("n"), which does the right thing. (An obscure test was trying to give a Decimal to list.pop()... doesn't make sense any more IMHO) * trying to write a few tests...
* Fix integer negation and absolute value to not relyMartin v. Löwis2006-10-041-4/+3
| | | | | on undefined behaviour of the C compiler anymore. Will backport to 2.5 and 2.4.
* "Conceptual" merge of rev 51711 from the 2.5 branch.Tim Peters2006-09-051-1/+1
| | | | | | | | | | | | i_divmod(): As discussed on Python-Dev, changed the overflow checking to live happily with recent gcc optimizations that assume signed integer arithmetic never overflows. This differs from the corresponding change on the 2.5 and 2.4 branches, using a less obscure approach, but one that /may/ tickle platform idiocies in their definitions of LONG_MIN. The 2.4 + 2.5 change avoided introducing a dependence on LONG_MIN, at the cost of substantially goofier code.
* Patch #1538606, Patch to fix __index__() clipping.Neal Norwitz2006-08-121-6/+11
| | | | | | | I modified this patch some by fixing style, some error checking, and adding XXX comments. This patch requires review and some changes are to be expected. I'm checking in now to get the greatest possible review and establish a baseline for moving forward. I don't want this to hold up release if possible.
* C++ compiler cleanup: bunch-o-casts, plus use of unsigned loop index var in ↵Skip Montanaro2006-04-181-17/+18
| | | | a couple places
* Fix int() and long() to repr() their argument when formatting the exception,Thomas Wouters2006-04-111-4/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | to avoid confusing situations like: >>> int("") ValueError: invalid literal for int(): >>> int("2\n\n2") ValueError: invalid literal for int(): 2 2 Also report the base used, to avoid: ValueError: invalid literal for int(): 2 They now report: >>> int("") ValueError: invalid literal for int() with base 10: '' >>> int("2\n\n2") ValueError: invalid literal for int() with base 10: '2\n\n2' >>> int("2", 2) ValueError: invalid literal for int() with base 2: '2' (Reporting the base could be avoided when base is 10, which is the default, but hrm.) Another effect of these changes is that the errormessage can be longer; before, it was cut off at about 250 characters. Now, it can be up to four times as long, as the unrepr'ed string is cut off at 200 characters, instead. No tests were added or changed, since testing for exact errormsgs is (pardon the pun) somewhat errorprone, and I consider not testing the exact text preferable. The actually changed code is tested frequent enough in the test_builtin test as it is (120 runs for each of ints and longs.)
* More C++-compliance. Note especially listobject.c - to get C++ to accept theAnthony Baxter2006-04-111-6/+6
| | | | | | | | | PyTypeObject structures, I had to make prototypes for the functions, and move the structure definition ahead of the functions. I'd dearly like a better way to do this - to change this would make for a massive set of changes to the codebase. There's still some warnings - this is purely to get rid of errors first.
* Remove unnecessary casts in type object initializers.Georg Brandl2006-03-301-1/+1
|
* Checking in the code for PEP 357.Guido van Rossum2006-03-071-0/+1
| | | | | | This was mostly written by Travis Oliphant. I've inspected it all; Neal Norwitz and MvL have also looked at it (in an earlier incarnation).
* Use %ld and casts to long for refcount printing, in absense of a universallyThomas Wouters2006-03-011-2/+7
| | | | | available %zd format character. Mark with an XXX comment so we can fix this, later.
* Revert backwards-incompatible const changes.Martin v. Löwis2006-02-271-1/+1
|
* RFE #1436243: make integers in [0..256] preallocated.Georg Brandl2006-02-221-1/+1
|
* Avoid unused variables when SIZEOF_SIZE_T == SIZEOF_LONG. Also normalizeThomas Wouters2006-02-151-1/+3
| | | | whitespace.
* Merge ssize_t branch.Martin v. Löwis2006-02-151-1/+70
|
* Add const to several API functions that take char *.Jeremy Hylton2005-12-101-1/+1
| | | | | | | | | | | | | | | | | | | In C++, it's an error to pass a string literal to a char* function without a const_cast(). Rather than require every C++ extension module to put a cast around string literals, fix the API to state the const-ness. I focused on parts of the API where people usually pass literals: PyArg_ParseTuple() and friends, Py_BuildValue(), PyMethodDef, the type slots, etc. Predictably, there were a large set of functions that needed to be fixed as a result of these changes. The most pervasive change was to make the keyword args list passed to PyArg_ParseTupleAndKewords() to be a const char *kwlist[]. One cast was required as a result of the changes: A type object mallocs the memory for its tp_doc slot and later frees it. PyTypeObject says that tp_doc is const char *; but if the type was created by type_new(), we know it is safe to cast to char *.
* Make subclasses of int, long, complex, float, and unicode perform typeBrett Cannon2005-04-261-1/+4
| | | | | | | conversion using the proper magic slot (e.g., __int__()). Also move conversion code out of PyNumber_*() functions in the C API into the nb_* function. Applied patch #1109424. Thanks Walter Doewald.
* Stop producing or using OverflowWarning. PEP 237 thought this wouldTim Peters2004-08-251-36/+4
| | | | | | | happen in 2.3, but nobody noticed it still was getting generated (the warning was disabled by default). OverflowWarning and PyExc_OverflowWarning should be removed for 2.5, and left notes all over saying so.
* Check the type of values returned by __int__, __float__, __long__,Neil Schemenauer2004-07-191-6/+0
| | | | | | __oct__, and __hex__. Raise TypeError if an invalid type is returned. Note that PyNumber_Int and PyNumber_Long can still return ints or longs. Fixes SF bug #966618.
* SF bug #980419: int left-shift causes memory leakRaymond Hettinger2004-06-261-4/+26
|
* Reword messageAndrew M. Kuchling2004-06-051-1/+1
|
* Fix exception wordingAndrew M. Kuchling2004-06-051-1/+1
|
* SF patch #875689: >100k alloc wasted on startupRaymond Hettinger2004-02-081-1/+1
| | | | | | | (Contributed by Mike Pall.) Make sure fill_free_list() is called only once rather than 106 times when pre-allocating small ints.
* - Removed FutureWarnings related to hex/oct literals and conversionsGuido van Rossum2003-11-291-30/+12
| | | | | | | | | | and left shifts. (Thanks to Kalle Svensson for SF patch 849227.) This addresses most of the remaining semantic changes promised by PEP 237, except for repr() of a long, which still shows the trailing 'L'. The PEP appears to promise warnings for operations that changed semantics compared to Python 2.3, but this is not implemented; we've suffered through enough warnings related to hex/oct literals and I think it's best to be silent now.
* Add a couple of decrefs to error paths.Michael W. Hudson2003-08-111-2/+4
| | | | | | | Now test_descr only appears to leak two references & I think this are in fact illusory (it's to do with things getting resurrected in __del__ methods & it's easy to be believe confusion occurs when that happens <wink>). Woohoo!