This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2017年03月22日 06:15 by serhiy.storchaka, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| long-constants.diff | serhiy.storchaka, 2017年03月22日 06:15 | |||
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 852 | merged | serhiy.storchaka, 2017年03月27日 18:56 | |
| PR 1001 | merged | serhiy.storchaka, 2017年04月05日 08:35 | |
| Messages (8) | |||
|---|---|---|---|
| msg289974 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2017年03月22日 06:15 | |
When C code needs to compare Python object with int 0 or add int 1 it either use local reference to PyLong_FromLong(0) and PyLong_FromLong(1) which should be decrefed just after use or module level global variable initialized and cleared during initializing and finalizing the module. Proposed patch adds global variables _PyLong_Zero and _PyLong_One for references to integer objects 0 and 1. This simplifies the code since no need to initialize local variables, check for error the result of PyLong_FromLong() and decref it after use. The patch decreases the total code size by 244 lines. That variables are only for internal use. User code should use PyLong_FromLong(0) and PyLong_FromLong(1). |
|||
| msg289983 - (view) | Author: Mark Dickinson (mark.dickinson) * (Python committer) | Date: 2017年03月22日 13:46 | |
I like it. |
|||
| msg289989 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2017年03月22日 14:57 | |
+1. Please create a PR for it. |
|||
| msg289990 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2017年03月22日 15:24 | |
+1 for this idea. Also consider adding new function PyLong_Increment. This basic operation is small pain using the current API. It may also give a small speed benefit. |
|||
| msg290000 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2017年03月22日 16:49 | |
Other common values used in C functions: empty byte string, empty Unicode string, empty tuple. The problem is to make sure that singletons are created in the right order :-/ This issue reminded me an old idea of writing a generalization of the _Py_IDENTIFIER() API. I created an issue #29881: Add a new private API for "static C variables" (_PyStaticVar) to clear them at exit. To be clear: it's related but different to this issue, the two issues are exclusive. |
|||
| msg290005 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2017年03月22日 18:02 | |
Yet one idea that can make the code simpler is make PyLong_FromLong(0) and PyLong_FromLong(1) never failing. I.e. require NSMALLPOSINTS not less than 2. > Also consider adding new function PyLong_Increment. This basic operation is small pain using the current API. It may also give a small speed benefit. Smaller pain with using _PyLong_One and Py_SETREF(). Py_SETREF(long_obj, PyNumber_Add(long_obj, _PyLong_One)); Agree that with _PyLong_Increment() it can look better and be faster. But I don't know whether incrementing by 1 is enough popular operation. I have counted 5 cases in the stdlib (not counting tests): for enumerate, range and Counter. > The problem is to make sure that singletons are created in the right order :-/ Yes, I spent much time for making empty Unicode string singleton always be initialized. It can be accessed at very early stage. |
|||
| msg290818 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2017年03月30日 06:09 | |
New changeset ba85d69a3e3610bdd05f0dd372cf4ebca178c7fb by Serhiy Storchaka in branch 'master': bpo-29878: Add global instances of int for 0 and 1. (#852) https://github.com/python/cpython/commit/ba85d69a3e3610bdd05f0dd372cf4ebca178c7fb |
|||
| msg291170 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2017年04月05日 09:00 | |
New changeset bae6881b4215b2613ad08ef0dc7bed7743c2b8cc by Serhiy Storchaka in branch 'master': Update Argument Clinic generated code for bpo-29878. (#1001) https://github.com/python/cpython/commit/bae6881b4215b2613ad08ef0dc7bed7743c2b8cc |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:44 | admin | set | github: 74064 |
| 2017年04月05日 09:00:44 | serhiy.storchaka | set | messages: + msg291170 |
| 2017年04月05日 08:35:45 | serhiy.storchaka | set | pull_requests: + pull_request1174 |
| 2017年03月30日 06:20:51 | serhiy.storchaka | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2017年03月30日 06:09:43 | serhiy.storchaka | set | messages: + msg290818 |
| 2017年03月27日 18:56:52 | serhiy.storchaka | set | pull_requests: + pull_request752 |
| 2017年03月22日 18:02:43 | serhiy.storchaka | set | messages: + msg290005 |
| 2017年03月22日 16:49:09 | vstinner | set | messages: + msg290000 |
| 2017年03月22日 15:24:13 | rhettinger | set | nosy:
+ rhettinger messages: + msg289990 |
| 2017年03月22日 14:57:34 | vstinner | set | messages: + msg289989 |
| 2017年03月22日 13:46:28 | mark.dickinson | set | messages: + msg289983 |
| 2017年03月22日 06:15:11 | serhiy.storchaka | create | |