Skip to content

Commit

Permalink
[build] Edit CPython source to use the new extracted definitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Chu committed Oct 24, 2018
1 parent cee9285 commit d7fd2eb
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Python-2.7.13/Modules/cStringIO.c
Expand Up @@ -508,6 +508,9 @@ O_writelines(Oobject *self, PyObject *args) {

Py_RETURN_NONE;
}
#ifdef OVM_MAIN
#include "Python-2.7.13/Modules/cStringIO.c/O_methods.def"
#else
static struct PyMethodDef O_methods[] = {
/* Common methods: */
{"flush", (PyCFunction)IO_flush, METH_NOARGS, IO_flush__doc__},
Expand All @@ -527,6 +530,7 @@ static struct PyMethodDef O_methods[] = {
{"writelines", (PyCFunction)O_writelines, METH_O, O_writelines__doc__},
{NULL, NULL} /* sentinel */
};
#endif

static PyMemberDef O_memberlist[] = {
{"softspace", T_INT, offsetof(Oobject, softspace), 0,
Expand Down Expand Up @@ -615,6 +619,9 @@ I_close(Iobject *self, PyObject *unused) {
return Py_None;
}

#ifdef OVM_MAIN
#include "Python-2.7.13/Modules/cStringIO.c/I_methods.def"
#else
static struct PyMethodDef I_methods[] = {
/* Common methods: */
{"flush", (PyCFunction)IO_flush, METH_NOARGS, IO_flush__doc__},
Expand All @@ -632,6 +639,7 @@ static struct PyMethodDef I_methods[] = {
{"close", (PyCFunction)I_close, METH_NOARGS, O_close__doc__},
{NULL, NULL}
};
#endif

static void
I_dealloc(Iobject *self) {
Expand Down Expand Up @@ -724,11 +732,15 @@ IO_StringIO(PyObject *self, PyObject *args) {

/* List of methods defined in the module */

#ifdef OVM_MAIN
#include "Python-2.7.13/Modules/cStringIO.c/IO_methods.def"
#else
static struct PyMethodDef IO_methods[] = {
{"StringIO", (PyCFunction)IO_StringIO,
METH_VARARGS, IO_StringIO__doc__},
{NULL, NULL} /* sentinel */
};
#endif


/* Initialization function for the module (*must* be called initcStringIO) */
Expand Down
4 changes: 4 additions & 0 deletions Python-2.7.13/Modules/readline.c
Expand Up @@ -666,6 +666,9 @@ contents of the line buffer.");

/* Table of functions exported by the module */

#ifdef OVM_MAIN
#include "Python-2.7.13/Modules/readline.c/readline_methods.def"
#else
static struct PyMethodDef readline_methods[] = {
{"parse_and_bind", parse_and_bind, METH_VARARGS, doc_parse_and_bind},
{"get_line_buffer", get_line_buffer, METH_NOARGS, doc_get_line_buffer},
Expand Down Expand Up @@ -712,6 +715,7 @@ static struct PyMethodDef readline_methods[] = {
#endif
{0, 0}
};
#endif


/* C function to call the Python hooks. */
Expand Down
4 changes: 4 additions & 0 deletions Python-2.7.13/Modules/resource.c
Expand Up @@ -230,13 +230,17 @@ resource_getpagesize(PyObject *self, PyObject *unused)

/* List of functions */

#ifdef OVM_MAIN
#include "Python-2.7.13/Modules/resource.c/resource_methods.def"
#else
static struct PyMethodDef resource_methods[] = {
{"getrusage", resource_getrusage, METH_VARARGS},
{"getrlimit", resource_getrlimit, METH_VARARGS},
{"setrlimit", resource_setrlimit, METH_VARARGS},
{"getpagesize", resource_getpagesize, METH_NOARGS},
{NULL, NULL} /* sentinel */
};
#endif


/* Module initialization */
Expand Down
12 changes: 12 additions & 0 deletions Python-2.7.13/Objects/typeobject.c
Expand Up @@ -2758,6 +2758,9 @@ type_subclasses(PyTypeObject *type, PyObject *args_ignored)
return list;
}

#ifdef OVM_MAIN
#include "Python-2.7.13/Objects/typeobject.c/type_methods.def"
#else
#ifdef OVM_MAIN
#include "Python-2.7.13/Objects/typeobject.c/type_methods.def"
#else
Expand All @@ -2773,6 +2776,7 @@ static PyMethodDef type_methods[] = {
{0}
};
#endif
#endif

PyDoc_STRVAR(type_doc,
"type(object) -> the object's type\n"
Expand Down Expand Up @@ -3610,6 +3614,9 @@ object_sizeof(PyObject *self, PyObject *args)
return PyInt_FromSsize_t(res);
}

#ifdef OVM_MAIN
#include "Python-2.7.13/Objects/typeobject.c/object_methods.def"
#else
#ifdef OVM_MAIN
#include "Python-2.7.13/Objects/typeobject.c/object_methods.def"
#else
Expand All @@ -3627,6 +3634,7 @@ static PyMethodDef object_methods[] = {
{0}
};
#endif
#endif


PyTypeObject PyBaseObject_Type = {
Expand Down Expand Up @@ -4938,12 +4946,16 @@ tp_new_wrapper(PyObject *self, PyObject *args, PyObject *kwds)
return res;
}

#ifdef OVM_MAIN
#include "Python-2.7.13/Objects/typeobject.c/tp_new_methoddef.def"
#else
static struct PyMethodDef tp_new_methoddef[] = {
{"__new__", (PyCFunction)tp_new_wrapper, METH_VARARGS|METH_KEYWORDS,
PyDoc_STR("T.__new__(S, ...) -> "
"a new object with type S, a subtype of T")},
{0}
};
#endif

static int
add_tp_new_wrapper(PyTypeObject *type)
Expand Down
7 changes: 6 additions & 1 deletion build/cpython-defs.sh
Expand Up @@ -194,7 +194,12 @@ edit-file() {
edit-all() {
# Reversed so that edits to the same file work! We are always inserting
# lines.
tac $BASE_DIR/method-edit-list.txt | xargs -n 4 -- $0 edit-file
#tac $BASE_DIR/method-edit-list.txt | xargs -n 4 -- $0 edit-file

# One-off editing
grep typeobject.c $BASE_DIR/method-edit-list.txt \
| tac | xargs -n 4 -- $0 edit-file

}

extract-types() {
Expand Down

0 comments on commit d7fd2eb

Please sign in to comment.