From 988d9067c1bc7b23afdd1dd3b29ffde5e3bce2e4 Mon Sep 17 00:00:00 2001 From: ahgamut <41098605+ahgamut@users.noreply.github.com> Date: Sat, 4 Sep 2021 14:35:08 +0530 Subject: [PATCH] changes after review --- third_party/python/Include/cosmo.h | 1 - third_party/python/Include/pymem.h | 7 ++--- third_party/python/Modules/_testcapimodule.c | 6 ++-- third_party/python/Modules/_tracemalloc.c | 6 ++-- third_party/python/Modules/config.c | 2 +- third_party/python/Objects/abstract.c | 2 +- third_party/python/Objects/obmalloc.c | 2 +- third_party/python/Python/pylifecycle.c | 6 ++-- third_party/python/python.mk | 33 ++++++-------------- 9 files changed, 23 insertions(+), 42 deletions(-) diff --git a/third_party/python/Include/cosmo.h b/third_party/python/Include/cosmo.h index 97214976d..9ea3f212e 100644 --- a/third_party/python/Include/cosmo.h +++ b/third_party/python/Include/cosmo.h @@ -2,7 +2,6 @@ #define Py_COSMO_H #include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ -/* clang-format off */ PyMODINIT_FUNC PyInit_cosmo(void); diff --git a/third_party/python/Include/pymem.h b/third_party/python/Include/pymem.h index 1d6cafd56..848d480ad 100644 --- a/third_party/python/Include/pymem.h +++ b/third_party/python/Include/pymem.h @@ -29,7 +29,6 @@ int _PyMem_SetupAllocators(const char *opt); int _PyMem_PymallocEnabled(void); #endif -#ifdef USE_TRACEMALLOC /* Identifier of an address space (domain) in tracemalloc */ typedef unsigned int _PyTraceMalloc_domain_t; @@ -64,9 +63,9 @@ int _PyTraceMalloc_Untrack( PyObject* _PyTraceMalloc_GetTraceback( _PyTraceMalloc_domain_t domain, uintptr_t ptr); -#else -#define PyTraceMalloc_Track(domain, ptr, size) (-2) -#define PyTraceMalloc_Untrack(domain, ptr) (-2) +#ifndef MODE_DBG +#define _PyTraceMalloc_Track(domain, ptr, size) (-2) +#define _PyTraceMalloc_Untrack(domain, ptr) (-2) #define _PyTraceMalloc_GetTraceback(domain, ptr) (&_Py_NoneStruct) #endif diff --git a/third_party/python/Modules/_testcapimodule.c b/third_party/python/Modules/_testcapimodule.c index 21ec90d38..9682f0edf 100644 --- a/third_party/python/Modules/_testcapimodule.c +++ b/third_party/python/Modules/_testcapimodule.c @@ -4112,7 +4112,7 @@ pyobject_malloc_without_gil(PyObject *self, PyObject *args) Py_RETURN_NONE; } -#ifdef USE_TRACEMALLOC + static PyObject * tracemalloc_track(PyObject *self, PyObject *args) { @@ -4184,7 +4184,7 @@ tracemalloc_get_traceback(PyObject *self, PyObject *args) return _PyTraceMalloc_GetTraceback(domain, (uintptr_t)ptr); } -#endif + static PyObject * dict_get_version(PyObject *self, PyObject *args) { @@ -4539,11 +4539,9 @@ static PyMethodDef TestMethods[] = { {"pymem_api_misuse", pymem_api_misuse, METH_NOARGS}, {"pymem_malloc_without_gil", pymem_malloc_without_gil, METH_NOARGS}, {"pyobject_malloc_without_gil", pyobject_malloc_without_gil, METH_NOARGS}, -#ifdef USE_TRACEMALLOC {"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}, diff --git a/third_party/python/Modules/_tracemalloc.c b/third_party/python/Modules/_tracemalloc.c index 6c8af64a2..8200a70ea 100644 --- a/third_party/python/Modules/_tracemalloc.c +++ b/third_party/python/Modules/_tracemalloc.c @@ -1794,7 +1794,7 @@ _PyTraceMalloc_Fini(void) } int -_PyTraceMalloc_Track(_PyTraceMalloc_domain_t domain, uintptr_t ptr, +(_PyTraceMalloc_Track)(_PyTraceMalloc_domain_t domain, uintptr_t ptr, size_t size) { int res; @@ -1823,7 +1823,7 @@ _PyTraceMalloc_Track(_PyTraceMalloc_domain_t domain, uintptr_t ptr, int -_PyTraceMalloc_Untrack(_PyTraceMalloc_domain_t domain, uintptr_t ptr) +(_PyTraceMalloc_Untrack)(_PyTraceMalloc_domain_t domain, uintptr_t ptr) { if (!tracemalloc_config.tracing) { /* tracemalloc is not tracing: do nothing */ @@ -1839,7 +1839,7 @@ _PyTraceMalloc_Untrack(_PyTraceMalloc_domain_t domain, uintptr_t ptr) PyObject* -_PyTraceMalloc_GetTraceback(_PyTraceMalloc_domain_t domain, uintptr_t ptr) +(_PyTraceMalloc_GetTraceback)(_PyTraceMalloc_domain_t domain, uintptr_t ptr) { traceback_t *traceback; diff --git a/third_party/python/Modules/config.c b/third_party/python/Modules/config.c index 2e198af20..1e63964fe 100644 --- a/third_party/python/Modules/config.c +++ b/third_party/python/Modules/config.c @@ -48,7 +48,7 @@ PyObject* PyInit__locale(void); PyObject* PyInit__io(void); PyObject* PyInit_zipimport(void); PyObject* PyInit_faulthandler(void); -#ifdef USE_TRACEMALLOC +#ifdef MODE_DBG PyObject* PyInit__tracemalloc(void); #endif PyObject* PyInit__symtable(void); diff --git a/third_party/python/Objects/abstract.c b/third_party/python/Objects/abstract.c index 4082112d1..248297746 100644 --- a/third_party/python/Objects/abstract.c +++ b/third_party/python/Objects/abstract.c @@ -2210,7 +2210,7 @@ PyObject_CallObject(PyObject *o, PyObject *a) return PyEval_CallObjectWithKeywords(o, a, NULL); } -#ifdef USE_CHECKFUNCRESULT +#ifdef MODE_DBG PyObject* _Py_CheckFunctionResult(PyObject *func, PyObject *result, const char *where) { diff --git a/third_party/python/Objects/obmalloc.c b/third_party/python/Objects/obmalloc.c index af84e9220..b3b7a6989 100644 --- a/third_party/python/Objects/obmalloc.c +++ b/third_party/python/Objects/obmalloc.c @@ -16,7 +16,7 @@ #include "third_party/python/Include/pymem.h" /* clang-format off */ -#ifdef USE_TRACEMALLOC +#ifdef MODE_DBG /* Defined in tracemalloc.c */ extern void _PyMem_DumpTraceback(int fd, const void *ptr); #endif diff --git a/third_party/python/Python/pylifecycle.c b/third_party/python/Python/pylifecycle.c index 2614965ca..6c7866f10 100644 --- a/third_party/python/Python/pylifecycle.c +++ b/third_party/python/Python/pylifecycle.c @@ -76,7 +76,7 @@ extern void PyLong_Fini(void); extern int _PyFaulthandler_Init(void); extern void _PyFaulthandler_Fini(void); extern void _PyHash_Fini(void); -#ifdef USE_TRACEMALLOC +#ifdef MODE_DBG extern int _PyTraceMalloc_Init(void); extern int _PyTraceMalloc_Fini(void); #endif @@ -477,7 +477,7 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib) if (install_sigs) initsigs(); /* Signal handling stuff, including initintr() */ -#ifdef USE_TRACEMALLOC +#ifdef MODE_DBG if (_PyTraceMalloc_Init() < 0) Py_FatalError("Py_Initialize: can't initialize tracemalloc"); #endif @@ -669,7 +669,7 @@ Py_FinalizeEx(void) _PyGC_CollectIfEnabled(); #endif -#ifdef USE_TRACEMALLOC +#ifdef MODE_DBG /* Disable tracemalloc after all Python objects have been destroyed, so it is possible to use tracemalloc in objects destructor. */ _PyTraceMalloc_Fini(); diff --git a/third_party/python/python.mk b/third_party/python/python.mk index f34aa696e..1ebd9099a 100644 --- a/third_party/python/python.mk +++ b/third_party/python/python.mk @@ -49,13 +49,6 @@ THIRD_PARTY_PYTHON_STDLIB_DIRS_OBJS = $(THIRD_PARTY_PYTHON_STDLIB_DIRS:%=o/$(MOD THIRD_PARTY_PYTHON_STDLIB_DATA_OBJS = $(THIRD_PARTY_PYTHON_STDLIB_DATA:%=o/$(MODE)/%.zip.o) THIRD_PARTY_PYTHON_STDLIB_PYCS = $(THIRD_PARTY_PYTHON_STDLIB_PYS:%=o/$(MODE)/%c) -THIRD_PARTY_PYTHON_FLAGS = \ - -DNDEBUG \ - -DPy_BUILD_CORE \ - -DPLATFORM='"cosmo"' \ - -DMULTIARCH='"x86_64-cosmo"' - - THIRD_PARTY_PYTHON_HDRS = \ third_party/python/Include/yoink.h \ third_party/python/Include/object.h \ @@ -315,8 +308,9 @@ THIRD_PARTY_PYTHON_INCS = \ third_party/python/Modules/unicodedata_db.inc THIRD_PARTY_PYTHON_STAGE1_A_SRCS = \ + third_party/python/Modules/_tracemalloc.c \ third_party/python/Modules/faulthandler.c \ - third_party/python/Objects/abstract.c \ + third_party/python/Objects/abstract.c \ third_party/python/Modules/fspath.c \ third_party/python/Modules/gcmodule.c \ third_party/python/Modules/getbuildinfo.c \ @@ -471,6 +465,7 @@ THIRD_PARTY_PYTHON_STAGE2_A_SRCS = \ third_party/python/Modules/_stat.c \ third_party/python/Modules/_struct.c \ third_party/python/Modules/_testcapimodule.c \ + third_party/python/Modules/_tracemalloc.c \ third_party/python/Modules/_weakref.c \ third_party/python/Modules/arraymodule.c \ third_party/python/Modules/atexitmodule.c \ @@ -1472,6 +1467,7 @@ THIRD_PARTY_PYTHON_STDLIB_PYS = \ third_party/python/Lib/tokenize.py \ third_party/python/Lib/trace.py \ third_party/python/Lib/traceback.py \ + third_party/python/Lib/tracemalloc.py \ third_party/python/Lib/tty.py \ third_party/python/Lib/types.py \ third_party/python/Lib/typing.py \ @@ -1822,6 +1818,7 @@ THIRD_PARTY_PYTHON_STDLIB_PYS = \ third_party/python/Lib/test/test_cmd_line.py \ third_party/python/Lib/test/test_bool.py \ third_party/python/Lib/test/test_urllib2_localnet.py \ + third_party/python/Lib/test/test_tracemalloc.py \ third_party/python/Lib/test/mapping_tests.py \ third_party/python/Lib/test/test_tempfile.py \ third_party/python/Lib/test/test_socketserver.py \ @@ -2166,21 +2163,6 @@ THIRD_PARTY_PYTHON_STDLIB_PYS = \ third_party/python/Lib/test/test_nntplib.py \ third_party/python/Lib/test/test_uu.py -ifeq ($(MODE), dbg) - THIRD_PARTY_PYTHON_FLAGS += \ - -DUSE_TRACEMALLOC \ - -DUSE_CHECKFUNCRESULT \ - -DUSE_BADINTERNALCALL - THIRD_PARTY_PYTHON_STAGE1_A_SRCS += \ - third_party/python/Modules/_tracemalloc.c - THIRD_PARTY_PYTHON_STAGE2_A_SRCS += \ - third_party/python/Modules/_tracemalloc.c - THIRD_PARTY_PYTHON_STDLIB_PYS += \ - third_party/python/Lib/tracemalloc.py \ - third_party/python/Lib/test/test_tracemalloc.py -endif - - THIRD_PARTY_PYTHON_STAGE1_A_DIRECTDEPS = \ LIBC_CALLS \ LIBC_FMT \ @@ -2328,7 +2310,10 @@ o/$(MODE)/third_party/python/Python/sysmodule.o: \ $(THIRD_PARTY_PYTHON_STAGE1_A_OBJS) \ $(THIRD_PARTY_PYTHON_STAGE2_A_OBJS): \ OVERRIDE_CPPFLAGS += \ - $(THIRD_PARTY_PYTHON_FLAGS) + -DNDEBUG \ + -DPy_BUILD_CORE \ + -DPLATFORM='"cosmo"' \ + -DMULTIARCH='"x86_64-cosmo"' o/$(MODE)/third_party/python/Modules/getbuildinfo.o: \ OVERRIDE_CFLAGS += \