Skip to content

Commit 811edcf

Browse files
Revert "gh-132775: Add _PyCode_GetVarCounts() (gh-133128)" (gh-133232)
The change broke the s390 builds, so I'm reverting it while I investigate. This reverts commit 94b4fcd.
1 parent 0119791 commit 811edcf

File tree

5 files changed

+0
-689
lines changed

5 files changed

+0
-689
lines changed

Include/cpython/funcobject.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,6 @@ static inline PyObject* PyFunction_GET_GLOBALS(PyObject *func) {
9797
}
9898
#define PyFunction_GET_GLOBALS(func) PyFunction_GET_GLOBALS(_PyObject_CAST(func))
9999

100-
static inline PyObject* PyFunction_GET_BUILTINS(PyObject *func) {
101-
return _PyFunction_CAST(func)->func_builtins;
102-
}
103-
#define PyFunction_GET_BUILTINS(func) PyFunction_GET_BUILTINS(_PyObject_CAST(func))
104-
105100
static inline PyObject* PyFunction_GET_MODULE(PyObject *func) {
106101
return _PyFunction_CAST(func)->func_module;
107102
}

Include/internal/pycore_code.h

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -565,57 +565,6 @@ extern int _Py_ClearUnusedTLBC(PyInterpreterState *interp);
565565
#endif
566566

567567

568-
typedef struct {
569-
int total;
570-
struct co_locals_counts {
571-
int total;
572-
struct {
573-
int total;
574-
int numposonly;
575-
int numposorkw;
576-
int numkwonly;
577-
int varargs;
578-
int varkwargs;
579-
} args;
580-
int numpure;
581-
struct {
582-
int total;
583-
// numargs does not contribute to locals.total.
584-
int numargs;
585-
int numothers;
586-
} cells;
587-
struct {
588-
int total;
589-
int numpure;
590-
int numcells;
591-
} hidden;
592-
} locals;
593-
int numfree; // nonlocal
594-
struct co_unbound_counts {
595-
int total;
596-
struct {
597-
int total;
598-
int numglobal;
599-
int numbuiltin;
600-
int numunknown;
601-
} globals;
602-
int numattrs;
603-
int numunknown;
604-
} unbound;
605-
} _PyCode_var_counts_t;
606-
607-
PyAPI_FUNC(void) _PyCode_GetVarCounts(
608-
PyCodeObject *,
609-
_PyCode_var_counts_t *);
610-
PyAPI_FUNC(int) _PyCode_SetUnboundVarCounts(
611-
PyThreadState *,
612-
PyCodeObject *,
613-
_PyCode_var_counts_t *,
614-
PyObject *globalnames,
615-
PyObject *attrnames,
616-
PyObject *globalsns,
617-
PyObject *builtinsns);
618-
619568
PyAPI_FUNC(int) _PyCode_ReturnsOnlyNone(PyCodeObject *);
620569

621570

Lib/test/test_code.py

Lines changed: 0 additions & 230 deletions
Original file line numberDiff line numberDiff line change
@@ -777,236 +777,6 @@ def test_local_kinds(self):
777777
kinds = _testinternalcapi.get_co_localskinds(func.__code__)
778778
self.assertEqual(kinds, expected)
779779

