diff options
Diffstat (limited to 'Modules/_lsprof.c')
-rw-r--r-- | Modules/_lsprof.c | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index 4162be8..0137d95 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -36,12 +36,8 @@ hpTimerUnit(void) #error "This module requires gettimeofday() on non-Windows platforms!" #endif -#if (defined(PYOS_OS2) && defined(PYCC_GCC)) -#include <sys/time.h> -#else #include <sys/resource.h> #include <sys/times.h> -#endif static PY_LONG_LONG hpTimer(void) @@ -227,7 +223,7 @@ static ProfilerEntry* newProfilerEntry(ProfilerObject *pObj, void *key, PyObject *userObj) { ProfilerEntry *self; - self = (ProfilerEntry*) malloc(sizeof(ProfilerEntry)); + self = (ProfilerEntry*) PyMem_Malloc(sizeof(ProfilerEntry)); if (self == NULL) { pObj->flags |= POF_NOMEMORY; return NULL; @@ -235,7 +231,7 @@ newProfilerEntry(ProfilerObject *pObj, void *key, PyObject *userObj) userObj = normalizeUserObj(userObj); if (userObj == NULL) { PyErr_Clear(); - free(self); + PyMem_Free(self); pObj->flags |= POF_NOMEMORY; return NULL; } @@ -268,7 +264,7 @@ static ProfilerSubEntry * newSubEntry(ProfilerObject *pObj, ProfilerEntry *caller, ProfilerEntry* entry) { ProfilerSubEntry *self; - self = (ProfilerSubEntry*) malloc(sizeof(ProfilerSubEntry)); + self = (ProfilerSubEntry*) PyMem_Malloc(sizeof(ProfilerSubEntry)); if (self == NULL) { pObj->flags |= POF_NOMEMORY; return NULL; @@ -286,7 +282,7 @@ newSubEntry(ProfilerObject *pObj, ProfilerEntry *caller, ProfilerEntry* entry) static int freeSubEntry(rotating_node_t *header, void *arg) { ProfilerSubEntry *subentry = (ProfilerSubEntry*) header; - free(subentry); + PyMem_Free(subentry); return 0; } @@ -295,7 +291,7 @@ static int freeEntry(rotating_node_t *header, void *arg) ProfilerEntry *entry = (ProfilerEntry*) header; RotatingTree_Enum(entry->calls, freeSubEntry, NULL); Py_DECREF(entry->userObj); - free(entry); + PyMem_Free(entry); return 0; } @@ -305,13 +301,13 @@ static void clearEntries(ProfilerObject *pObj) pObj->profilerEntries = EMPTY_ROTATING_TREE; /* release the memory hold by the ProfilerContexts */ if (pObj->currentProfilerContext) { - free(pObj->currentProfilerContext); + PyMem_Free(pObj->currentProfilerContext); pObj->currentProfilerContext = NULL; } while (pObj->freelistProfilerContext) { ProfilerContext *c = pObj->freelistProfilerContext; pObj->freelistProfilerContext = c->previous; - free(c); + PyMem_Free(c); } pObj->freelistProfilerContext = NULL; } @@ -397,7 +393,7 @@ ptrace_enter_call(PyObject *self, void *key, PyObject *userObj) else { /* free list exhausted, allocate a new one */ pContext = (ProfilerContext*) - malloc(sizeof(ProfilerContext)); + PyMem_Malloc(sizeof(ProfilerContext)); if (pContext == NULL) { pObj->flags |= POF_NOMEMORY; goto restorePyerr; @@ -708,7 +704,7 @@ flush_unmatched(ProfilerObject *pObj) else pObj->currentProfilerContext = pContext->previous; if (pContext) - free(pContext); + PyMem_Free(pContext); } } @@ -876,10 +872,12 @@ PyInit__lsprof(void) PyDict_SetItemString(d, "Profiler", (PyObject *)&PyProfiler_Type); if (!initialized) { - PyStructSequence_InitType(&StatsEntryType, - &profiler_entry_desc); - PyStructSequence_InitType(&StatsSubEntryType, - &profiler_subentry_desc); + if (PyStructSequence_InitType2(&StatsEntryType, + &profiler_entry_desc) < 0) + return NULL; + if (PyStructSequence_InitType2(&StatsSubEntryType, + &profiler_subentry_desc) < 0) + return NULL; } Py_INCREF((PyObject*) &StatsEntryType); Py_INCREF((PyObject*) &StatsSubEntryType); |