summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
Diffstat (limited to 'Include')
-rw-r--r--Include/objimpl.h38
-rw-r--r--Include/pymem.h72
2 files changed, 13 insertions, 97 deletions
diff --git a/Include/objimpl.h b/Include/objimpl.h
index a616620..47e0da4 100644
--- a/Include/objimpl.h
+++ b/Include/objimpl.h
@@ -77,40 +77,20 @@ recommended to use PyObject_{New, NewVar, Del}. */
modules should use the PyObject_* API. */
#ifdef WITH_PYMALLOC
-#define PyCore_OBJECT_MALLOC_FUNC _PyCore_ObjectMalloc
-#define PyCore_OBJECT_REALLOC_FUNC _PyCore_ObjectRealloc
-#define PyCore_OBJECT_FREE_FUNC _PyCore_ObjectFree
-#define NEED_TO_DECLARE_OBJECT_MALLOC_AND_FRIEND
+void *_PyCore_ObjectMalloc(size_t nbytes);
+void *_PyCore_ObjectRealloc(void *p, size_t nbytes);
+void _PyCore_ObjectFree(void *p);
+#define PyCore_OBJECT_MALLOC _PyCore_ObjectMalloc
+#define PyCore_OBJECT_REALLOC _PyCore_ObjectRealloc
+#define PyCore_OBJECT_FREE _PyCore_ObjectFree
#endif /* !WITH_PYMALLOC */
-#ifndef PyCore_OBJECT_MALLOC_FUNC
-#undef PyCore_OBJECT_REALLOC_FUNC
-#undef PyCore_OBJECT_FREE_FUNC
-#define PyCore_OBJECT_MALLOC_FUNC PyCore_MALLOC_FUNC
-#define PyCore_OBJECT_REALLOC_FUNC PyCore_REALLOC_FUNC
-#define PyCore_OBJECT_FREE_FUNC PyCore_FREE_FUNC
-#endif
-
-#ifndef PyCore_OBJECT_MALLOC_PROTO
-#undef PyCore_OBJECT_REALLOC_PROTO
-#undef PyCore_OBJECT_FREE_PROTO
-#define PyCore_OBJECT_MALLOC_PROTO PyCore_MALLOC_PROTO
-#define PyCore_OBJECT_REALLOC_PROTO PyCore_REALLOC_PROTO
-#define PyCore_OBJECT_FREE_PROTO PyCore_FREE_PROTO
-#endif
-
-#ifdef NEED_TO_DECLARE_OBJECT_MALLOC_AND_FRIEND
-extern void *PyCore_OBJECT_MALLOC_FUNC PyCore_OBJECT_MALLOC_PROTO;
-extern void *PyCore_OBJECT_REALLOC_FUNC PyCore_OBJECT_REALLOC_PROTO;
-extern void PyCore_OBJECT_FREE_FUNC PyCore_OBJECT_FREE_PROTO;
-#endif
-
#ifndef PyCore_OBJECT_MALLOC
#undef PyCore_OBJECT_REALLOC
#undef PyCore_OBJECT_FREE
-#define PyCore_OBJECT_MALLOC(n) PyCore_OBJECT_MALLOC_FUNC(n)
-#define PyCore_OBJECT_REALLOC(p, n) PyCore_OBJECT_REALLOC_FUNC((p), (n))
-#define PyCore_OBJECT_FREE(p) PyCore_OBJECT_FREE_FUNC(p)
+#define PyCore_OBJECT_MALLOC(n) PyCore_MALLOC(n)
+#define PyCore_OBJECT_REALLOC(p, n) PyCore_REALLOC((p), (n))
+#define PyCore_OBJECT_FREE(p) PyCore_FREE(p)
#endif
/*
diff --git a/Include/pymem.h b/Include/pymem.h
index d09f38c..a02a1e0 100644
--- a/Include/pymem.h
+++ b/Include/pymem.h
@@ -20,39 +20,14 @@ extern "C" {
The PyCore_* macros can be defined to make the interpreter use a
custom allocator. Note that they are for internal use only. Both
- the core and extension modules should use the PyMem_* API.
-
- See the comment block at the end of this file for two scenarios
- showing how to use this to use a different allocator. */
-
-#ifndef PyCore_MALLOC_FUNC
-#undef PyCore_REALLOC_FUNC
-#undef PyCore_FREE_FUNC
-#define PyCore_MALLOC_FUNC malloc
-#define PyCore_REALLOC_FUNC realloc
-#define PyCore_FREE_FUNC free
-#endif
-
-#ifndef PyCore_MALLOC_PROTO
-#undef PyCore_REALLOC_PROTO
-#undef PyCore_FREE_PROTO
-#define PyCore_MALLOC_PROTO (size_t)
-#define PyCore_REALLOC_PROTO (void *, size_t)
-#define PyCore_FREE_PROTO (void *)
-#endif
-
-#ifdef NEED_TO_DECLARE_MALLOC_AND_FRIEND
-extern void *PyCore_MALLOC_FUNC PyCore_MALLOC_PROTO;
-extern void *PyCore_REALLOC_FUNC PyCore_REALLOC_PROTO;
-extern void PyCore_FREE_FUNC PyCore_FREE_PROTO;
-#endif
+ the core and extension modules should use the PyMem_* API. */
#ifndef PyCore_MALLOC
#undef PyCore_REALLOC
#undef PyCore_FREE
-#define PyCore_MALLOC(n) PyCore_MALLOC_FUNC(n)
-#define PyCore_REALLOC(p, n) PyCore_REALLOC_FUNC((p), (n))
-#define PyCore_FREE(p) PyCore_FREE_FUNC(p)
+#define PyCore_MALLOC(n) malloc(n)
+#define PyCore_REALLOC(p, n) realloc((p), (n))
+#define PyCore_FREE(p) free(p)
#endif
/* BEWARE:
@@ -133,43 +108,4 @@ extern DL_IMPORT(void) PyMem_Free(void *);
}
#endif
-/* SCENARIOS
-
- Here are two scenarios by Vladimir Marangozov (the author of the
- memory allocation redesign).
-
- 1) Scenario A
-
- Suppose you want to use a debugging malloc library that collects info on
- where the malloc calls originate from. Assume the interface is:
-
- d_malloc(size_t n, char* src_file, unsigned long src_line) c.s.
-
- In this case, you would define (for example in pyconfig.h) :
-
- #define PyCore_MALLOC_FUNC d_malloc
- ...
- #define PyCore_MALLOC_PROTO (size_t, char *, unsigned long)
- ...
- #define NEED_TO_DECLARE_MALLOC_AND_FRIEND
-
- #define PyCore_MALLOC(n) PyCore_MALLOC_FUNC((n), __FILE__, __LINE__)
- ...
-
- 2) Scenario B
-
- Suppose you want to use malloc hooks (defined & initialized in a 3rd party
- malloc library) instead of malloc functions. In this case, you would
- define:
-
- #define PyCore_MALLOC_FUNC (*malloc_hook)
- ...
- #define NEED_TO_DECLARE_MALLOC_AND_FRIEND
-
- and ignore the previous definitions about PyCore_MALLOC_FUNC, etc.
-
-
-*/
-
-
#endif /* !Py_PYMEM_H */