Skip to content

Commit e2d8a50

Browse files
authored
bpo-45122: Remove PyCode_New from mypyc (#11067)
Guido plans to remove PyCode_New from CPython CAPI. See: https://bugs.python.org/issue45122 Fixes #11066
1 parent cc224ca commit e2d8a50

File tree

1 file changed

+4
-33
lines changed

1 file changed

+4
-33
lines changed

mypyc/lib-rt/exc_ops.c

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -189,38 +189,9 @@ void CPy_TypeError(const char *expected, PyObject *value) {
189189
}
190190
}
191191

192-
// These functions are basically exactly PyCode_NewEmpty and
193-
// _PyTraceback_Add which are available in all the versions we support.
194-
// We're continuing to use them because we'll probably optimize them later.
195-
static PyCodeObject *CPy_CreateCodeObject(const char *filename, const char *funcname, int line) {
196-
PyObject *filename_obj = PyUnicode_FromString(filename);
197-
PyObject *funcname_obj = PyUnicode_FromString(funcname);
198-
PyObject *empty_bytes = PyBytes_FromStringAndSize("", 0);
199-
PyObject *empty_tuple = PyTuple_New(0);
200-
PyCodeObject *code_obj = NULL;
201-
if (filename_obj == NULL || funcname_obj == NULL || empty_bytes == NULL
202-
|| empty_tuple == NULL) {
203-
goto Error;
204-
}
205-
code_obj = PyCode_New(0, 0, 0, 0, 0,
206-
empty_bytes,
207-
empty_tuple,
208-
empty_tuple,
209-
empty_tuple,
210-
empty_tuple,
211-
empty_tuple,
212-
filename_obj,
213-
funcname_obj,
214-
line,
215-
empty_bytes);
216-
Error:
217-
Py_XDECREF(empty_bytes);
218-
Py_XDECREF(empty_tuple);
219-
Py_XDECREF(filename_obj);
220-
Py_XDECREF(funcname_obj);
221-
return code_obj;
222-
}
223-
192+
// This function is basically exactly the same with _PyTraceback_Add
193+
// which is available in all the versions we support.
194+
// We're continuing to use this because we'll probably optimize this later.
224195
void CPy_AddTraceback(const char *filename, const char *funcname, int line, PyObject *globals) {
225196
PyObject *exc, *val, *tb;
226197
PyThreadState *thread_state = PyThreadState_GET();
@@ -233,7 +204,7 @@ void CPy_AddTraceback(const char *filename, const char *funcname, int line, PyOb
233204
// FS encoding, which could have a decoder in Python. We don't do
234205
// that so *that* doesn't apply to us.)
235206
PyErr_Fetch(&exc, &val, &tb);
236-
PyCodeObject *code_obj = CPy_CreateCodeObject(filename, funcname, line);
207+
PyCodeObject *code_obj = PyCode_NewEmpty(filename, funcname, line);
237208
if (code_obj == NULL) {
238209
goto error;
239210
}

0 commit comments

Comments
 (0)