GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-111962: Make dtoa thread-safe in `--disable-gil` builds. by colesbury · Pull Request #112049 · python/cpython Conversation
|
| #define Bigint_Kmax 7 | ||
|
|
||
| /* The size of the cached powers of 5 array */ | ||
| #define Bigint_Pow5max 8 |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'm wondering whether there's a better name here; the "max" part seems potentially confusing (the max value stored here would be 5**2**9, right?). Bigint_Pow5count? Bigint_Pow5size?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I renamed it to Bigint_Pow5size
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| struct _dtoa_state { | ||
| /* p5s is a linked list of powers of 5 of the form 5**(2**i), i >= 2 */ | ||
| /* p5s is an array of powers of 5 of the form 5**(2**i), i >= 2 */ |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nit: Could we adjust this comment to be more explicit about the indexing - i.e., make it clear that p5s[i] is 5**(2**(i+2)) for 0 <= i < Bigint_Pow5max?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| #endif // !Py_USING_MEMORY_DEBUGGER | ||
|
|
||
|
|
||
| /* These functions are used by modules compiled as C extension like math: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Deleted because the comment is out of date, presumably? 👍
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yeah, these comments were about why the below functions used PyAPI_FUNC (were "exported"), but the symbols are no longer exported.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| if (!(k >>= 2)) | ||
| return b; | ||
| assert(k < (1 << (Bigint_Pow5max))); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This single line is by far the hardest to review, and reminds me yet again why I'd be delighted to see dtoa.c go away entirely. :-)
This says that pow5mult will never be called with k >= 1024, right?
I do believe that there's an upper limit on possible k values here, based on:
(2**53 - 1) * 2**-1074), and dtoa.c is clever enough to pad with zeros when requested (e.g., with something crazy like format(math.pi, '.2000f')) rather than try to compute those zeros.And based on the above, 1023 certainly seems plausible as an upper bound for possible k values. I'd be hard pushed to give a proof that k can never exceed 1023, though. (At least, not without spending a lot more time than I currently have available.)
@colesbury Does the above roughly match your reasoning? Would it be possible to add a comment to the code justifying the assertion?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I've added a comment and moved the assertion up. The limits are related to the maximum base-10 exponent. For double-to-string, that's DBL_MAX_10_EXP (308). As you say, we set the limits ourselves for string-to-double, which are e=308 for overflow and e=-512 for underflow. But our exponent can be adjusted based on the number of digits, so we can see values as larges as k=535 float('1' +'0'*38 + '1E-535'), where the limits is from the combination of 512+STRTOD_DIGLIM-DBL_DIG-1.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates! LGTM
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@mdickinson - would you please merge this? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@colesbury Apologies; I'd been assuming you'd merge it (and was beginning to wonder why you hadn't). :-) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Probably Sam doesn't have rights to merge |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…thon#112049) This updates `dtoa.c` to avoid using the Bigint free-list in --disable-gil builds and to pre-computes the needed powers of 5 during interpreter initialization. * pythongh-111962: Make dtoa thread-safe in `--disable-gil` builds. This avoids using the Bigint free-list in `--disable-gil` builds and pre-computes the needed powers of 5 during interpreter initialization. * Fix size of cached powers of 5 array. We need the powers of 5 up to 5**512 because we only jump straight to underflow when the exponent is less than -512 (or larger than 308). * Rename Py_NOGIL to Py_GIL_DISABLED * Changes from review * Fix assertion placement
…thon#112049) This updates `dtoa.c` to avoid using the Bigint free-list in --disable-gil builds and to pre-computes the needed powers of 5 during interpreter initialization. * pythongh-111962: Make dtoa thread-safe in `--disable-gil` builds. This avoids using the Bigint free-list in `--disable-gil` builds and pre-computes the needed powers of 5 during interpreter initialization. * Fix size of cached powers of 5 array. We need the powers of 5 up to 5**512 because we only jump straight to underflow when the exponent is less than -512 (or larger than 308). * Rename Py_NOGIL to Py_GIL_DISABLED * Changes from review * Fix assertion placement
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.