780-
@unittest.skipIf(_testinternalcapi is None, "missing _testinternalcapi")
781-
def test_var_counts(self):
782-
self.maxDiff = None
783-
def new_var_counts(*,
784-
posonly=0,
785-
posorkw=0,
786-
kwonly=0,
787-
varargs=0,
788-
varkwargs=0,
789-
purelocals=0,
790-
argcells=0,
791-
othercells=0,
792-
freevars=0,
793-
globalvars=0,
794-
attrs=0,
795-
unknown=0,
796-
):
797-
nargvars = posonly + posorkw + kwonly + varargs + varkwargs
798-
nlocals = nargvars + purelocals + othercells
799-
if isinstance(globalvars, int):
800-
globalvars = {
801-
'total': globalvars,
802-
'numglobal': 0,
803-
'numbuiltin': 0,
804-
'numunknown': globalvars,
805-
}
806-
else:
807-
g_numunknown = 0
808-
if isinstance(globalvars, dict):
809-
numglobal = globalvars['numglobal']
810-
numbuiltin = globalvars['numbuiltin']
811-
size = 2
812-
if 'numunknown' in globalvars:
813-
g_numunknown = globalvars['numunknown']
814-
size += 1
815-
assert len(globalvars) == size, globalvars
816-
else:
817-
assert not isinstance(globalvars, str), repr(globalvars)
818-
try:
819-
numglobal, numbuiltin = globalvars
820-
except ValueError:
821-
numglobal, numbuiltin, g_numunknown = globalvars
822-
globalvars = {
823-
'total': numglobal + numbuiltin + g_numunknown,
824-
'numglobal': numglobal,
825-
'numbuiltin': numbuiltin,
826-
'numunknown': g_numunknown,
827-
}
828-
unbound = globalvars['total'] + attrs + unknown
829-
return {
830-
'total': nlocals + freevars + unbound,
831-
'locals': {
832-
'total': nlocals,
833-
'args': {
834-
'total': nargvars,
835-
'numposonly': posonly,
836-
'numposorkw': posorkw,
837-
'numkwonly': kwonly,
838-
'varargs': varargs,
839-
'varkwargs': varkwargs,
840-
},
841-
'numpure': purelocals,
842-
'cells': {
843-
'total': argcells + othercells,
844-
'numargs': argcells,
845-
'numothers': othercells,
846-
},
847-
'hidden': {
848-
'total': 0,
849-
'numpure': 0,
850-
'numcells': 0,
851-
},
852-
},
853-
'numfree': freevars,
854-
'unbound': {
855-
'total': unbound,
856-
'globals': globalvars,
857-
'numattrs': attrs,
858-
'numunknown': unknown,
859-
},
860-
}
861-
862-
import test._code_definitions as defs
863-
funcs = {
864-
defs.spam_minimal: new_var_counts(),
865-
defs.spam_full: new_var_counts(
866-
posonly=2,
867-
posorkw=2,
868-
kwonly=2,
869-
varargs=1,
870-
varkwargs=1,
871-
purelocals=4,
872-
globalvars=3,
873-
attrs=1,
874-
),
875-
defs.spam: new_var_counts(
876-
posorkw=1,
877-
),
878-
defs.spam_N: new_var_counts(
879-
posorkw=1,
880-
purelocals=1,
881-
),
882-
defs.spam_C: new_var_counts(
883-
posorkw=1,
884-
purelocals=1,
885-
argcells=1,
886-
othercells=1,
887-
),
888-
defs.spam_NN: new_var_counts(
889-
posorkw=1,
890-
purelocals=1,
891-
),
892-
defs.spam_NC: new_var_counts(
893-
posorkw=1,
894-
purelocals=1,
895-
argcells=1,
896-
othercells=1,
897-
),
898-
defs.spam_CN: new_var_counts(
899-
posorkw=1,
900-
purelocals=1,
901-
argcells=1,
902-
othercells=1,
903-
),
904-
defs.spam_CC: new_var_counts(
905-
posorkw=1,
906-
purelocals=1,
907-
argcells=1,
908-
othercells=1,
909-
),
910-
defs.eggs_nested: new_var_counts(
911-
posorkw=1,
912-
),
913-
defs.eggs_closure: new_var_counts(
914-
posorkw=1,
915-
freevars=2,
916-
),
917-
defs.eggs_nested_N: new_var_counts(
918-
posorkw=1,
919-
purelocals=1,
920-
),
921-
defs.eggs_nested_C: new_var_counts(
922-
posorkw=1,
923-
purelocals=1,
924-
argcells=1,
925-
freevars=2,
926-
),
927-
defs.eggs_closure_N: new_var_counts(
928-
posorkw=1,
929-
purelocals=1,
930-
freevars=2,
931-
),
932-
defs.eggs_closure_C: new_var_counts(
933-
posorkw=1,
934-
purelocals=1,
935-
argcells=1,
936-
othercells=1,
937-
freevars=2,
938-
),
939-
defs.ham_nested: new_var_counts(
940-
posorkw=1,
941-
),
942-
defs.ham_closure: new_var_counts(
943-
posorkw=1,
944-
freevars=3,
945-
),
946-
defs.ham_C_nested: new_var_counts(
947-
posorkw=1,
948-
),
949-
defs.ham_C_closure: new_var_counts(
950-
posorkw=1,
951-
freevars=4,
952-
),
953-
}
954-
assert len(funcs) == len(defs.FUNCTIONS), (len(funcs), len(defs.FUNCTIONS))
955-
for func in defs.FUNCTIONS:
956-
with self.subTest(func):
957-
expected = funcs[func]
958-
counts = _testinternalcapi.get_code_var_counts(func.__code__)
959-
self.assertEqual(counts, expected)
960-
961-
def func_with_globals_and_builtins():
962-
mod1 = _testinternalcapi
963-
mod2 = dis
964-
mods = (mod1, mod2)
965-
checks = tuple(callable(m) for m in mods)
966-
return callable(mod2), tuple(mods), list(mods), checks
967-
968-
func = func_with_globals_and_builtins
969-
with self.subTest(f'{func} code'):
970-
expected = new_var_counts(
971-
purelocals=4,
972-
globalvars=5,
973-
)
974-
counts = _testinternalcapi.get_code_var_counts(func.__code__)
975-
self.assertEqual(counts, expected)
976-
977-
with self.subTest(f'{func} with own globals and builtins'):
978-
expected = new_var_counts(
979-
purelocals=4,
980-
globalvars=(2, 3),
981-
)
982-
counts = _testinternalcapi.get_code_var_counts(func)
983-
self.assertEqual(counts, expected)
984-
985-
with self.subTest(f'{func} without globals'):
986-
expected = new_var_counts(
987-
purelocals=4,
988-
globalvars=(0, 3, 2),
989-
)
990-
counts = _testinternalcapi.get_code_var_counts(func, globalsns={})
991-
self.assertEqual(counts, expected)
992-
993-
with self.subTest(f'{func} without both'):
994-
expected = new_var_counts(
995-
purelocals=4,
996-
globalvars=5,
997-
)
998-
counts = _testinternalcapi.get_code_var_counts(func, globalsns={},
999-
builtinsns={})
1000-
self.assertEqual(counts, expected)
1001-
1002-
with self.subTest(f'{func} without builtins'):
1003-
expected = new_var_counts(
1004-
purelocals=4,
1005-
globalvars=(2, 0, 3),
1006-
)
1007-
counts = _testinternalcapi.get_code_var_counts(func, builtinsns={})
1008-
self.assertEqual(counts, expected)
1009-
1010780

1011781
def isinterned(s):
1012782
return s is sys.intern(('_' + s + '_')[1:-1])

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy