• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef Py_INTERNAL_LONG_H
2 #define Py_INTERNAL_LONG_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6 
7 #ifndef Py_BUILD_CORE
8 #  error "this header requires Py_BUILD_CORE define"
9 #endif
10 
11 /*
12  * Default int base conversion size limitation: Denial of Service prevention.
13  *
14  * Chosen such that this isn't wildly slow on modern hardware and so that
15  * everyone's existing deployed numpy test suite passes before
16  * https://github.com/numpy/numpy/issues/22098 is widely available.
17  *
18  * $ python -m timeit -s 's = "1"*4300' 'int(s)'
19  * 2000 loops, best of 5: 125 usec per loop
20  * $ python -m timeit -s 's = "1"*4300; v = int(s)' 'str(v)'
21  * 1000 loops, best of 5: 311 usec per loop
22  * (zen2 cloud VM)
23  *
24  * 4300 decimal digits fits a ~14284 bit number.
25  */
26 #define _PY_LONG_DEFAULT_MAX_STR_DIGITS 4300
27 /*
28  * Threshold for max digits check.  For performance reasons int() and
29  * int.__str__() don't checks values that are smaller than this
30  * threshold.  Acts as a guaranteed minimum size limit for bignums that
31  * applications can expect from CPython.
32  *
33  * % python -m timeit -s 's = "1"*640; v = int(s)' 'str(int(s))'
34  * 20000 loops, best of 5: 12 usec per loop
35  *
36  * "640 digits should be enough for anyone." - gps
37  * fits a ~2126 bit decimal number.
38  */
39 #define _PY_LONG_MAX_STR_DIGITS_THRESHOLD 640
40 
41 #if ((_PY_LONG_DEFAULT_MAX_STR_DIGITS != 0) && \
42    (_PY_LONG_DEFAULT_MAX_STR_DIGITS < _PY_LONG_MAX_STR_DIGITS_THRESHOLD))
43 # error "_PY_LONG_DEFAULT_MAX_STR_DIGITS smaller than threshold."
44 #endif
45 
46 #ifdef __cplusplus
47 }
48 #endif
49 #endif /* !Py_INTERNAL_LONG_H */
50