summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-04-21 15:10:37 (GMT)
committerGitHub <noreply@github.com>2022-04-21 15:10:37 (GMT)
commit944fffee8916cb94321fa33cd3a43f4108717746 (patch)
treef88202dd13021ad5cf4b260ecf05ebab6015a5f6 /Include
parent2a5f171759a31597032cfe52646929e6f8727243 (diff)
downloadcpython-944fffee8916cb94321fa33cd3a43f4108717746.zip
cpython-944fffee8916cb94321fa33cd3a43f4108717746.tar.gz
cpython-944fffee8916cb94321fa33cd3a43f4108717746.tar.bz2
GH-88116: Use a compact format to represent end line and column offsets. (GH-91666)
* Stores all location info in linetable to conform to PEP 626. * Remove column table from code objects. * Remove end-line table from code objects. * Document new location table format
Diffstat (limited to 'Include')
-rw-r--r--Include/cpython/code.h32
-rw-r--r--Include/internal/pycore_code.h49
2 files changed, 54 insertions, 27 deletions
diff --git a/Include/cpython/code.h b/Include/cpython/code.h
index 6dc2290..be3b10b 100644
--- a/Include/cpython/code.h
+++ b/Include/cpython/code.h
@@ -86,15 +86,7 @@ typedef uint16_t _Py_CODEUNIT;
PyObject *co_filename; /* unicode (where it was loaded from) */ \
PyObject *co_name; /* unicode (name, for reference) */ \
PyObject *co_qualname; /* unicode (qualname, for reference) */ \
- PyObject *co_linetable; /* bytes (encoding addr<->lineno mapping) \
- See Objects/lnotab_notes.txt for details. \
- */ \
- PyObject *co_endlinetable; /* bytes object that holds end lineno for \
- instructions separated across different \
- lines */ \
- PyObject *co_columntable; /* bytes object that holds start/end column \
- offset each instruction */ \
- \
+ PyObject *co_linetable; /* bytes object that holds location info */ \
PyObject *co_weakreflist; /* to support weakrefs to code objects */ \
/* Scratch space for extra data relating to the code object. \
Type is a void* to keep the format private in codeobject.c to force \
@@ -153,13 +145,13 @@ PyAPI_FUNC(PyCodeObject *) PyCode_New(
int, int, int, int, int, PyObject *, PyObject *,
PyObject *, PyObject *, PyObject *, PyObject *,
PyObject *, PyObject *, PyObject *, int, PyObject *,
- PyObject *, PyObject *, PyObject *);
+ PyObject *);
PyAPI_FUNC(PyCodeObject *) PyCode_NewWithPosOnlyArgs(
int, int, int, int, int, int, PyObject *, PyObject *,
PyObject *, PyObject *, PyObject *, PyObject *,
PyObject *, PyObject *, PyObject *, int, PyObject *,
- PyObject *, PyObject *, PyObject *);
+ PyObject *);
/* same as struct above */
/* Creates a new empty code object with the specified source location. */
@@ -176,8 +168,8 @@ PyAPI_FUNC(int) PyCode_Addr2Location(PyCodeObject *, int, int *, int *, int *, i
/* for internal use only */
struct _opaque {
int computed_line;
- const char *lo_next;
- const char *limit;
+ const uint8_t *lo_next;
+ const uint8_t *limit;
};
typedef struct _line_offsets {
@@ -210,6 +202,20 @@ PyAPI_FUNC(int) _PyCode_GetExtra(PyObject *code, Py_ssize_t index,
PyAPI_FUNC(int) _PyCode_SetExtra(PyObject *code, Py_ssize_t index,
void *extra);
+
+typedef enum _PyCodeLocationInfoKind {
+ /* short forms are 0 to 9 */
+ PY_CODE_LOCATION_INFO_SHORT0 = 0,
+ /* one lineforms are 10 to 12 */
+ PY_CODE_LOCATION_INFO_ONE_LINE0 = 10,
+ PY_CODE_LOCATION_INFO_ONE_LINE1 = 11,
+ PY_CODE_LOCATION_INFO_ONE_LINE2 = 12,
+
+ PY_CODE_LOCATION_INFO_NO_COLUMNS = 13,
+ PY_CODE_LOCATION_INFO_LONG = 14,
+ PY_CODE_LOCATION_INFO_NONE = 15
+} _PyCodeLocationInfoKind;
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h
index 8c868bc..3059db4 100644
--- a/Include/internal/pycore_code.h
+++ b/Include/internal/pycore_code.h
@@ -176,8 +176,6 @@ struct _PyCodeConstructor {
PyObject *code;
int firstlineno;
PyObject *linetable;
- PyObject *endlinetable;
- PyObject *columntable;
/* used by the code */
PyObject *consts;
@@ -221,21 +219,10 @@ extern PyObject* _PyCode_GetCellvars(PyCodeObject *);
extern PyObject* _PyCode_GetFreevars(PyCodeObject *);
extern PyObject* _PyCode_GetCode(PyCodeObject *);
-/* Return the ending source code line number from a bytecode index. */
-extern int _PyCode_Addr2EndLine(PyCodeObject *, int);
-
-/* Return the ending source code line number from a bytecode index. */
-extern int _PyCode_Addr2EndLine(PyCodeObject *, int);
-/* Return the starting source code column offset from a bytecode index. */
-extern int _PyCode_Addr2Offset(PyCodeObject *, int);
-/* Return the ending source code column offset from a bytecode index. */
-extern int _PyCode_Addr2EndOffset(PyCodeObject *, int);
-
/** API for initializing the line number tables. */
extern int _PyCode_InitAddressRange(PyCodeObject* co, PyCodeAddressRange *bounds);
-extern int _PyCode_InitEndAddressRange(PyCodeObject* co, PyCodeAddressRange* bounds);
-/** Out of process API for initializing the line number table. */
+/** Out of process API for initializing the location table. */
extern void _PyLineTable_InitAddressRange(
const char *linetable,
Py_ssize_t length,
@@ -445,6 +432,40 @@ read_obj(uint16_t *p)
return (PyObject *)val;
}
+static inline int
+write_varint(uint8_t *ptr, unsigned int val)
+{
+ int written = 1;
+ while (val >= 64) {
+ *ptr++ = 64 | (val & 63);
+ val >>= 6;
+ written++;
+ }
+ *ptr = val;
+ return written;
+}
+
+static inline int
+write_signed_varint(uint8_t *ptr, int val)
+{
+ if (val < 0) {
+ val = ((-val)<<1) | 1;
+ }
+ else {
+ val = val << 1;
+ }
+ return write_varint(ptr, val);
+}
+
+static inline int
+write_location_entry_start(uint8_t *ptr, int code, int length)
+{
+ assert((code & 15) == code);
+ *ptr = 128 | (code << 3) | (length - 1);
+ return 1;
+}
+
+
#ifdef __cplusplus
}
#endif