summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorEddie Elizondo <eelizondo@fb.com>2019-09-19 16:29:05 (GMT)
committerDino Viehland <dinoviehland@gmail.com>2019-09-19 16:29:05 (GMT)
commit3368f3c6ae4140a0883e19350e672fd09c9db616 (patch)
tree0b4477fdd89aefa2b9d17e6a16c3f172f32a5660 /Parser
parent079931d12223ec98cbf53185b90db48efa61f93f (diff)
downloadcpython-3368f3c6ae4140a0883e19350e672fd09c9db616.zip
cpython-3368f3c6ae4140a0883e19350e672fd09c9db616.tar.gz
cpython-3368f3c6ae4140a0883e19350e672fd09c9db616.tar.bz2
bpo-38140: Make dict and weakref offsets opaque for C heap types (#16076)
* Make dict and weakref offsets opaque for C heap types * Add news
Diffstat (limited to 'Parser')
-rwxr-xr-xParser/asdl_c.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index 0b72f9e..3a9d4e6 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -724,6 +724,11 @@ ast_type_reduce(PyObject *self, PyObject *unused)
return Py_BuildValue("O()", Py_TYPE(self));
}
+static PyMemberDef ast_type_members[] = {
+ {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY},
+ {NULL} /* Sentinel */
+};
+
static PyMethodDef ast_type_methods[] = {
{"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
{NULL}
@@ -740,6 +745,7 @@ static PyType_Slot AST_type_slots[] = {
{Py_tp_setattro, PyObject_GenericSetAttr},
{Py_tp_traverse, ast_traverse},
{Py_tp_clear, ast_clear},
+ {Py_tp_members, ast_type_members},
{Py_tp_methods, ast_type_methods},
{Py_tp_getset, ast_type_getsets},
{Py_tp_init, ast_type_init},
@@ -930,7 +936,6 @@ static int add_ast_fields(void)
self.emit("if (init_identifiers() < 0) return 0;", 1)
self.emit("state->AST_type = PyType_FromSpec(&AST_type_spec);", 1)
self.emit("if (!state->AST_type) return 0;", 1)
- self.emit("((PyTypeObject*)state->AST_type)->tp_dictoffset = offsetof(AST_object, dict);", 1)
self.emit("if (add_ast_fields() < 0) return 0;", 1)
for dfn in mod.dfns:
self.visit(dfn)
@@ -1372,6 +1377,7 @@ def main(srcfile, dump_module=False):
f.write('\n')
f.write('#include "Python.h"\n')
f.write('#include "%s-ast.h"\n' % mod.name)
+ f.write('#include "structmember.h"\n')
f.write('\n')
generate_module_def(f, mod)