changes after review

This commit is contained in:
ahgamut 2021-09-04 14:35:08 +05:30
parent 2da34acf82
commit 988d9067c1
9 changed files with 23 additions and 42 deletions

View file

@ -2,7 +2,6 @@
#define Py_COSMO_H #define Py_COSMO_H
#include "third_party/python/Include/object.h" #include "third_party/python/Include/object.h"
COSMOPOLITAN_C_START_ COSMOPOLITAN_C_START_
/* clang-format off */
PyMODINIT_FUNC PyInit_cosmo(void); PyMODINIT_FUNC PyInit_cosmo(void);

View file

@ -29,7 +29,6 @@ int _PyMem_SetupAllocators(const char *opt);
int _PyMem_PymallocEnabled(void); int _PyMem_PymallocEnabled(void);
#endif #endif
#ifdef USE_TRACEMALLOC
/* Identifier of an address space (domain) in tracemalloc */ /* Identifier of an address space (domain) in tracemalloc */
typedef unsigned int _PyTraceMalloc_domain_t; typedef unsigned int _PyTraceMalloc_domain_t;
@ -64,9 +63,9 @@ int _PyTraceMalloc_Untrack(
PyObject* _PyTraceMalloc_GetTraceback( PyObject* _PyTraceMalloc_GetTraceback(
_PyTraceMalloc_domain_t domain, _PyTraceMalloc_domain_t domain,
uintptr_t ptr); uintptr_t ptr);
#else #ifndef MODE_DBG
#define PyTraceMalloc_Track(domain, ptr, size) (-2) #define _PyTraceMalloc_Track(domain, ptr, size) (-2)
#define PyTraceMalloc_Untrack(domain, ptr) (-2) #define _PyTraceMalloc_Untrack(domain, ptr) (-2)
#define _PyTraceMalloc_GetTraceback(domain, ptr) (&_Py_NoneStruct) #define _PyTraceMalloc_GetTraceback(domain, ptr) (&_Py_NoneStruct)
#endif #endif

View file

@ -4112,7 +4112,7 @@ pyobject_malloc_without_gil(PyObject *self, PyObject *args)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
#ifdef USE_TRACEMALLOC
static PyObject * static PyObject *
tracemalloc_track(PyObject *self, PyObject *args) tracemalloc_track(PyObject *self, PyObject *args)
{ {
@ -4184,7 +4184,7 @@ tracemalloc_get_traceback(PyObject *self, PyObject *args)
return _PyTraceMalloc_GetTraceback(domain, (uintptr_t)ptr); return _PyTraceMalloc_GetTraceback(domain, (uintptr_t)ptr);
} }
#endif
static PyObject * static PyObject *
dict_get_version(PyObject *self, PyObject *args) dict_get_version(PyObject *self, PyObject *args)
{ {
@ -4539,11 +4539,9 @@ static PyMethodDef TestMethods[] = {
{"pymem_api_misuse", pymem_api_misuse, METH_NOARGS}, {"pymem_api_misuse", pymem_api_misuse, METH_NOARGS},
{"pymem_malloc_without_gil", pymem_malloc_without_gil, METH_NOARGS}, {"pymem_malloc_without_gil", pymem_malloc_without_gil, METH_NOARGS},
{"pyobject_malloc_without_gil", pyobject_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_track", tracemalloc_track, METH_VARARGS},
{"tracemalloc_untrack", tracemalloc_untrack, METH_VARARGS}, {"tracemalloc_untrack", tracemalloc_untrack, METH_VARARGS},
{"tracemalloc_get_traceback", tracemalloc_get_traceback, METH_VARARGS}, {"tracemalloc_get_traceback", tracemalloc_get_traceback, METH_VARARGS},
#endif
{"dict_get_version", dict_get_version, METH_VARARGS}, {"dict_get_version", dict_get_version, METH_VARARGS},
{"pyobject_fastcall", test_pyobject_fastcall, METH_VARARGS}, {"pyobject_fastcall", test_pyobject_fastcall, METH_VARARGS},
{"pyobject_fastcalldict", test_pyobject_fastcalldict, METH_VARARGS}, {"pyobject_fastcalldict", test_pyobject_fastcalldict, METH_VARARGS},

View file

@ -1794,7 +1794,7 @@ _PyTraceMalloc_Fini(void)
} }
int int
_PyTraceMalloc_Track(_PyTraceMalloc_domain_t domain, uintptr_t ptr, (_PyTraceMalloc_Track)(_PyTraceMalloc_domain_t domain, uintptr_t ptr,
size_t size) size_t size)
{ {
int res; int res;
@ -1823,7 +1823,7 @@ _PyTraceMalloc_Track(_PyTraceMalloc_domain_t domain, uintptr_t ptr,
int int
_PyTraceMalloc_Untrack(_PyTraceMalloc_domain_t domain, uintptr_t ptr) (_PyTraceMalloc_Untrack)(_PyTraceMalloc_domain_t domain, uintptr_t ptr)
{ {
if (!tracemalloc_config.tracing) { if (!tracemalloc_config.tracing) {
/* tracemalloc is not tracing: do nothing */ /* tracemalloc is not tracing: do nothing */
@ -1839,7 +1839,7 @@ _PyTraceMalloc_Untrack(_PyTraceMalloc_domain_t domain, uintptr_t ptr)
PyObject* PyObject*
_PyTraceMalloc_GetTraceback(_PyTraceMalloc_domain_t domain, uintptr_t ptr) (_PyTraceMalloc_GetTraceback)(_PyTraceMalloc_domain_t domain, uintptr_t ptr)
{ {
traceback_t *traceback; traceback_t *traceback;

View file

@ -48,7 +48,7 @@ PyObject* PyInit__locale(void);
PyObject* PyInit__io(void); PyObject* PyInit__io(void);
PyObject* PyInit_zipimport(void); PyObject* PyInit_zipimport(void);
PyObject* PyInit_faulthandler(void); PyObject* PyInit_faulthandler(void);
#ifdef USE_TRACEMALLOC #ifdef MODE_DBG
PyObject* PyInit__tracemalloc(void); PyObject* PyInit__tracemalloc(void);
#endif #endif
PyObject* PyInit__symtable(void); PyObject* PyInit__symtable(void);

View file

@ -2210,7 +2210,7 @@ PyObject_CallObject(PyObject *o, PyObject *a)
return PyEval_CallObjectWithKeywords(o, a, NULL); return PyEval_CallObjectWithKeywords(o, a, NULL);
} }
#ifdef USE_CHECKFUNCRESULT #ifdef MODE_DBG
PyObject* PyObject*
_Py_CheckFunctionResult(PyObject *func, PyObject *result, const char *where) _Py_CheckFunctionResult(PyObject *func, PyObject *result, const char *where)
{ {

View file

@ -16,7 +16,7 @@
#include "third_party/python/Include/pymem.h" #include "third_party/python/Include/pymem.h"
/* clang-format off */ /* clang-format off */
#ifdef USE_TRACEMALLOC #ifdef MODE_DBG
/* Defined in tracemalloc.c */ /* Defined in tracemalloc.c */
extern void _PyMem_DumpTraceback(int fd, const void *ptr); extern void _PyMem_DumpTraceback(int fd, const void *ptr);
#endif #endif

View file

@ -76,7 +76,7 @@ extern void PyLong_Fini(void);
extern int _PyFaulthandler_Init(void); extern int _PyFaulthandler_Init(void);
extern void _PyFaulthandler_Fini(void); extern void _PyFaulthandler_Fini(void);
extern void _PyHash_Fini(void); extern void _PyHash_Fini(void);
#ifdef USE_TRACEMALLOC #ifdef MODE_DBG
extern int _PyTraceMalloc_Init(void); extern int _PyTraceMalloc_Init(void);
extern int _PyTraceMalloc_Fini(void); extern int _PyTraceMalloc_Fini(void);
#endif #endif
@ -477,7 +477,7 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib)
if (install_sigs) if (install_sigs)
initsigs(); /* Signal handling stuff, including initintr() */ initsigs(); /* Signal handling stuff, including initintr() */
#ifdef USE_TRACEMALLOC #ifdef MODE_DBG
if (_PyTraceMalloc_Init() < 0) if (_PyTraceMalloc_Init() < 0)
Py_FatalError("Py_Initialize: can't initialize tracemalloc"); Py_FatalError("Py_Initialize: can't initialize tracemalloc");
#endif #endif
@ -669,7 +669,7 @@ Py_FinalizeEx(void)
_PyGC_CollectIfEnabled(); _PyGC_CollectIfEnabled();
#endif #endif
#ifdef USE_TRACEMALLOC #ifdef MODE_DBG
/* Disable tracemalloc after all Python objects have been destroyed, /* Disable tracemalloc after all Python objects have been destroyed,
so it is possible to use tracemalloc in objects destructor. */ so it is possible to use tracemalloc in objects destructor. */
_PyTraceMalloc_Fini(); _PyTraceMalloc_Fini();

View file

@ -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_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_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_HDRS = \
third_party/python/Include/yoink.h \ third_party/python/Include/yoink.h \
third_party/python/Include/object.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/Modules/unicodedata_db.inc
THIRD_PARTY_PYTHON_STAGE1_A_SRCS = \ THIRD_PARTY_PYTHON_STAGE1_A_SRCS = \
third_party/python/Modules/_tracemalloc.c \
third_party/python/Modules/faulthandler.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/fspath.c \
third_party/python/Modules/gcmodule.c \ third_party/python/Modules/gcmodule.c \
third_party/python/Modules/getbuildinfo.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/_stat.c \
third_party/python/Modules/_struct.c \ third_party/python/Modules/_struct.c \
third_party/python/Modules/_testcapimodule.c \ third_party/python/Modules/_testcapimodule.c \
third_party/python/Modules/_tracemalloc.c \
third_party/python/Modules/_weakref.c \ third_party/python/Modules/_weakref.c \
third_party/python/Modules/arraymodule.c \ third_party/python/Modules/arraymodule.c \
third_party/python/Modules/atexitmodule.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/tokenize.py \
third_party/python/Lib/trace.py \ third_party/python/Lib/trace.py \
third_party/python/Lib/traceback.py \ third_party/python/Lib/traceback.py \
third_party/python/Lib/tracemalloc.py \
third_party/python/Lib/tty.py \ third_party/python/Lib/tty.py \
third_party/python/Lib/types.py \ third_party/python/Lib/types.py \
third_party/python/Lib/typing.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_cmd_line.py \
third_party/python/Lib/test/test_bool.py \ third_party/python/Lib/test/test_bool.py \
third_party/python/Lib/test/test_urllib2_localnet.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/mapping_tests.py \
third_party/python/Lib/test/test_tempfile.py \ third_party/python/Lib/test/test_tempfile.py \
third_party/python/Lib/test/test_socketserver.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_nntplib.py \
third_party/python/Lib/test/test_uu.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 = \ THIRD_PARTY_PYTHON_STAGE1_A_DIRECTDEPS = \
LIBC_CALLS \ LIBC_CALLS \
LIBC_FMT \ LIBC_FMT \
@ -2328,7 +2310,10 @@ o/$(MODE)/third_party/python/Python/sysmodule.o: \
$(THIRD_PARTY_PYTHON_STAGE1_A_OBJS) \ $(THIRD_PARTY_PYTHON_STAGE1_A_OBJS) \
$(THIRD_PARTY_PYTHON_STAGE2_A_OBJS): \ $(THIRD_PARTY_PYTHON_STAGE2_A_OBJS): \
OVERRIDE_CPPFLAGS += \ OVERRIDE_CPPFLAGS += \
$(THIRD_PARTY_PYTHON_FLAGS) -DNDEBUG \
-DPy_BUILD_CORE \
-DPLATFORM='"cosmo"' \
-DMULTIARCH='"x86_64-cosmo"'
o/$(MODE)/third_party/python/Modules/getbuildinfo.o: \ o/$(MODE)/third_party/python/Modules/getbuildinfo.o: \
OVERRIDE_CFLAGS += \ OVERRIDE_CFLAGS += \