Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
bpo-40137: Convert _functools module to use PyType_FromModuleAndSpec.#23405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
8 commits Select commitHold shift + click to select a range
63b68b5 test
shihai19912ddffb0 update pep573 in functools extension module
shihai19914578c7c Merge remote-tracking branch 'origin/master' into bpo_40137_functools2
shihai19917074ba6 Convert _functools module to use PyType_FromModuleAndSpec.
shihai1991e9a51a5 apply Christian's comment
shihai19913c36c69 Merge remote-tracking branch 'origin/master' into bpo_40137_functools2
shihai19915bb2dd5 apply petr's comment
shihai19911941d85 apply petr's comment
shihai1991File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
apply Christian's comment
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commite9a51a5994fc081daed50d7b99d04f76282800dd
There are no files selected for viewing
3 changes: 1 addition & 2 deletionsLib/test/test_functools.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -27,8 +27,7 @@ | ||
| py_functools=import_helper.import_fresh_module('functools', | ||
| blocked=['_functools']) | ||
| c_functools=import_helper.import_fresh_module('functools') | ||
shihai1991 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| decimal=import_helper.import_fresh_module('decimal',fresh=['_decimal']) | ||
52 changes: 31 additions & 21 deletionsModules/_functoolsmodule.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -43,6 +43,17 @@ get_functools_state(PyObject *module) | ||
| static void partial_setvectorcall(partialobject *pto); | ||
| static struct PyModuleDef _functools_module; | ||
| static inline _functools_state * | ||
| get_functools_state_by_type(PyTypeObject *type) | ||
| { | ||
| PyObject *module = _PyType_GetModuleByDef(type, &_functools_module); | ||
| if (module == NULL) { | ||
| return NULL; | ||
| } | ||
| _functools_state *state = get_functools_state(module); | ||
| return state; | ||
| } | ||
| static PyObject * | ||
| partial_new(PyTypeObject *type, PyObject *args, PyObject *kw) | ||
| { | ||
| @@ -55,11 +66,10 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw) | ||
| return NULL; | ||
| } | ||
| _functools_state *state =get_functools_state_by_type(type); | ||
| if (state == NULL) { | ||
| return NULL; | ||
| } | ||
| pargs = pkw = NULL; | ||
| func = PyTuple_GET_ITEM(args, 0); | ||
| @@ -542,19 +552,18 @@ static PyType_Spec keyobject_type_spec = { | ||
| static PyObject * | ||
| keyobject_call(keyobject *ko, PyObject *args, PyObject *kwds) | ||
| { | ||
| PyObject *object; | ||
| keyobject *result; | ||
| _functools_state *state; | ||
| static char *kwargs[] = {"obj", NULL}; | ||
| if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:K", kwargs, &object)) | ||
| return NULL; | ||
| state =get_functools_state_by_type(Py_TYPE(ko)); | ||
| if (state == NULL) { | ||
| return NULL; | ||
| } | ||
| result = PyObject_New(keyobject, state->keyobject_type); | ||
shihai1991 marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| if (!result) | ||
| return NULL; | ||
| @@ -573,15 +582,13 @@ keyobject_richcompare(PyObject *ko, PyObject *other, int op) | ||
| PyObject *y; | ||
| PyObject *compare; | ||
| PyObject *answer; | ||
| PyObject* stack[2]; | ||
| _functools_state *state; | ||
| state =get_functools_state_by_type(Py_TYPE(ko)); | ||
| if (state == NULL) { | ||
| return NULL; | ||
| } | ||
| if (!Py_IS_TYPE(other, state->keyobject_type)) { | ||
| PyErr_Format(PyExc_TypeError, "other argument must be K instance"); | ||
| return NULL; | ||
| @@ -784,7 +791,8 @@ typedef struct lru_cache_object { | ||
| } lru_cache_object; | ||
| static PyObject * | ||
| lru_cache_make_key(_functools_state *state, PyObject *args, | ||
| PyObject *kwds, int typed) | ||
| { | ||
| PyObject *key, *keyword, *value; | ||
| Py_ssize_t key_size, pos, key_pos, kwds_size; | ||
| @@ -822,7 +830,6 @@ lru_cache_make_key(PyObject *module, PyObject *args, PyObject *kwds, int typed) | ||
| Py_INCREF(item); | ||
| PyTuple_SET_ITEM(key, key_pos++, item); | ||
| } | ||
| if (kwds_size) { | ||
| Py_INCREF(state->kwd_mark); | ||
| PyTuple_SET_ITEM(key, key_pos++, state->kwd_mark); | ||
| @@ -867,10 +874,14 @@ uncached_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwd | ||
| static PyObject * | ||
| infinite_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds) | ||
| { | ||
| PyObject *result; | ||
| Py_hash_t hash; | ||
| _functools_state *state; | ||
| state = get_functools_state_by_type(Py_TYPE(self)); | ||
| if (state == NULL) { | ||
| return NULL; | ||
| } | ||
| PyObject *key = lru_cache_make_key(state, args, kwds, self->typed); | ||
| if (!key) | ||
| return NULL; | ||
| hash = PyObject_Hash(key); | ||
| @@ -968,15 +979,15 @@ static PyObject * | ||
| bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds) | ||
| { | ||
| lru_list_elem *link; | ||
| PyObject *key, *result, *testresult; | ||
| Py_hash_t hash; | ||
| _functools_state *state; | ||
| state =get_functools_state_by_type(Py_TYPE(self)); | ||
| if (state == NULL) { | ||
| return NULL; | ||
| } | ||
| key = lru_cache_make_key(state, args, kwds, self->typed); | ||
| if (!key) | ||
| return NULL; | ||
| hash = PyObject_Hash(key); | ||
| @@ -1030,7 +1041,6 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds | ||
| self->root.next == &self->root) | ||
| { | ||
| /* Cache is not full, so put the result in a new link */ | ||
| link = (lru_list_elem *)PyObject_New(lru_list_elem, | ||
| state->lru_list_elem_type); | ||
| if (link == NULL) { | ||
18 changes: 5 additions & 13 deletionsModules/_pickle.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.