Fix Pyston speedups (#281)

We remove (i.e. hide behind a debug ifdef) the recursion checking methods,
and the memory hooks and memory allocator methods. ASAN mode has no
PYMALLOC, so we need a macro. Fix build break with des.c stack allocation.
This commit is contained in:
Gautham 2021-10-02 13:58:51 +05:30 committed by GitHub
parent 2fe8571010
commit 57f0eed382
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 260 additions and 63 deletions

View file

@ -3488,6 +3488,7 @@ test_pymem_alloc0(PyObject *self)
Py_RETURN_NONE;
}
#if IsModeDbg()
typedef struct {
PyMemAllocatorEx alloc;
@ -3780,6 +3781,7 @@ remove_mem_hooks(PyObject *self)
fm_remove_hooks();
Py_RETURN_NONE;
}
#endif
PyDoc_STRVAR(docstring_empty,
""
@ -4234,6 +4236,7 @@ test_PyTime_AsMicroseconds(PyObject *self, PyObject *args)
return _PyTime_AsNanosecondsObject(ms);
}
#if IsModeDbg()
static PyObject*
get_recursion_depth(PyObject *self, PyObject *args)
{
@ -4242,6 +4245,7 @@ get_recursion_depth(PyObject *self, PyObject *args)
/* subtract one to ignore the frame of the get_recursion_depth() call */
return PyLong_FromLong(tstate->recursion_depth - 1);
}
#endif
static PyObject*
pymem_buffer_overflow(PyObject *self, PyObject *args)
@ -4656,6 +4660,7 @@ static PyMethodDef TestMethods[] = {
{"create_cfunction", create_cfunction, METH_NOARGS},
{"test_pymem_alloc0",
(PyCFunction)test_pymem_alloc0, METH_NOARGS},
#if IsModeDbg()
{"test_pymem_setrawallocators",
(PyCFunction)test_pymem_setrawallocators, METH_NOARGS},
{"test_pymem_setallocators",
@ -4666,6 +4671,7 @@ static PyMethodDef TestMethods[] = {
PyDoc_STR("set_nomemory(start:int, stop:int = 0)")},
{"remove_mem_hooks", (PyCFunction)remove_mem_hooks, METH_NOARGS,
PyDoc_STR("Remove memory hooks.")},
#endif
{"no_docstring",
(PyCFunction)test_with_docstring, METH_NOARGS},
{"docstring_empty",
@ -4723,6 +4729,7 @@ static PyMethodDef TestMethods[] = {
#endif
{"PyTime_AsMilliseconds", test_PyTime_AsMilliseconds, METH_VARARGS},
{"PyTime_AsMicroseconds", test_PyTime_AsMicroseconds, METH_VARARGS},
#if IsModeDbg()
{"get_recursion_depth", get_recursion_depth, METH_NOARGS},
{"pymem_buffer_overflow", pymem_buffer_overflow, METH_NOARGS},
{"pymem_api_misuse", pymem_api_misuse, METH_NOARGS},
@ -4731,6 +4738,7 @@ static PyMethodDef TestMethods[] = {
{"tracemalloc_track", tracemalloc_track, METH_VARARGS},
{"tracemalloc_untrack", tracemalloc_untrack, METH_VARARGS},
{"tracemalloc_get_traceback", tracemalloc_get_traceback, METH_VARARGS},
#endif
{"dict_get_version", dict_get_version, METH_VARARGS},
{"pyobject_fastcall", test_pyobject_fastcall, METH_VARARGS},
{"pyobject_fastcalldict", test_pyobject_fastcalldict, METH_VARARGS},

View file

@ -41,6 +41,7 @@ PYTHON_PROVIDE("_tracemalloc.is_tracing");
PYTHON_PROVIDE("_tracemalloc.start");
PYTHON_PROVIDE("_tracemalloc.stop");
#if IsModeDbg()
/* Trace memory blocks allocated by PyMem_RawMalloc() */
#define TRACE_RAW_MALLOC
@ -1686,30 +1687,6 @@ static PyMethodDef module_methods[] = {
PyDoc_STRVAR(module_doc,
"Debug module to trace memory blocks allocated by Python.");
static struct PyModuleDef module_def = {
PyModuleDef_HEAD_INIT,
"_tracemalloc",
module_doc,
0, /* non-negative size to be able to unload the module */
module_methods,
NULL,
};
PyMODINIT_FUNC
PyInit__tracemalloc(void)
{
PyObject *m;
m = PyModule_Create(&module_def);
if (m == NULL)
return NULL;
if (tracemalloc_init() < 0)
return NULL;
return m;
}
static int
parse_sys_xoptions(PyObject *value)
{
@ -1862,6 +1839,41 @@ PyObject*
return traceback_to_pyobject(traceback, NULL);
}
#endif
static struct PyModuleDef module_def = {
PyModuleDef_HEAD_INIT,
"_tracemalloc",
#ifdef USETRACEMALLOC
module_doc,
#else
NULL,
#endif
0, /* non-negative size to be able to unload the module */
#ifdef USETRACEMALLOC
module_methods,
#else
NULL,
#endif
NULL,
};
PyMODINIT_FUNC
PyInit__tracemalloc(void)
{
PyObject *m;
m = PyModule_Create(&module_def);
if (m == NULL)
return NULL;
#ifdef USETRACEMALLOC
if (tracemalloc_init() < 0)
return NULL;
#endif
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__tracemalloc = {
"_tracemalloc",

View file

@ -424,12 +424,14 @@ Py_Main(int argc, wchar_t **argv)
}
}
#if IsModeDbg()
opt = Py_GETENV("PYTHONMALLOC");
if (_PyMem_SetupAllocators(opt) < 0) {
fprintf(stderr,
"Error in PYTHONMALLOC: unknown allocator \"%s\"!\n", opt);
exit(1);
}
#endif
_PyRandom_Init();