diff options
author | Brett Cannon <brett@python.org> | 2016-09-07 18:16:41 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2016-09-07 18:16:41 (GMT) |
commit | 5c4de2863b217338deb9a0fcd20b202b8647b366 (patch) | |
tree | bba5ca1d16f518125a5d2bfb4fe32a362f5527d5 /Include | |
parent | a9296e7f3be4d6c22271b25c86467ff867c63bbb (diff) | |
download | cpython-5c4de2863b217338deb9a0fcd20b202b8647b366.zip cpython-5c4de2863b217338deb9a0fcd20b202b8647b366.tar.gz cpython-5c4de2863b217338deb9a0fcd20b202b8647b366.tar.bz2 |
Add the co_extra field and accompanying APIs to code objects.
This completes PEP 523.
Diffstat (limited to 'Include')
-rw-r--r-- | Include/ceval.h | 4 | ||||
-rw-r--r-- | Include/code.h | 20 | ||||
-rw-r--r-- | Include/pystate.h | 7 |
3 files changed, 30 insertions, 1 deletions
diff --git a/Include/ceval.h b/Include/ceval.h index 7607f75..81f4bbf 100644 --- a/Include/ceval.h +++ b/Include/ceval.h @@ -187,6 +187,10 @@ PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds); PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void); #endif +#ifndef Py_LIMITED_API +PyAPI_FUNC(Py_ssize_t) _PyEval_RequestCodeExtraIndex(freefunc); +#endif + #define Py_BEGIN_ALLOW_THREADS { \ PyThreadState *_save; \ _save = PyEval_SaveThread(); diff --git a/Include/code.h b/Include/code.h index a300ead..a054a92 100644 --- a/Include/code.h +++ b/Include/code.h @@ -7,6 +7,14 @@ extern "C" { #endif + +/* Holder for co_extra information */ +typedef struct { + Py_ssize_t ce_size; + void **ce_extras; +} _PyCodeObjectExtra; + + /* Bytecode object */ typedef struct { PyObject_HEAD @@ -15,6 +23,7 @@ typedef struct { int co_nlocals; /* #local variables */ int co_stacksize; /* #entries needed for evaluation stack */ int co_flags; /* CO_..., see below */ + int co_firstlineno; /* first source line number */ PyObject *co_code; /* instruction opcodes */ PyObject *co_consts; /* list (constants used) */ PyObject *co_names; /* list of strings (names used) */ @@ -30,11 +39,12 @@ typedef struct { unsigned char *co_cell2arg; /* Maps cell vars which are arguments. */ PyObject *co_filename; /* unicode (where it was loaded from) */ PyObject *co_name; /* unicode (name, for reference) */ - int co_firstlineno; /* first source line number */ PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) See Objects/lnotab_notes.txt for details. */ void *co_zombieframe; /* for optimization only (see frameobject.c) */ PyObject *co_weakreflist; /* to support weakrefs to code objects */ + /* Scratch space for extra data relating to the code object */ + _PyCodeObjectExtra *co_extra; } PyCodeObject; /* Masks for co_flags above */ @@ -128,6 +138,14 @@ PyAPI_FUNC(PyObject*) _PyCode_ConstantKey(PyObject *obj); PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, PyObject *lnotab); + +#ifndef Py_LIMITED_API +PyAPI_FUNC(int) _PyCode_GetExtra(PyObject *code, Py_ssize_t index, + void **extra); +PyAPI_FUNC(int) _PyCode_SetExtra(PyObject *code, Py_ssize_t index, + void *extra); +#endif + #ifdef __cplusplus } #endif diff --git a/Include/pystate.h b/Include/pystate.h index 5a06773..5ab5c98 100644 --- a/Include/pystate.h +++ b/Include/pystate.h @@ -8,6 +8,10 @@ extern "C" { #endif +/* This limitation is for performance and simplicity. If needed it can be +removed (with effort). */ +#define MAX_CO_EXTRA_USERS 255 + /* State shared between threads */ struct _ts; /* Forward */ @@ -141,6 +145,9 @@ typedef struct _ts { PyObject *coroutine_wrapper; int in_coroutine_wrapper; + Py_ssize_t co_extra_user_count; + freefunc co_extra_freefuncs[MAX_CO_EXTRA_USERS]; + /* XXX signal handlers should also be here */ } PyThreadState; |