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-100719: Remove redundantgi_code field from generator object.#100749

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
markshannon merged 10 commits intopython:mainfromfaster-cpython:trim-code-object-2
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
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
Add API function to access code object of generator.
  • Loading branch information
@markshannon
markshannon committedJan 4, 2023
commit3a9df11651c8d2cf5090f26f7e62bd32da6a9813
1 change: 1 addition & 0 deletionsInclude/cpython/genobject.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -44,6 +44,7 @@ PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(PyFrameObject *,
PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *);
PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self);
PyAPI_FUNC(PyCodeObject *) PyGen_GetCode(PyGenObject *gen);


/* --- PyCoroObject ------------------------------------------------------- */
Expand Down
5 changes: 5 additions & 0 deletionsLib/test/test_capi/test_misc.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1214,6 +1214,11 @@ def test_pendingcalls_non_threaded(self):
self.pendingcalls_submit(l, n)
self.pendingcalls_wait(l, n)

def test_gen_get_code(self):
def genf(): yield
gen = genf()
self.assertEqual(_testcapi.gen_get_code(gen), gen.gi_code)


class SubinterpreterTest(unittest.TestCase):

Expand Down
11 changes: 11 additions & 0 deletionsModules/_testcapimodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2943,6 +2943,16 @@ eval_get_func_desc(PyObject *self, PyObject *func)
return PyUnicode_FromString(PyEval_GetFuncDesc(func));
}

static PyObject *
gen_get_code(PyObject *self, PyObject *gen)
{
if (!PyGen_Check(gen)) {
PyErr_SetString(PyExc_TypeError, "argument must be a generator object");
return NULL;
}
return (PyObject *)PyGen_GetCode((PyGenObject *)gen);
}

static PyObject *
get_feature_macros(PyObject *self, PyObject *Py_UNUSED(args))
{
Expand DownExpand Up@@ -3346,6 +3356,7 @@ static PyMethodDef TestMethods[] = {
{"frame_getvarstring", test_frame_getvarstring, METH_VARARGS, NULL},
{"eval_get_func_name", eval_get_func_name, METH_O, NULL},
{"eval_get_func_desc", eval_get_func_desc, METH_O, NULL},
{"gen_get_code", gen_get_code, METH_O, NULL},
{"get_feature_macros", get_feature_macros, METH_NOARGS, NULL},
{"test_code_api", test_code_api, METH_NOARGS, NULL},
{"settrace_to_record", settrace_to_record, METH_O, NULL},
Expand Down
8 changes: 8 additions & 0 deletionsObjects/genobject.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,6 +31,14 @@ _PyGen_GetCode(PyGenObject *gen) {
return frame->f_code;
}

PyCodeObject *
PyGen_GetCode(PyGenObject *gen) {
assert(PyGen_Check(gen));
PyCodeObject *res = _PyGen_GetCode(gen);
Py_INCREF(res);
return res;
}

static inline int
exc_state_traverse(_PyErr_StackItem *exc_state, visitproc visit, void *arg)
{
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp