Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-119127: functools.partial placeholders#119827
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
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
ee7333c8bcc462c67c9b4680d9009591ff5067e9388af20b3607a0b1f55801e58941453722e07a79c2af12aaa7292c767b496a9d238d9c11707b95714b38ca32bca198576493a3fd2d608529936fea348caec6e8115b8c53f5f00b202c9292c16d38400ff558ccc38fe7c82c7c9b7ef3e59d7117bfc5917957a978aaee6afe8e0ad00dd80ed352cfa9038ed549b8c71bc1fdbd30672211185510266b4fadd58a125971fbb9033650d31e5d1a3d39b09e4c5df16f12f882dd600f9cb653d255524404044e800217b38ee45011f47db3c872bdfd16189a6c6ef21c8d73ea8bd3ae70e47ed2eacf5ef78d8d30a8640e6e3d28266c305d14bf68cee642d58d6c28e8744bcbb8964704881ae6c3ad7d95e5d484File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -25,6 +25,7 @@ class _functools._lru_cache_wrapper "PyObject *" "&lru_cache_type_spec" | ||
| typedef struct _functools_state { | ||
| /* this object is used delimit args and keywords in the cache keys */ | ||
| PyObject *kwd_mark; | ||
| PyObject *placeholder; | ||
| PyTypeObject *partial_type; | ||
| PyTypeObject *keyobject_type; | ||
| PyTypeObject *lru_list_elem_type; | ||
| @@ -66,6 +67,7 @@ typedef struct { | ||
| PyObject *kw; | ||
| PyObject *dict; /* __dict__ */ | ||
| PyObject *weakreflist; /* List of weak references */ | ||
| PyObject *placeholder; | ||
| Py_ssize_t np; /* Number of placeholders */ | ||
| vectorcallfunc vectorcall; | ||
| } partialobject; | ||
| @@ -141,14 +143,16 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw) | ||
| Py_DECREF(pto); | ||
| return NULL; | ||
| } | ||
| pto->placeholder = state->placeholder; | ||
| Py_ssize_t nnp = 0; | ||
| Py_ssize_t nnargs = PyTuple_GET_SIZE(nargs); | ||
| PyObject *item; | ||
| if (nnargs > 0){ | ||
dg-pb marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| Py_ssize_t i; | ||
| for (i=nnargs; i > 0;) { | ||
| item = PyTuple_GET_ITEM(nargs, i-1); | ||
| if (!Py_Is(item,pto->placeholder)) | ||
| break; | ||
| i--; | ||
| } | ||
| @@ -158,7 +162,7 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw) | ||
| if (nnargs > 0){ | ||
| for (Py_ssize_t i=0; i < nnargs; i++){ | ||
| item = PyTuple_GET_ITEM(nargs, i); | ||
| if (Py_Is(item,pto->placeholder)) | ||
| nnp++; | ||
| } | ||
| } | ||
| @@ -173,7 +177,7 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw) | ||
| for (Py_ssize_t i=0; i < anargs; i++) { | ||
| if (i < pnargs) { | ||
| item = PyTuple_GET_ITEM(pargs, i); | ||
| if ((j < nnargs) & Py_Is(item,pto->placeholder)){ | ||
dg-pb marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| item = PyTuple_GET_ITEM(nargs, j); | ||
| j++; | ||
| pnp--; | ||
| @@ -348,7 +352,7 @@ partial_vectorcall(partialobject *pto, PyObject *const *args, | ||
| nargs_new = pto_nargs + nargs - np; | ||
| Py_ssize_t j = 0; // Placeholder counter | ||
dg-pb marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| for (Py_ssize_t i=0; i < pto_nargs; i++) { | ||
| if (Py_Is(pto_args[i],pto->placeholder)){ | ||
| memcpy(stack + i, args + j, 1 * sizeof(PyObject*)); | ||
| j += 1; | ||
| } else { | ||
| @@ -438,7 +442,7 @@ partial_call(partialobject *pto, PyObject *args, PyObject *kwargs) | ||
| Py_ssize_t j = 0; // Placeholder counter | ||
| for (Py_ssize_t i=0; i < pto_nargs; i++) { | ||
dg-pb marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| item = PyTuple_GET_ITEM(pto_args, i); | ||
| if (Py_Is(item,pto->placeholder)){ | ||
dg-pb marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| item = PyTuple_GET_ITEM(args, j); | ||
| j += 1; | ||
| } | ||
| @@ -1616,6 +1620,14 @@ _functools_exec(PyObject *module) | ||
| return -1; | ||
| } | ||
| state->placeholder = (PyObject *)&placeholder_type; | ||
| if (state->placeholder == NULL) { | ||
| return -1; | ||
| } | ||
| if (PyModule_AddType(module, &placeholder_type) < 0) { | ||
| return -1; | ||
| } | ||
| state->partial_type = (PyTypeObject *)PyType_FromModuleAndSpec(module, | ||
| &partial_type_spec, NULL); | ||
| if (state->partial_type == NULL) { | ||
| @@ -1624,9 +1636,6 @@ _functools_exec(PyObject *module) | ||
| if (PyModule_AddType(module, state->partial_type) < 0) { | ||
| return -1; | ||
| } | ||
| PyObject *lru_cache_type = PyType_FromModuleAndSpec(module, | ||
| &lru_cache_type_spec, NULL); | ||
| @@ -1663,6 +1672,7 @@ _functools_traverse(PyObject *module, visitproc visit, void *arg) | ||
| { | ||
| _functools_state *state = get_functools_state(module); | ||
| Py_VISIT(state->kwd_mark); | ||
| Py_VISIT(state->placeholder); | ||
| Py_VISIT(state->partial_type); | ||
| Py_VISIT(state->keyobject_type); | ||
| Py_VISIT(state->lru_list_elem_type); | ||
| @@ -1674,6 +1684,7 @@ _functools_clear(PyObject *module) | ||
| { | ||
| _functools_state *state = get_functools_state(module); | ||
| Py_CLEAR(state->kwd_mark); | ||
| Py_CLEAR(state->placeholder); | ||
| Py_CLEAR(state->partial_type); | ||
| Py_CLEAR(state->keyobject_type); | ||
| Py_CLEAR(state->lru_list_elem_type); | ||