Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-132775: Unrevert "Add _PyCode_GetVarCounts()"#133265

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
Changes from1 commit
Commits
Show all changes
22 commits
Select commitHold shift + click to select a range
d9c3672
gh-132775: Unrevert "Add _PyCode_GetVarCounts()"
ericsnowcurrentlyMay 1, 2025
54b6192
Avoid casting to int.
ericsnowcurrentlyMay 1, 2025
b97326f
Cast to int.
ericsnowcurrentlyMay 1, 2025
1e6aa82
Add an assert.
ericsnowcurrentlyMay 1, 2025
881c798
Add some helper macros.
ericsnowcurrentlyMay 1, 2025
ae1efb3
Track counts using a local variable.
ericsnowcurrentlyMay 1, 2025
5f6fe84
Do not double-count names.
ericsnowcurrentlyMay 1, 2025
c9855f1
Temporarily skip some code.
ericsnowcurrentlyMay 2, 2025
f1f9df9
Temporarily skip some code.
ericsnowcurrentlyMay 2, 2025
09678e4
Temporarily skip some code.
ericsnowcurrentlyMay 2, 2025
1ab3c28
Temporarily skip some code.
ericsnowcurrentlyMay 3, 2025
3ba74f6
Temporarily skip some code.
ericsnowcurrentlyMay 3, 2025
d6ed560
Temporarily skip some code.
ericsnowcurrentlyMay 3, 2025
93377fe
Temporarily skip some code.
ericsnowcurrentlyMay 3, 2025
170c354
Temporarily skip some code.
ericsnowcurrentlyMay 3, 2025
0128404
Temporarily skip some code.
ericsnowcurrentlyMay 3, 2025
4fa2ecf
Temporarily skip some code.
ericsnowcurrentlyMay 3, 2025
4347b13
Print the ind=ex.
ericsnowcurrentlyMay 3, 2025
c199564
Print more stuff.
ericsnowcurrentlyMay 4, 2025
88f7beb
Drop the temporary code.
ericsnowcurrentlyMay 5, 2025
c8877e4
Respect op caches.
ericsnowcurrentlyMay 5, 2025
5b3c975
Add a critical section.
ericsnowcurrentlyMay 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Track counts using a local variable.
  • Loading branch information
@ericsnowcurrently
ericsnowcurrently committedMay 1, 2025
commitae1efb3fdd6210d9dee3587693efe1a2de1f8bda
58 changes: 29 additions & 29 deletionsObjects/codeobject.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1728,23 +1728,22 @@ identify_unbound_names(PyThreadState *tstate, PyCodeObject *co,
assert(globalsns == NULL || PyDict_Check(globalsns));
assert(builtinsns == NULL || PyDict_Check(builtinsns));
assert(counts == NULL || counts->total == 0);
struct co_unbound_counts unbound = {0};
Py_ssize_t len = Py_SIZE(co);
for (int i = 0; i < len; i++) {
_Py_CODEUNIT inst = _Py_GetBaseCodeUnit(co, i);
if (inst.op.code == LOAD_ATTR) {
int oparg = GET_OPARG(co, i, inst.op.arg);
int index = LOAD_ATTR_NAME_INDEX(oparg);
PyObject *name = GETITEM(co->co_names, index);
if (counts != NULL) {
if (PySet_Contains(attrnames, name)) {
if (_PyErr_Occurred(tstate)) {
return -1;
}
continue;
if (PySet_Contains(attrnames, name)) {
if (_PyErr_Occurred(tstate)) {
return -1;
}
counts->total += 1;
counts->numattrs += 1;
continue;
}
unbound.total += 1;
unbound.numattrs += 1;
if (PySet_Add(attrnames, name) < 0) {
return -1;
}
Expand All@@ -1753,36 +1752,37 @@ identify_unbound_names(PyThreadState *tstate, PyCodeObject *co,
int oparg = GET_OPARG(co, i, inst.op.arg);
int index = LOAD_ATTR_NAME_INDEX(oparg);
PyObject *name = GETITEM(co->co_names, index);
if (counts != NULL) {
if (PySet_Contains(globalnames, name)) {
if (_PyErr_Occurred(tstate)) {
return -1;
}
continue;
if (PySet_Contains(globalnames, name)) {
if (_PyErr_Occurred(tstate)) {
return -1;
}
counts->total += 1;
counts->globals.total += 1;
counts->globals.numunknown += 1;
if (globalsns != NULL && PyDict_Contains(globalsns, name)) {
if (_PyErr_Occurred(tstate)) {
return -1;
}
counts->globals.numglobal += 1;
counts->globals.numunknown -= 1;
continue;
}
unbound.total += 1;
unbound.globals.total += 1;
unbound.globals.numunknown += 1;
if (globalsns != NULL && PyDict_Contains(globalsns, name)) {
if (_PyErr_Occurred(tstate)) {
return -1;
}
if (builtinsns != NULL && PyDict_Contains(builtinsns, name)) {
if (_PyErr_Occurred(tstate)) {
return -1;
}
counts->globals.numbuiltin += 1;
counts->globals.numunknown -=1;
unbound.globals.numglobal += 1;
unbound.globals.numunknown -= 1;
}
if (builtinsns != NULL && PyDict_Contains(builtinsns, name)) {
if (_PyErr_Occurred(tstate)) {
return -1;
}
unbound.globals.numbuiltin += 1;
unbound.globals.numunknown -= 1;
}
if (PySet_Add(globalnames, name) < 0) {
return -1;
}
}
}
if (counts != NULL) {
*counts = unbound;
}
return 0;
}

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp