Niklas Fiekas
8bd216dfed
bpo-29882: Add an efficient popcount method for integers ( #771 )
...
* bpo-29882: Add an efficient popcount method for integers
* Update 'sign bit' and versionadded in docs
* Add entry to whatsnew document
* Doc: use positive example, mention population count
* Minor cleanups of the core code
* Move popcount_digit closer to where it's used
* Use z instead of self after conversion
* Add 'absolute value' and 'population count' to docstring
* Fix clinic error about missing summary line
* Ensure popcount_digit is portable with 64-bit ints
Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2020-05-29 17:28:02 +01:00
Serhiy Storchaka
5f4b229df7
bpo-40792: Make the result of PyNumber_Index() always having exact type int. (GH-20443)
...
Previously, the result could have been an instance of a subclass of int.
Also revert bpo-26202 and make attributes start, stop and step of the range
object having exact type int.
Add private function _PyNumber_Index() which preserves the old behavior
of PyNumber_Index() for performance to use it in the conversion functions
like PyLong_AsLong().
2020-05-28 10:33:45 +03:00
Mark Dickinson
20941de0dd
bpo-37999: Fix outdated __int__ and nb_int references in comments (GH-20449)
...
* Fix outdated __int__ and nb_int references in comments
* Also update C-API documentation
* Add back missing 'method' word
* Remove .. deprecated notices
2020-05-27 13:43:17 +01:00
Serhiy Storchaka
578c3955e0
bpo-37999: No longer use __int__ in implicit integer conversions. (GH-15636)
...
Only __index__ should be used to make integer conversions lossless.
2020-05-26 18:43:38 +03:00
Sergey Fedoseev
86a93fddf7
bpo-37986: Improve perfomance of PyLong_FromDouble() (GH-15611)
...
* bpo-37986: Improve perfomance of PyLong_FromDouble()
* Use strict bound check for safety and symmetry
* Remove possibly outdated performance claims
Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2020-05-10 10:15:57 +01:00
Dong-hee Na
b88cd585d3
bpo-40455: Remove gcc10 warning about x_digits ( #19852 )
...
* bpo-40455: Remove gcc10 warning about x_digits
* bpo-40455: nit
* bpo-40455: fix logic error
2020-05-04 22:32:42 +09:00
Victor Stinner
4a3fe08353
bpo-40268: Include explicitly pycore_interp.h (GH-19505)
...
pycore_pystate.h no longer includes pycore_interp.h:
it's now included explicitly in files accessing PyInterpreterState.
2020-04-14 14:26:24 +02:00
Serhiy Storchaka
8f87eefe7f
bpo-39943: Add the const qualifier to pointers on non-mutable PyBytes data. (GH-19472)
2020-04-12 14:58:27 +03:00
Petr Viktorin
ffd9753a94
bpo-39245: Switch to public API for Vectorcall (GH-18460)
...
The bulk of this patch was generated automatically with:
for name in \
PyObject_Vectorcall \
Py_TPFLAGS_HAVE_VECTORCALL \
PyObject_VectorcallMethod \
PyVectorcall_Function \
PyObject_CallOneArg \
PyObject_CallMethodNoArgs \
PyObject_CallMethodOneArg \
;
do
echo $name
git grep -lwz _$name | xargs -0 sed -i "s/\b_$name\b/$name/g"
done
old=_PyObject_FastCallDict
new=PyObject_VectorcallDict
git grep -lwz $old | xargs -0 sed -i "s/\b$old\b/$new/g"
and then cleaned up:
- Revert changes to in docs & news
- Revert changes to backcompat defines in headers
- Nudge misaligned comments
2020-02-11 17:46:57 +01:00
Victor Stinner
60ac6ed557
bpo-39573: Use Py_SET_SIZE() function (GH-18402)
...
Replace direct acccess to PyVarObject.ob_size with usage of
the Py_SET_SIZE() function.
2020-02-07 23:18:08 +01:00
Victor Stinner
58ac700fb0
bpo-39573: Use Py_TYPE() macro in Objects directory (GH-18392)
...
Replace direct access to PyObject.ob_type with Py_TYPE().
2020-02-07 03:04:21 +01:00
Victor Stinner
c6e5c1123b
bpo-39489: Remove COUNT_ALLOCS special build (GH-18259)
...
Remove:
* COUNT_ALLOCS macro
* sys.getcounts() function
* SHOW_ALLOC_COUNT code in listobject.c
* SHOW_TRACK_COUNT code in tupleobject.c
* PyConfig.show_alloc_count field
* -X showalloccount command line option
* @test.support.requires_type_collecting decorator
2020-02-03 15:17:15 +01:00
Dong-hee Na
0d5eac8c32
closes bpo-39415: Remove unused codes from longobject.c complexobject.c floatobject.c. (GH-18105)
2020-01-21 18:49:30 -08:00
Niklas Fiekas
c5b79003f5
bpo-31031: Unify duplicate bits_in_digit and bit_length (GH-2866)
...
Add _Py_bit_length() to unify duplicate bits_in_digit() and bit_length().
2020-01-16 15:09:19 +01:00
Victor Stinner
630c8df5cf
bpo-38858: Small integer per interpreter (GH-17315)
...
Each Python subinterpreter now has its own "small integer
singletons": numbers in [-5; 257] range.
It is no longer possible to change the number of small integers at
build time by overriding NSMALLNEGINTS and NSMALLPOSINTS macros:
macros should now be modified manually in pycore_pystate.h header
file.
For now, continue to share _PyLong_Zero and _PyLong_One singletons
between all subinterpreters.
2019-12-17 13:02:18 +01:00
Sergey Fedoseev
1f9f69dd4c
bpo-27961: Replace PY_LLONG_MAX, PY_LLONG_MIN and PY_ULLONG_MAX with standard macros (GH-15385)
...
Use standard constants LLONG_MIN, LLONG_MAX and ULLONG_MAX.
2019-12-05 15:55:28 +01:00
HongWeipeng
036fe85bd3
bpo-27145: small_ints[x] could be returned in long_add and long_sub (GH-15716)
2019-11-26 16:54:49 +09:00
Victor Stinner
5dcc06f6e0
bpo-38858: Allocate small integers on the heap (GH-17301)
...
Allocate small Python integers (small_ints of longobject.c) on the
heap, rather than using static objects.
2019-11-21 08:51:59 +01:00
Victor Stinner
6314abcc08
bpo-37802: Fix a compiler warning in longobject.c (GH-16517)
...
bpo-37802, bpo-38321: Fix the following warnings:
longobject.c(420): warning C4244: 'function': conversion from
'unsigned __int64' to 'sdigit', possible loss of data
longobject.c(428): warning C4267: 'function': conversion from
'size_t' to 'sdigit', possible loss of data
2019-10-01 13:29:53 +02:00
HongWeipeng
42acb7b8d2
bpo-35696: Simplify long_compare() (GH-16146)
2019-09-19 00:10:15 +09:00
Sergey Fedoseev
c6734ee7c5
bpo-37802: Slightly improve perfomance of PyLong_FromUnsigned*() (GH-15192)
2019-09-12 15:41:14 +01:00
Raymond Hettinger
7117074410
bpo-38096: Clean up the "struct sequence" / "named tuple" docs (GH-15895)
...
* bpo-38096: Clean up the "struct sequence" / "named tuple" docs
* Fix remaining occurrences of "struct sequence"
* Repair a user visible docstring
2019-09-11 15:17:32 +01:00
Jordon Xu
2ec7010206
bpo-37752: Delete redundant Py_CHARMASK in normalizestring() (GH-15095)
2019-09-10 17:04:08 +01:00
animalize
6b519985d2
replace inline function `is_small_int` with a macro version (GH-15710)
2019-09-05 23:00:56 -07:00
Victor Stinner
bed4817d52
Make PyXXX_Fini() functions private (GH-15531)
...
For example, rename PyTuple_Fini() to _PyTuple_Fini().
These functions are only declared in the internal C API.
2019-08-27 00:12:32 +02:00
Greg Price
5e63ab05f1
bpo-37812: Convert CHECK_SMALL_INT macro to a function so the return is explicit. (GH-15216)
2019-08-24 10:19:37 -07:00
Jeroen Demeyer
196a530e00
bpo-37483: add _PyObject_CallOneArg() function ( #14558 )
2019-07-04 19:31:34 +09:00
Zackery Spytz
dc2476500d
bpo-37170: Fix the cast on error in PyLong_AsUnsignedLongLongMask() (GH-13860)
2019-06-06 22:39:23 +02:00
Petr Viktorin
1e375c6269
bpo-36027: Really fix "incompatible pointer type" compiler warning (GH-13761)
...
Apologies for the earlier hasty attempt.
2019-06-03 02:28:29 +02:00
Petr Viktorin
e584cbff1e
bpo-36027 bpo-36974: Fix "incompatible pointer type" compiler warnings (GH-13758)
2019-06-03 01:08:14 +02:00
Mark Dickinson
c52996785a
bpo-36027: Extend three-argument pow to negative second argument (GH-13266)
2019-06-02 10:24:06 +01:00
Jeroen Demeyer
530f506ac9
bpo-36974: tp_print -> tp_vectorcall_offset and tp_reserved -> tp_as_async (GH-13464)
...
Automatically replace
tp_print -> tp_vectorcall_offset
tp_compare -> tp_as_async
tp_reserved -> tp_as_async
2019-05-30 19:13:39 -07:00
Inada Naoki
7d408697a9
remove unnecessary tp_dealloc (GH-13647)
2019-05-29 17:23:27 +09:00
Serhiy Storchaka
a5119e7d75
bpo-36957: Add _PyLong_Rshift() and _PyLong_Lshift(). (GH-13416)
2019-05-19 14:14:38 +03:00
Serhiy Storchaka
96aeaec647
bpo-36793: Remove unneeded __str__ definitions. (GH-13081)
...
Classes that define __str__ the same as __repr__ can
just inherit it from object.
2019-05-06 22:29:40 +03:00
stratakis
a10d426bab
bpo-36292: Mark unreachable code as such in long bitwise ops (GH-12333)
2019-03-18 18:59:20 +01:00
Serhiy Storchaka
6a44f6eef3
bpo-36048: Use __index__() instead of __int__() for implicit conversion if available. (GH-11952)
...
Deprecate using the __int__() method in implicit conversions of Python
numbers to C integers.
2019-02-25 17:57:58 +02:00
Sergey Fedoseev
ea6207d593
bpo-36063: Minor performance tweak in long_divmod(). (GH-11915)
2019-02-21 12:01:11 +02:00
Victor Stinner
6d43f6f081
bpo-35713: Split _Py_InitializeCore into subfunctions (GH-11650)
...
* Split _Py_InitializeCore_impl() into subfunctions: add multiple pycore_init_xxx() functions
* Preliminary sys.stderr is now set earlier to get an usable
sys.stderr ealier.
* Move code into _Py_Initialize_ReconfigureCore() to be able to call
it from _Py_InitializeCore().
* Split _PyExc_Init(): create a new _PyBuiltins_AddExceptions()
function.
* Call _PyExc_Init() earlier in _Py_InitializeCore_impl()
and new_interpreter() to get working exceptions earlier.
* _Py_ReadyTypes() now returns _PyInitError rather than calling
Py_FatalError().
* Misc code cleanup
2019-01-22 21:18:05 +01:00
Victor Stinner
b509d52083
bpo-35059: PyObject_INIT() casts to PyObject* (GH-10674)
...
PyObject_INIT() and PyObject_INIT_VAR() now cast their first argument
to PyObject*, as done in Python 3.7.
Revert partially commit b4435e20a9
.
2018-11-23 14:27:38 +01:00
Pablo Galindo
49c75a8086
bpo-35064 prefix smelly symbols that appear with COUNT_ALLOCS with _Py_ (GH-10152)
...
Configuring python with ./configure --with-pydebug CFLAGS="-D COUNT_ALLOCS -O0"
makes "make smelly" fail as some symbols were being exported without the "Py_" or
"_Py" prefixes.
2018-10-28 15:02:17 +00:00
Victor Stinner
b4435e20a9
bpo-35059: Convert PyObject_INIT() to function (GH-10077)
...
* Convert PyObject_INIT() and PyObject_INIT_VAR() macros to static
inline functions.
* Fix usage of these functions: cast to PyObject* or PyVarObject*.
2018-10-26 14:35:00 +02:00
Serhiy Storchaka
b2e2025941
bpo-33073: Rework int.as_integer_ratio() implementation (GH-9303)
...
* Simplify the C code.
* Simplify tests and make them more strict and robust.
* Add references in the documentation.
2018-10-19 23:46:31 +02:00
Zackery Spytz
7bb9cd0a67
bpo-34899: Fix a possible assertion failure due to int_from_bytes_impl() (GH-9705)
...
The _PyLong_FromByteArray() call in int_from_bytes_impl() was
unchecked.
2018-10-06 00:02:23 +03:00
Raymond Hettinger
73820a60cc
Fix compiler warning with a type cast (GH-9300)
2018-09-14 01:35:59 -07:00
Raymond Hettinger
00bc08ec11
Fix-up parenthesis, organization, and NULL check (GH-9297)
2018-09-14 01:00:11 -07:00
Lisa Roach
5ac704306f
bpo-33073: Adding as_integer_ratio to ints. (GH-8750)
2018-09-13 23:56:23 -07:00
Serhiy Storchaka
7cb7bcff20
bpo-20260: Implement non-bitwise unsigned int converters for Argument Clinic. (GH-8434)
2018-07-26 13:22:16 +03:00
Serhiy Storchaka
6405feecda
bpo-33012: Fix invalid function casts for long_long. (GH-6652)
...
long_long() was used with three function types:
PyCFunction, getter and unaryfunction.
2018-04-30 15:35:08 +03:00
Siddhesh Poyarekar
55edd0c185
bpo-33012: Fix invalid function cast warnings with gcc 8 for METH_NOARGS. (GH-6030)
...
METH_NOARGS functions need only a single argument but they are cast
into a PyCFunction, which takes two arguments. This triggers an
invalid function cast warning in gcc8 due to the argument mismatch.
Fix this by adding a dummy unused argument.
2018-04-29 21:59:33 +03:00
Victor Stinner
dd431b32f4
PyLong_FromString(): fix Coverity CID 1424951 ( #4738 )
...
Explicitly cast digits (Py_ssize_t) to double to fix the following
false-alarm warning from Coverity:
"fsize_z = digits * log_base_BASE[base] + 1;"
CID 1424951: Incorrect expression (UNINTENDED_INTEGER_DIVISION)
Dividing integer expressions "9223372036854775783UL" and "4UL", and
then converting the integer quotient to type "double". Any remainder,
or fractional part of the quotient, is ignored.
2017-12-08 00:06:55 +01:00
Serhiy Storchaka
29ba688034
bpo-31619: Fixed integer overflow in converting huge strings to int. ( #3884 )
2017-12-03 22:16:21 +02:00
Sanyam Khurana
28b624825e
bpo-16055: Fixes incorrect error text for int('1', base=1000) ( #4376 )
...
* bpo-16055: Fixes incorrect error text for int('1', base=1000)
* bpo-16055: Address review comments
2017-11-13 13:49:26 -08:00
Serhiy Storchaka
9b6c60cbce
bpo-31979: Simplify transforming decimals to ASCII ( #4336 )
...
in int(), float() and complex() parsers.
This also speeds up parsing non-ASCII numbers by around 20%.
2017-11-13 21:23:48 +02:00
stratakis
e8b1965639
bpo-23699: Use a macro to reduce boilerplate code in rich comparison functions (GH-793)
2017-11-02 20:32:54 +10:00
Serhiy Storchaka
85c0b8941f
bpo-31619: Fixed a ValueError when convert a string with large number of underscores ( #3827 )
...
to integer with binary base.
2017-10-03 14:13:44 +03:00
Barry Warsaw
b2e5794870
bpo-31338 ( #3374 )
...
* Add Py_UNREACHABLE() as an alias to abort().
* Use Py_UNREACHABLE() instead of assert(0)
* Convert more unreachable code to use Py_UNREACHABLE()
* Document Py_UNREACHABLE() and a few other macros.
2017-09-14 18:13:16 -07:00
Serhiy Storchaka
918403cfc3
bpo-29816: Shift operation now has less opportunity to raise OverflowError. ( #680 )
...
ValueError always is raised rather than OverflowError for negative counts.
Shifting zero with non-negative count always returns zero.
2017-03-30 09:47:07 +03:00
Serhiy Storchaka
ba85d69a3e
bpo-29878: Add global instances of int for 0 and 1. ( #852 )
2017-03-30 09:09:41 +03:00
Serhiy Storchaka
18b250f844
bpo-29793: Convert some builtin types constructors to Argument Clinic. ( #615 )
2017-03-19 08:51:07 +02:00
svelankar
390a0969c1
bpo-29749: Update int() docstring (GH-565)
...
The docstring did not properly represent the fact that the argument to int() was positional-only.
2017-03-08 16:29:01 -08:00
Serhiy Storchaka
2e5642422f
bpo-29695: Remove bad keyword parameters in int(), bool(), float(), list() and tuple(). ( #518 )
2017-03-06 17:01:06 +02:00
orenmn
86aa269646
remove 3 redundant casts in Objects/longobject.c ( #445 )
2017-03-06 08:42:47 +00:00
Serhiy Storchaka
58d23e6806
bpo-29695: Deprecated using bad named keyword arguments in builtings: ( #486 )
...
int(), bool(), float(), list() and tuple(). Specify the value as a
positional argument instead.
2017-03-06 00:53:39 +02:00
Serhiy Storchaka
196a7bc1ea
Issue #29421 : Make int.to_bytes() and int.from_bytes() slightly faster
...
(10-20% for small integers).
2017-02-02 16:54:45 +02:00
Serhiy Storchaka
495e8808d7
Issue #20185 : Converted the int class to Argument Clinic.
...
Based on patch by Vajrasky Kok.
2017-02-01 23:12:20 +02:00
Victor Stinner
de4ae3d486
Backed out changeset b9c9691c72c5
...
Issue #28858 : The change b9c9691c72c5 introduced a regression. It seems like
_PyObject_CallArg1() uses more stack memory than
PyObject_CallFunctionObjArgs().
2016-12-04 22:59:09 +01:00
Victor Stinner
27580c1fb5
Replace PyObject_CallFunctionObjArgs() with fastcall
...
* PyObject_CallFunctionObjArgs(func, NULL) => _PyObject_CallNoArg(func)
* PyObject_CallFunctionObjArgs(func, arg, NULL) => _PyObject_CallArg1(func, arg)
PyObject_CallFunctionObjArgs() allocates 40 bytes on the C stack and requires
extra work to "parse" C arguments to build a C array of PyObject*.
_PyObject_CallNoArg() and _PyObject_CallArg1() are simpler and don't allocate
memory on the C stack.
This change is part of the fastcall project. The change on listsort() is
related to the issue #23507 .
2016-12-01 14:43:22 +01:00
Serhiy Storchaka
460bd0d284
Issue #19569 : Compiler warnings are now emitted if use most of deprecated
...
functions.
2016-11-20 12:16:46 +02:00
Serhiy Storchaka
85b0f5beb1
Added the const qualifier to char* variables that refer to readonly internal
...
UTF-8 represenatation of Unicode objects.
2016-11-20 10:16:47 +02:00
Serhiy Storchaka
1a73bf365e
Issue #28701 : Replace PyUnicode_CompareWithASCIIString with _PyUnicode_EqualToASCIIString.
...
The latter function is more readable, faster and doesn't raise exceptions.
2016-11-16 10:19:57 +02:00
Serhiy Storchaka
3b73ea1278
Issue #28701 : Replace PyUnicode_CompareWithASCIIString with _PyUnicode_EqualToASCIIString.
...
The latter function is more readable, faster and doesn't raise exceptions.
2016-11-16 10:19:20 +02:00
Serhiy Storchaka
f4934ea77d
Issue #28701 : Replace PyUnicode_CompareWithASCIIString with _PyUnicode_EqualToASCIIString.
...
The latter function is more readable, faster and doesn't raise exceptions.
2016-11-16 10:17:58 +02:00
Serhiy Storchaka
b2e64f903d
Issue #28621 : Sped up converting int to float by reusing faster bits counting
...
implementation. Patch by Adrian Wielgosik.
2016-11-08 20:34:22 +02:00
Mark Dickinson
c1c4a64edb
Issue #27111 : Minor simplication to long_add and long_sub fast path code. Thanks Oren Milman.
2016-09-17 20:01:56 +01:00
Mark Dickinson
fba121fe9d
Issue #27441 : Remove some redundant assignments to ob_size in longobject.c. Thanks Oren Milman.
2016-09-17 19:44:13 +01:00
Mark Dickinson
92ca535626
Issue #27222 : various cleanups in long_rshift. Thanks Oren Milman.
2016-09-17 17:50:50 +01:00
Mark Dickinson
82cb124300
Issue #25221 : merge from 3.5.
2016-09-10 20:20:08 +01:00
Mark Dickinson
36820dd5a9
Issue #25221 : Fix corrupted result from PyLong_FromLong(0) when Python is compiled with NSMALLPOSINTS = 0.
2016-09-10 20:17:36 +01:00
Brett Cannon
a721abac29
Issue #26331 : Implement the parsing part of PEP 515.
...
Thanks to Georg Brandl for the patch.
2016-09-09 14:57:09 -07:00
Martin Panter
0be894b2f6
Issue #27895 : Spelling fixes (Contributed by Ville Skyttä).
2016-09-07 12:03:06 +00:00
Benjamin Peterson
2f8bfef158
replace PY_SIZE_MAX with SIZE_MAX
2016-09-07 09:26:18 -07:00
Benjamin Peterson
ca47063998
replace Py_(u)intptr_t with the c99 standard types
2016-09-06 13:47:26 -07:00
Benjamin Peterson
d953f8e10b
remove some silly defined() tests
2016-09-06 10:51:19 -07:00
Benjamin Peterson
af580dff4a
replace PY_LONG_LONG with long long
2016-09-06 10:46:49 -07:00
Benjamin Peterson
ed4aa83ff7
require a long long data type ( closes #27961 )
2016-09-05 17:44:18 -07:00
Raymond Hettinger
15f44ab043
Issue #27895 : Spelling fixes (Contributed by Ville Skyttä).
2016-08-30 10:47:49 -07:00
Mark Dickinson
82a95277b8
Issue #27870 : A left shift of zero by a large integer no longer attempts to allocate large amounts of memory.
2016-08-29 19:27:06 +01:00
Mark Dickinson
4e1de16f88
Issue #25402 : in int-to-decimal-string conversion, reduce intermediate storage requirements and relax restriction on converting large integers. Patch by Serhiy Storchaka.
2016-08-29 17:26:43 +01:00
Mark Dickinson
583c6e860c
Issue #27214 : Fix potential bug and remove useless optimization in long_invert. Thanks Oren Milman.
2016-08-29 16:40:29 +01:00
Mark Dickinson
b820d7f631
Issue #27792 : force int return type for modulo operations involving bools.
2016-08-22 12:24:46 +01:00
Mark Dickinson
1dc3c898a8
Untabify Objects/longobject.c.
2016-08-21 10:33:36 +01:00
Mark Dickinson
dc590a4cc3
Issue #25604 : Fix minor bug in integer true division, which could
...
have caused off-by-one-ulp results on certain platforms.
2016-08-21 10:23:23 +01:00
Victor Stinner
8bcf312d09
Issue #27786 : Simplify x_sub()
...
The z variable is known to be a fresh number which cannot be shared, Py_SIZE()
can be used directly to negate the number.
2016-08-17 19:48:33 +02:00
Martin Panter
8bde911115
Issue #27626 : Merge spelling fixes from 3.5
2016-07-28 01:30:58 +00:00
Martin Panter
eb9957065a
Issue #27626 : Spelling fixes in docs, comments and internal names
...
Based on patch by Ville Skyttä.
2016-07-28 01:11:04 +00:00
Serhiy Storchaka
e63e5d60ee
Issue #27073 : Removed redundant checks in long_add and long_sub.
...
Patch by Oren Milman.
2016-06-04 00:06:45 +03:00
Serhiy Storchaka
ea36c941a1
Issue #23640 : int.from_bytes() no longer bypasses constructors for subclasses.
2016-05-12 10:37:58 +03:00
Serhiy Storchaka
1f364438ad
Issue #23640 : int.from_bytes() no longer bypasses constructors for subclasses.
2016-05-12 10:39:32 +03:00
Victor Stinner
f963c13597
longobject.c: fix compilation warning on Windows 64-bit
...
We know that Py_SIZE(b) is -1 or 1 an so fits into the sdigit type.
2016-03-23 18:36:54 +01:00