From 7cbba2deb3fc49bd66e11b34f8e210371bac5913 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Wed, 7 Sep 2016 11:16:41 -0700 Subject: Add the co_extra field and accompanying APIs to code objects. This completes PEP 523. --- Include/code.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'Include/code.h') diff --git a/Include/code.h b/Include/code.h index a300ead5ec..a054a92261 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 -- cgit v1.2.1 From dc3c1c358987438ec626fb5ac60a36715ee8a1be Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Wed, 7 Sep 2016 14:30:39 -0700 Subject: Make PyCodeObject.co_extra even more private to force users through the proper API. --- Include/code.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'Include/code.h') diff --git a/Include/code.h b/Include/code.h index a054a92261..b39d6bd511 100644 --- a/Include/code.h +++ b/Include/code.h @@ -7,14 +7,6 @@ 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 @@ -43,8 +35,10 @@ typedef struct { 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; + /* Scratch space for extra data relating to the code object.__icc_nan + Type is a void* to keep the format private in codeobject.c to force + people to go through the proper APIs. */ + void *co_extra; } PyCodeObject; /* Masks for co_flags above */ -- cgit v1.2.1 From 17668cfa5e0e6f50376cc233d9b063b908a19845 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Thu, 8 Sep 2016 22:01:51 -0700 Subject: Issue #28003: Implement PEP 525 -- Asynchronous Generators. --- Include/code.h | 1 + 1 file changed, 1 insertion(+) (limited to 'Include/code.h') diff --git a/Include/code.h b/Include/code.h index b39d6bd511..9823f10d4e 100644 --- a/Include/code.h +++ b/Include/code.h @@ -59,6 +59,7 @@ typedef struct { ``async def`` keywords) */ #define CO_COROUTINE 0x0080 #define CO_ITERABLE_COROUTINE 0x0100 +#define CO_ASYNC_GENERATOR 0x0200 /* These are no longer used. */ #if 0 -- cgit v1.2.1 From 2fdfdf47618ed421642a743b67d2616c7dae138e Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 11 Sep 2016 13:48:15 +0300 Subject: Issue #27129: Replaced wordcode related magic constants with macros. --- Include/code.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Include/code.h') diff --git a/Include/code.h b/Include/code.h index 9823f10d4e..061902911d 100644 --- a/Include/code.h +++ b/Include/code.h @@ -7,6 +7,16 @@ extern "C" { #endif +typedef uint16_t _Py_CODEUNIT; + +#ifdef WORDS_BIGENDIAN +# define _Py_OPCODE(word) ((word) >> 8) +# define _Py_OPARG(word) ((word) & 255) +#else +# define _Py_OPCODE(word) ((word) & 255) +# define _Py_OPARG(word) ((word) >> 8) +#endif + /* Bytecode object */ typedef struct { PyObject_HEAD -- cgit v1.2.1 From 4c857a4c95e1f254e20f8b857268064700be8cc6 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 21 Nov 2016 14:24:32 -0800 Subject: Issue 28751: Fix comments in code.h. (Contributed by Ned Batchelder). --- Include/code.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'Include/code.h') diff --git a/Include/code.h b/Include/code.h index 061902911d..c5fce3c963 100644 --- a/Include/code.h +++ b/Include/code.h @@ -32,9 +32,8 @@ typedef struct { PyObject *co_varnames; /* tuple of strings (local variable names) */ PyObject *co_freevars; /* tuple of strings (free variable names) */ PyObject *co_cellvars; /* tuple of strings (cell variable names) */ - /* The rest aren't used in either hash or comparisons, except for - co_name (used in both) and co_firstlineno (used only in - comparisons). This is done to preserve the name and line number + /* The rest aren't used in either hash or comparisons, except for co_name, + used in both. This is done to preserve the name and line number for tracebacks and debuggers; otherwise, constant de-duplication would collapse identical functions/lambdas defined on different lines. */ @@ -45,7 +44,7 @@ typedef struct { 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.__icc_nan + /* Scratch space for extra data relating to the code object. Type is a void* to keep the format private in codeobject.c to force people to go through the proper APIs. */ void *co_extra; -- cgit v1.2.1