mirror of https://github.com/python/cpython
Vladimir Marangozov's long-awaited malloc restructuring.
For more comments, read the patches@python.org archives. For documentation read the comments in mymalloc.h and objimpl.h. (This is not exactly what Vladimir posted to the patches list; I've made a few changes, and Vladimir sent me a fix in private email for a problem that only occurs in debug mode. I'm also holding back on his change to main.c, which seems unnecessary to me.)
This commit is contained in:
parent
2808b744e8
commit
b18618dab7
|
@ -57,6 +57,8 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "myproto.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
/* Move this down here since some C++ #include's don't like to be included
|
/* Move this down here since some C++ #include's don't like to be included
|
||||||
inside an extern "C" */
|
inside an extern "C" */
|
||||||
|
@ -67,12 +69,8 @@ extern "C" {
|
||||||
#pragma lib_export on
|
#pragma lib_export on
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* The following should never be necessary */
|
#ifndef DL_IMPORT /* declarations for DLL import */
|
||||||
#ifdef NEED_TO_DECLARE_MALLOC_AND_FRIEND
|
#define DL_IMPORT(RTYPE) RTYPE
|
||||||
extern ANY *malloc Py_PROTO((size_t));
|
|
||||||
extern ANY *calloc Py_PROTO((size_t, size_t));
|
|
||||||
extern ANY *realloc Py_PROTO((ANY *, size_t));
|
|
||||||
extern void free Py_PROTO((ANY *)); /* XXX sometimes int on Unix old systems */
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NULL
|
#ifndef NULL
|
||||||
|
@ -87,34 +85,117 @@ extern void free Py_PROTO((ANY *)); /* XXX sometimes int on Unix old systems */
|
||||||
#define _PyMem_EXTRA 0
|
#define _PyMem_EXTRA 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PyMem_NEW(type, n) \
|
/*
|
||||||
( (type *) malloc(_PyMem_EXTRA + (n) * sizeof(type)) )
|
* Core memory allocator
|
||||||
#define PyMem_RESIZE(p, type, n) \
|
* =====================
|
||||||
if ((p) == NULL) \
|
*/
|
||||||
(p) = (type *) malloc(_PyMem_EXTRA + (n) * sizeof(type)); \
|
|
||||||
else \
|
|
||||||
(p) = (type *) realloc((ANY *)(p), \
|
|
||||||
_PyMem_EXTRA + (n) * sizeof(type))
|
|
||||||
#define PyMem_DEL(p) free((ANY *)p)
|
|
||||||
#define PyMem_XDEL(p) if ((p) == NULL) ; else PyMem_DEL(p)
|
|
||||||
|
|
||||||
|
/* To make sure the interpreter is user-malloc friendly, all memory
|
||||||
|
APIs are implemented on top of this one.
|
||||||
|
|
||||||
/* Two sets of function wrappers around malloc and friends; useful if
|
The PyCore_* macros can be defined to make the interpreter use a
|
||||||
you need to be sure that you are using the same memory allocator as
|
custom allocator. Note that they are for internal use only. Both
|
||||||
|
the core and extension modules should use the PyMem_* API. */
|
||||||
|
|
||||||
|
#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 Py_PROTO((size_t))
|
||||||
|
#define PyCore_REALLOC_PROTO Py_PROTO((ANY *, size_t))
|
||||||
|
#define PyCore_FREE_PROTO Py_PROTO((ANY *))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef NEED_TO_DECLARE_MALLOC_AND_FRIEND
|
||||||
|
extern ANY *PyCore_MALLOC_FUNC PyCore_MALLOC_PROTO;
|
||||||
|
extern ANY *PyCore_REALLOC_FUNC PyCore_REALLOC_PROTO;
|
||||||
|
extern void PyCore_FREE_FUNC PyCore_FREE_PROTO;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#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)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* BEWARE:
|
||||||
|
|
||||||
|
Each interface exports both functions and macros. Extension modules
|
||||||
|
should normally use the functions for ensuring binary compatibility
|
||||||
|
of the user's code across Python versions. Subsequently, if the
|
||||||
|
Python runtime switches to its own malloc (different from standard
|
||||||
|
malloc), no recompilation is required for the extensions.
|
||||||
|
|
||||||
|
The macro versions trade compatibility for speed. They can be used
|
||||||
|
whenever there is a performance problem, but their use implies
|
||||||
|
recompilation of the code for each new Python release. The Python
|
||||||
|
core uses the macros because it *is* compiled on every upgrade.
|
||||||
|
This might not be the case with 3rd party extensions in a custom
|
||||||
|
setup (for example, a customer does not always have access to the
|
||||||
|
source of 3rd party deliverables). You have been warned! */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Raw memory interface
|
||||||
|
* ====================
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Functions */
|
||||||
|
|
||||||
|
/* Function wrappers around PyCore_MALLOC and friends; useful if you
|
||||||
|
need to be sure that you are using the same memory allocator as
|
||||||
Python. Note that the wrappers make sure that allocating 0 bytes
|
Python. Note that the wrappers make sure that allocating 0 bytes
|
||||||
returns a non-NULL pointer, even if the underlying malloc doesn't.
|
returns a non-NULL pointer, even if the underlying malloc
|
||||||
The Python interpreter continues to use PyMem_NEW etc. */
|
doesn't. Returned pointers must be checked for NULL explicitly.
|
||||||
|
No action is performed on failure. */
|
||||||
/* These wrappers around malloc call PyErr_NoMemory() on failure */
|
|
||||||
extern DL_IMPORT(ANY *) Py_Malloc Py_PROTO((size_t));
|
|
||||||
extern DL_IMPORT(ANY *) Py_Realloc Py_PROTO((ANY *, size_t));
|
|
||||||
extern DL_IMPORT(void) Py_Free Py_PROTO((ANY *));
|
|
||||||
|
|
||||||
/* These wrappers around malloc *don't* call anything on failure */
|
|
||||||
extern DL_IMPORT(ANY *) PyMem_Malloc Py_PROTO((size_t));
|
extern DL_IMPORT(ANY *) PyMem_Malloc Py_PROTO((size_t));
|
||||||
extern DL_IMPORT(ANY *) PyMem_Realloc Py_PROTO((ANY *, size_t));
|
extern DL_IMPORT(ANY *) PyMem_Realloc Py_PROTO((ANY *, size_t));
|
||||||
extern DL_IMPORT(void) PyMem_Free Py_PROTO((ANY *));
|
extern DL_IMPORT(void) PyMem_Free Py_PROTO((ANY *));
|
||||||
|
|
||||||
|
/* Starting from Python 1.6, the wrappers Py_{Malloc,Realloc,Free} are
|
||||||
|
no longer supported. They used to call PyErr_NoMemory() on failure. */
|
||||||
|
|
||||||
|
/* Macros */
|
||||||
|
#define PyMem_MALLOC(n) PyCore_MALLOC(n)
|
||||||
|
#define PyMem_REALLOC(p, n) PyCore_REALLOC((ANY *)(p), (n))
|
||||||
|
#define PyMem_FREE(p) PyCore_FREE((ANY *)(p))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Type-oriented memory interface
|
||||||
|
* ==============================
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Functions */
|
||||||
|
#define PyMem_New(type, n) \
|
||||||
|
( (type *) PyMem_Malloc((n) * sizeof(type)) )
|
||||||
|
#define PyMem_Resize(p, type, n) \
|
||||||
|
( (p) = (type *) PyMem_Realloc((n) * sizeof(type)) )
|
||||||
|
#define PyMem_Del(p) PyMem_Free(p)
|
||||||
|
|
||||||
|
/* Macros */
|
||||||
|
#define PyMem_NEW(type, n) \
|
||||||
|
( (type *) PyMem_MALLOC(_PyMem_EXTRA + (n) * sizeof(type)) )
|
||||||
|
#define PyMem_RESIZE(p, type, n) \
|
||||||
|
if ((p) == NULL) \
|
||||||
|
(p) = (type *)(PyMem_MALLOC( \
|
||||||
|
_PyMem_EXTRA + (n) * sizeof(type))); \
|
||||||
|
else \
|
||||||
|
(p) = (type *)(PyMem_REALLOC((p), \
|
||||||
|
_PyMem_EXTRA + (n) * sizeof(type)))
|
||||||
|
#define PyMem_DEL(p) PyMem_FREE(p)
|
||||||
|
|
||||||
|
/* PyMem_XDEL is deprecated. To avoid the call when p is NULL,
|
||||||
|
it is recommended to write the test explicitly in the code.
|
||||||
|
Note that according to ANSI C, free(NULL) has no effect. */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,42 +35,204 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
|
#include "mymalloc.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Additional macros for modules that implement new object types.
|
Functions and macros for modules that implement new object types.
|
||||||
You must first include "object.h".
|
You must first include "object.h".
|
||||||
|
|
||||||
PyObject_NEW(type, typeobj) allocates memory for a new object of the given
|
- PyObject_New(type, typeobj) allocates memory for a new object of
|
||||||
type; here 'type' must be the C structure type used to represent the
|
the given type; here 'type' must be the C structure type used to
|
||||||
object and 'typeobj' the address of the corresponding type object.
|
represent the object and 'typeobj' the address of the corresponding
|
||||||
Reference count and type pointer are filled in; the rest of the bytes of
|
type object. Reference count and type pointer are filled in; the
|
||||||
the object are *undefined*! The resulting expression type is 'type *'.
|
rest of the bytes of the object are *undefined*! The resulting
|
||||||
The size of the object is actually determined by the tp_basicsize field
|
expression type is 'type *'. The size of the object is actually
|
||||||
of the type object.
|
determined by the tp_basicsize field of the type object.
|
||||||
|
|
||||||
PyObject_NEW_VAR(type, typeobj, n) is similar but allocates a variable-size
|
- PyObject_NewVar(type, typeobj, n) is similar but allocates a
|
||||||
object with n extra items. The size is computed as tp_basicsize plus
|
variable-size object with n extra items. The size is computed as
|
||||||
n * tp_itemsize. This fills in the ob_size field as well.
|
tp_basicsize plus n * tp_itemsize. This fills in the ob_size field
|
||||||
|
as well.
|
||||||
|
|
||||||
|
- PyObject_Del(op) releases the memory allocated for an object.
|
||||||
|
|
||||||
|
- PyObject_Init(op, typeobj) and PyObject_InitVar(op, typeobj, n) are
|
||||||
|
similar to PyObject_{New, NewVar} except that they don't allocate
|
||||||
|
the memory needed for an object. Instead of the 'type' parameter,
|
||||||
|
they accept the pointer of a new object (allocated by an arbitrary
|
||||||
|
allocator) and initialize its object header fields.
|
||||||
|
|
||||||
|
Note that objects created with PyObject_{New, NewVar} are allocated
|
||||||
|
within the Python heap by an object allocator, the latter being
|
||||||
|
implemented (by default) on top of the Python raw memory
|
||||||
|
allocator. This ensures that Python keeps control on the user's
|
||||||
|
objects regarding their memory management; for instance, they may be
|
||||||
|
subject to automatic garbage collection.
|
||||||
|
|
||||||
|
In case a specific form of memory management is needed, implying that
|
||||||
|
the objects would not reside in the Python heap (for example standard
|
||||||
|
malloc heap(s) are mandatory, use of shared memory, C++ local storage
|
||||||
|
or operator new), you must first allocate the object with your custom
|
||||||
|
allocator, then pass its pointer to PyObject_{Init, InitVar} for
|
||||||
|
filling in its Python-specific fields: reference count, type pointer,
|
||||||
|
possibly others. You should be aware that Python has very limited
|
||||||
|
control over these objects because they don't cooperate with the
|
||||||
|
Python memory manager. Such objects may not be eligible for automatic
|
||||||
|
garbage collection and you have to make sure that they are released
|
||||||
|
accordingly whenever their destructor gets called (cf. the specific
|
||||||
|
form of memory management you're using).
|
||||||
|
|
||||||
|
Unless you have specific memory management requirements, it is
|
||||||
|
recommended to use PyObject_{New, NewVar, Del}. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Core object memory allocator
|
||||||
|
* ============================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MS_COREDLL
|
/* The purpose of the object allocator is to make make the distinction
|
||||||
|
between "object memory" and the rest within the Python heap.
|
||||||
|
|
||||||
|
Object memory is the one allocated by PyObject_{New, NewVar}, i.e.
|
||||||
|
the one that holds the object's representation defined by its C
|
||||||
|
type structure, *excluding* any object-specific memory buffers that
|
||||||
|
might be referenced by the structure (for type structures that have
|
||||||
|
pointer fields). By default, the object memory allocator is
|
||||||
|
implemented on top of the raw memory allocator.
|
||||||
|
|
||||||
|
The PyCore_* macros can be defined to make the interpreter use a
|
||||||
|
custom object memory allocator. They are reserved for internal
|
||||||
|
memory management purposes exclusively. Both the core and extension
|
||||||
|
modules should use the PyObject_* API. */
|
||||||
|
|
||||||
|
#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 ANY *PyCore_OBJECT_MALLOC_FUNC PyCore_OBJECT_MALLOC_PROTO;
|
||||||
|
extern ANY *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)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Raw object memory interface
|
||||||
|
* ===========================
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* The use of this API should be avoided, unless a builtin object
|
||||||
|
constructor inlines PyObject_{New, NewVar}, either because the
|
||||||
|
latter functions cannot allocate the exact amount of needed memory,
|
||||||
|
either for speed. This situation is exceptional, but occurs for
|
||||||
|
some object constructors (PyBuffer_New, PyList_New...). Inlining
|
||||||
|
PyObject_{New, NewVar} for objects that are supposed to belong to
|
||||||
|
the Python heap is discouraged. If you really have to, make sure
|
||||||
|
the object is initialized with PyObject_{Init, InitVar}. Do *not*
|
||||||
|
inline PyObject_{Init, InitVar} for user-extension types or you
|
||||||
|
might seriously interfere with Python's memory management. */
|
||||||
|
|
||||||
|
/* Functions */
|
||||||
|
|
||||||
|
/* Wrappers around PyCore_OBJECT_MALLOC and friends; useful if you
|
||||||
|
need to be sure that you are using the same object memory allocator
|
||||||
|
as Python. These wrappers *do not* make sure that allocating 0
|
||||||
|
bytes returns a non-NULL pointer. Returned pointers must be checked
|
||||||
|
for NULL explicitly; no action is performed on failure. */
|
||||||
|
extern DL_IMPORT(ANY *) PyObject_Malloc Py_PROTO((size_t));
|
||||||
|
extern DL_IMPORT(ANY *) PyObject_Realloc Py_PROTO((ANY *, size_t));
|
||||||
|
extern DL_IMPORT(void) PyObject_Free Py_PROTO((ANY *));
|
||||||
|
|
||||||
|
/* Macros */
|
||||||
|
#define PyObject_MALLOC(n) PyCore_OBJECT_MALLOC(n)
|
||||||
|
#define PyObject_REALLOC(op, n) PyCore_OBJECT_REALLOC((ANY *)(op), (n))
|
||||||
|
#define PyObject_FREE(op) PyCore_OBJECT_FREE((ANY *)(op))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generic object allocator interface
|
||||||
|
* ==================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Functions */
|
||||||
|
extern DL_IMPORT(PyObject *) PyObject_Init Py_PROTO((PyObject *, PyTypeObject *));
|
||||||
|
extern DL_IMPORT(PyVarObject *) PyObject_InitVar Py_PROTO((PyVarObject *, PyTypeObject *, int));
|
||||||
extern DL_IMPORT(PyObject *) _PyObject_New Py_PROTO((PyTypeObject *));
|
extern DL_IMPORT(PyObject *) _PyObject_New Py_PROTO((PyTypeObject *));
|
||||||
extern DL_IMPORT(PyVarObject *) _PyObject_NewVar Py_PROTO((PyTypeObject *, int));
|
extern DL_IMPORT(PyVarObject *) _PyObject_NewVar Py_PROTO((PyTypeObject *, int));
|
||||||
|
extern DL_IMPORT(void) _PyObject_Del Py_PROTO((PyObject *));
|
||||||
|
|
||||||
#define PyObject_NEW(type, typeobj) ((type *) _PyObject_New(typeobj))
|
#define PyObject_New(type, typeobj) \
|
||||||
#define PyObject_NEW_VAR(type, typeobj, n) ((type *) _PyObject_NewVar(typeobj, n))
|
( (type *) _PyObject_New(typeobj) )
|
||||||
|
#define PyObject_NewVar(type, typeobj, n) \
|
||||||
|
( (type *) _PyObject_NewVar((typeobj), (n)) )
|
||||||
|
#define PyObject_Del(op) _PyObject_Del((PyObject *)(op))
|
||||||
|
|
||||||
#else
|
/* Macros trading binary compatibility for speed. See also mymalloc.h.
|
||||||
/* For an MS-Windows DLL, we change the way an object is created, so that the
|
Note that these macros expect non-NULL object pointers.*/
|
||||||
extension module's malloc is used, rather than the core DLL malloc, as there is
|
#define PyObject_INIT(op, typeobj) \
|
||||||
no guarantee they will use the same heap
|
( (op)->ob_type = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
|
||||||
*/
|
#define PyObject_INIT_VAR(op, typeobj, size) \
|
||||||
extern DL_IMPORT(PyObject *) _PyObject_New Py_PROTO((PyTypeObject *, PyObject *));
|
( (op)->ob_size = (size), PyObject_INIT((op), (typeobj)) )
|
||||||
extern DL_IMPORT(PyVarObject *) _PyObject_NewVar Py_PROTO((PyTypeObject *, int, PyVarObject *));
|
|
||||||
|
|
||||||
#define PyObject_NEW(type, typeobj) ((type *) _PyObject_New(typeobj,(PyObject *)malloc((typeobj)->tp_basicsize)))
|
#define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize )
|
||||||
#define PyObject_NEW_VAR(type, typeobj, n) ((type *) _PyObject_NewVar(typeobj, n, (PyVarObject *)malloc((typeobj)->tp_basicsize + n * (typeobj)->tp_itemsize)))
|
#define _PyObject_VAR_SIZE(typeobj, n) \
|
||||||
|
( (typeobj)->tp_basicsize + (n) * (typeobj)->tp_itemsize )
|
||||||
|
|
||||||
#endif /* MS_COREDLL */
|
#define PyObject_NEW(type, typeobj) \
|
||||||
|
( (type *) PyObject_Init( \
|
||||||
|
(PyObject *) PyObject_MALLOC( _PyObject_SIZE(typeobj) ), (typeobj)) )
|
||||||
|
#define PyObject_NEW_VAR(type, typeobj, n) \
|
||||||
|
( (type *) PyObject_InitVar( \
|
||||||
|
(PyVarObject *) PyObject_MALLOC( _PyObject_VAR_SIZE((typeobj),(n)) ),\
|
||||||
|
(typeobj), (n)) )
|
||||||
|
#define PyObject_DEL(op) PyObject_FREE(op)
|
||||||
|
|
||||||
|
/* This example code implements an object constructor with a custom
|
||||||
|
allocator, where PyObject_New is inlined, and shows the important
|
||||||
|
distinction between two steps (at least):
|
||||||
|
1) the actual allocation of the object storage;
|
||||||
|
2) the initialization of the Python specific fields
|
||||||
|
in this storage with PyObject_{Init, InitVar}.
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
YourObject_New(...)
|
||||||
|
{
|
||||||
|
PyObject *op;
|
||||||
|
|
||||||
|
op = (PyObject *) Your_Allocator(_PyObject_SIZE(YourTypeStruct));
|
||||||
|
if (op == NULL)
|
||||||
|
return PyErr_NoMemory();
|
||||||
|
|
||||||
|
op = PyObject_Init(op, &YourTypeStruct);
|
||||||
|
if (op == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
op->ob_field = value;
|
||||||
|
...
|
||||||
|
return op;
|
||||||
|
}
|
||||||
|
|
||||||
|
Note that in C++, the use of the new operator usually implies that
|
||||||
|
the 1st step is performed automatically for you, so in a C++ class
|
||||||
|
constructor you would start directly with PyObject_Init/InitVar. */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -273,7 +273,7 @@ PyCursesScreen_New(arg)
|
||||||
PyFileObject *in_fo;
|
PyFileObject *in_fo;
|
||||||
PyFileObject *out_fo;
|
PyFileObject *out_fo;
|
||||||
PyCursesScreenObject *xp;
|
PyCursesScreenObject *xp;
|
||||||
xp = PyObject_NEW(PyCursesScreenObject, &PyCursesScreen_Type);
|
xp = PyObject_New(PyCursesScreenObject, &PyCursesScreen_Type);
|
||||||
if (xp == NULL)
|
if (xp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
return (PyObject *)xp;
|
return (PyObject *)xp;
|
||||||
|
@ -289,7 +289,7 @@ PyCursesWindow_New(win)
|
||||||
{
|
{
|
||||||
PyCursesWindowObject *wo;
|
PyCursesWindowObject *wo;
|
||||||
|
|
||||||
wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
|
wo = PyObject_New(PyCursesWindowObject, &PyCursesWindow_Type);
|
||||||
if (wo == NULL)
|
if (wo == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
wo->win = win;
|
wo->win = win;
|
||||||
|
@ -303,7 +303,7 @@ PyCursesWindow_Dealloc(wo)
|
||||||
{
|
{
|
||||||
if (wo->win != stdscr)
|
if (wo->win != stdscr)
|
||||||
delwin(wo->win);
|
delwin(wo->win);
|
||||||
PyMem_DEL(wo);
|
PyObject_Del(wo);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -1125,7 +1125,7 @@ PyCursesPad_New(pad)
|
||||||
WINDOW *pad;
|
WINDOW *pad;
|
||||||
{
|
{
|
||||||
PyCursesPadObject *po;
|
PyCursesPadObject *po;
|
||||||
po = PyObject_NEW(PyCursesPadObject, &PyCursesPad_Type);
|
po = PyObject_New(PyCursesPadObject, &PyCursesPad_Type);
|
||||||
if (po == NULL)
|
if (po == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
po->pad = pad;
|
po->pad = pad;
|
||||||
|
|
|
@ -848,7 +848,7 @@ _compile(PyObject* self_, PyObject* args)
|
||||||
&PyString_Type, &code, &groups, &groupindex))
|
&PyString_Type, &code, &groups, &groupindex))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
self = PyObject_NEW(PatternObject, &Pattern_Type);
|
self = PyObject_New(PatternObject, &Pattern_Type);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -886,7 +886,7 @@ _pattern_new_match(PatternObject* pattern, SRE_STATE* state,
|
||||||
if (status > 0) {
|
if (status > 0) {
|
||||||
|
|
||||||
/* create match object (with room for extra group marks) */
|
/* create match object (with room for extra group marks) */
|
||||||
match = PyObject_NEW_VAR(MatchObject, &Match_Type, 2*pattern->groups);
|
match = PyObject_NewVar(MatchObject, &Match_Type, 2*pattern->groups);
|
||||||
if (match == NULL)
|
if (match == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -1002,7 +1002,7 @@ _pattern_dealloc(PatternObject* self)
|
||||||
Py_XDECREF(self->code);
|
Py_XDECREF(self->code);
|
||||||
Py_XDECREF(self->pattern);
|
Py_XDECREF(self->pattern);
|
||||||
Py_XDECREF(self->groupindex);
|
Py_XDECREF(self->groupindex);
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
|
@ -1163,7 +1163,7 @@ _match_dealloc(MatchObject* self)
|
||||||
{
|
{
|
||||||
Py_XDECREF(self->string);
|
Py_XDECREF(self->string);
|
||||||
Py_DECREF(self->pattern);
|
Py_DECREF(self->pattern);
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
|
|
|
@ -469,7 +469,7 @@ Tkapp_New(screenName, baseName, className, interactive)
|
||||||
TkappObject *v;
|
TkappObject *v;
|
||||||
char *argv0;
|
char *argv0;
|
||||||
|
|
||||||
v = PyObject_NEW(TkappObject, &Tkapp_Type);
|
v = PyObject_New(TkappObject, &Tkapp_Type);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -1640,7 +1640,7 @@ Tktt_New(func)
|
||||||
{
|
{
|
||||||
TkttObject *v;
|
TkttObject *v;
|
||||||
|
|
||||||
v = PyObject_NEW(TkttObject, &Tktt_Type);
|
v = PyObject_New(TkttObject, &Tktt_Type);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -1662,7 +1662,7 @@ Tktt_Dealloc(self)
|
||||||
|
|
||||||
Py_XDECREF(func);
|
Py_XDECREF(func);
|
||||||
|
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -1910,7 +1910,7 @@ Tkapp_Dealloc(self)
|
||||||
ENTER_TCL
|
ENTER_TCL
|
||||||
Tcl_DeleteInterp(Tkapp_Interp(self));
|
Tcl_DeleteInterp(Tkapp_Interp(self));
|
||||||
LEAVE_TCL
|
LEAVE_TCL
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
DisableEventHook();
|
DisableEventHook();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -648,7 +648,7 @@ newalcobject(ALconfig config)
|
||||||
{
|
{
|
||||||
alcobject *self;
|
alcobject *self;
|
||||||
|
|
||||||
self = PyObject_NEW(alcobject, &Alctype);
|
self = PyObject_New(alcobject, &Alctype);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
/* XXXX Add your own initializers here */
|
/* XXXX Add your own initializers here */
|
||||||
|
@ -667,7 +667,7 @@ alc_dealloc(self)
|
||||||
#else
|
#else
|
||||||
(void) ALfreeconfig(self->config); /* ignore errors */
|
(void) ALfreeconfig(self->config); /* ignore errors */
|
||||||
#endif
|
#endif
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -1421,7 +1421,7 @@ newalpobject(ALport port)
|
||||||
{
|
{
|
||||||
alpobject *self;
|
alpobject *self;
|
||||||
|
|
||||||
self = PyObject_NEW(alpobject, &Alptype);
|
self = PyObject_New(alpobject, &Alptype);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
/* XXXX Add your own initializers here */
|
/* XXXX Add your own initializers here */
|
||||||
|
@ -1442,7 +1442,7 @@ alp_dealloc(self)
|
||||||
ALcloseport(self->port);
|
ALcloseport(self->port);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -346,7 +346,7 @@ newarrayobject(size, descr)
|
||||||
if (nbytes / descr->itemsize != (size_t)size) {
|
if (nbytes / descr->itemsize != (size_t)size) {
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
}
|
}
|
||||||
op = PyMem_NEW(arrayobject, 1);
|
op = PyObject_NewVar(arrayobject, &Arraytype, size);
|
||||||
if (op == NULL) {
|
if (op == NULL) {
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
}
|
}
|
||||||
|
@ -356,14 +356,11 @@ newarrayobject(size, descr)
|
||||||
else {
|
else {
|
||||||
op->ob_item = PyMem_NEW(char, nbytes);
|
op->ob_item = PyMem_NEW(char, nbytes);
|
||||||
if (op->ob_item == NULL) {
|
if (op->ob_item == NULL) {
|
||||||
PyMem_DEL(op);
|
PyObject_Del(op);
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
op->ob_type = &Arraytype;
|
|
||||||
op->ob_size = size;
|
|
||||||
op->ob_descr = descr;
|
op->ob_descr = descr;
|
||||||
_Py_NewReference((PyObject *)op);
|
|
||||||
return (PyObject *) op;
|
return (PyObject *) op;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -466,7 +463,7 @@ array_dealloc(op)
|
||||||
{
|
{
|
||||||
if (op->ob_item != NULL)
|
if (op->ob_item != NULL)
|
||||||
PyMem_DEL(op->ob_item);
|
PyMem_DEL(op->ob_item);
|
||||||
PyMem_DEL(op);
|
PyObject_Del(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
@ -89,7 +89,7 @@ newdbhashobject(file, flags, mode,
|
||||||
bsddbobject *dp;
|
bsddbobject *dp;
|
||||||
HASHINFO info;
|
HASHINFO info;
|
||||||
|
|
||||||
if ((dp = PyObject_NEW(bsddbobject, &Bsddbtype)) == NULL)
|
if ((dp = PyObject_New(bsddbobject, &Bsddbtype)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
info.bsize = bsize;
|
info.bsize = bsize;
|
||||||
|
@ -143,7 +143,7 @@ newdbbtobject(file, flags, mode,
|
||||||
bsddbobject *dp;
|
bsddbobject *dp;
|
||||||
BTREEINFO info;
|
BTREEINFO info;
|
||||||
|
|
||||||
if ((dp = PyObject_NEW(bsddbobject, &Bsddbtype)) == NULL)
|
if ((dp = PyObject_New(bsddbobject, &Bsddbtype)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
info.flags = btflags;
|
info.flags = btflags;
|
||||||
|
@ -200,7 +200,7 @@ newdbrnobject(file, flags, mode,
|
||||||
bsddbobject *dp;
|
bsddbobject *dp;
|
||||||
RECNOINFO info;
|
RECNOINFO info;
|
||||||
|
|
||||||
if ((dp = PyObject_NEW(bsddbobject, &Bsddbtype)) == NULL)
|
if ((dp = PyObject_New(bsddbobject, &Bsddbtype)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
info.flags = rnflags;
|
info.flags = rnflags;
|
||||||
|
@ -261,7 +261,7 @@ bsddb_dealloc(dp)
|
||||||
"Python bsddb: close errno %d in dealloc\n",
|
"Python bsddb: close errno %d in dealloc\n",
|
||||||
errno);
|
errno);
|
||||||
}
|
}
|
||||||
PyMem_DEL(dp);
|
PyObject_Del(dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_THREAD
|
#ifdef WITH_THREAD
|
||||||
|
|
|
@ -171,7 +171,7 @@ Pdata_dealloc(Pdata *self) {
|
||||||
|
|
||||||
if (self->data) free(self->data);
|
if (self->data) free(self->data);
|
||||||
|
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyTypeObject PdataType = {
|
static PyTypeObject PdataType = {
|
||||||
|
@ -186,7 +186,7 @@ static PyObject *
|
||||||
Pdata_New() {
|
Pdata_New() {
|
||||||
Pdata *self;
|
Pdata *self;
|
||||||
|
|
||||||
UNLESS (self = PyObject_NEW(Pdata, &PdataType)) return NULL;
|
UNLESS (self = PyObject_New(Pdata, &PdataType)) return NULL;
|
||||||
self->size=8;
|
self->size=8;
|
||||||
self->length=0;
|
self->length=0;
|
||||||
self->data=malloc(self->size * sizeof(PyObject*));
|
self->data=malloc(self->size * sizeof(PyObject*));
|
||||||
|
@ -2132,7 +2132,7 @@ static Picklerobject *
|
||||||
newPicklerobject(PyObject *file, int bin) {
|
newPicklerobject(PyObject *file, int bin) {
|
||||||
Picklerobject *self;
|
Picklerobject *self;
|
||||||
|
|
||||||
UNLESS (self = PyObject_NEW(Picklerobject, &Picklertype))
|
UNLESS (self = PyObject_New(Picklerobject, &Picklertype))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
self->fp = NULL;
|
self->fp = NULL;
|
||||||
|
@ -2243,7 +2243,7 @@ Pickler_dealloc(Picklerobject *self) {
|
||||||
free(self->write_buf);
|
free(self->write_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2885,7 +2885,7 @@ Instance_New(PyObject *cls, PyObject *args) {
|
||||||
PyInstanceObject *inst;
|
PyInstanceObject *inst;
|
||||||
|
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
UNLESS (inst=PyObject_NEW(PyInstanceObject, &PyInstance_Type))
|
UNLESS (inst=PyObject_New(PyInstanceObject, &PyInstance_Type))
|
||||||
goto err;
|
goto err;
|
||||||
inst->in_class=(PyClassObject*)cls;
|
inst->in_class=(PyClassObject*)cls;
|
||||||
Py_INCREF(cls);
|
Py_INCREF(cls);
|
||||||
|
@ -4036,7 +4036,7 @@ static Unpicklerobject *
|
||||||
newUnpicklerobject(PyObject *f) {
|
newUnpicklerobject(PyObject *f) {
|
||||||
Unpicklerobject *self;
|
Unpicklerobject *self;
|
||||||
|
|
||||||
UNLESS (self = PyObject_NEW(Unpicklerobject, &Unpicklertype))
|
UNLESS (self = PyObject_New(Unpicklerobject, &Unpicklertype))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
self->file = NULL;
|
self->file = NULL;
|
||||||
|
@ -4141,7 +4141,7 @@ Unpickler_dealloc(Unpicklerobject *self) {
|
||||||
free(self->buf);
|
free(self->buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ static char cStringIO_module_documentation[] =
|
||||||
"\n"
|
"\n"
|
||||||
"This module provides a simple useful replacement for\n"
|
"This module provides a simple useful replacement for\n"
|
||||||
"the StringIO module that is written in C. It does not provide the\n"
|
"the StringIO module that is written in C. It does not provide the\n"
|
||||||
"full generality if StringIO, but it provides anough for most\n"
|
"full generality if StringIO, but it provides enough for most\n"
|
||||||
"applications and is especially useful in conjuction with the\n"
|
"applications and is especially useful in conjuction with the\n"
|
||||||
"pickle module.\n"
|
"pickle module.\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
@ -407,7 +407,7 @@ static void
|
||||||
O_dealloc(Oobject *self) {
|
O_dealloc(Oobject *self) {
|
||||||
if (self->buf != NULL)
|
if (self->buf != NULL)
|
||||||
free(self->buf);
|
free(self->buf);
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -465,7 +465,7 @@ static PyObject *
|
||||||
newOobject(int size) {
|
newOobject(int size) {
|
||||||
Oobject *self;
|
Oobject *self;
|
||||||
|
|
||||||
self = PyObject_NEW(Oobject, &Otype);
|
self = PyObject_New(Oobject, &Otype);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
self->pos=0;
|
self->pos=0;
|
||||||
|
@ -536,7 +536,7 @@ static struct PyMethodDef I_methods[] = {
|
||||||
static void
|
static void
|
||||||
I_dealloc(Iobject *self) {
|
I_dealloc(Iobject *self) {
|
||||||
Py_XDECREF(self->pbuf);
|
Py_XDECREF(self->pbuf);
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -586,7 +586,7 @@ newIobject(PyObject *s) {
|
||||||
}
|
}
|
||||||
buf = PyString_AS_STRING(s);
|
buf = PyString_AS_STRING(s);
|
||||||
size = PyString_GET_SIZE(s);
|
size = PyString_GET_SIZE(s);
|
||||||
UNLESS(self = PyObject_NEW(Iobject, &Itype)) return NULL;
|
UNLESS(self = PyObject_New(Iobject, &Itype)) return NULL;
|
||||||
Py_INCREF(s);
|
Py_INCREF(s);
|
||||||
self->buf=buf;
|
self->buf=buf;
|
||||||
self->string_size=size;
|
self->string_size=size;
|
||||||
|
|
|
@ -447,7 +447,7 @@ cdplayer_dealloc(self)
|
||||||
{
|
{
|
||||||
if (self->ob_cdplayer != NULL)
|
if (self->ob_cdplayer != NULL)
|
||||||
CDclose(self->ob_cdplayer);
|
CDclose(self->ob_cdplayer);
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -483,7 +483,7 @@ newcdplayerobject(cdp)
|
||||||
{
|
{
|
||||||
cdplayerobject *p;
|
cdplayerobject *p;
|
||||||
|
|
||||||
p = PyObject_NEW(cdplayerobject, &CdPlayertype);
|
p = PyObject_New(cdplayerobject, &CdPlayertype);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
p->ob_cdplayer = cdp;
|
p->ob_cdplayer = cdp;
|
||||||
|
@ -761,7 +761,7 @@ cdparser_dealloc(self)
|
||||||
self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL;
|
self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL;
|
||||||
}
|
}
|
||||||
CDdeleteparser(self->ob_cdparser);
|
CDdeleteparser(self->ob_cdparser);
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -799,7 +799,7 @@ newcdparserobject(cdp)
|
||||||
cdparserobject *p;
|
cdparserobject *p;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
p = PyObject_NEW(cdparserobject, &CdParsertype);
|
p = PyObject_New(cdparserobject, &CdParsertype);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
p->ob_cdparser = cdp;
|
p->ob_cdparser = cdp;
|
||||||
|
|
|
@ -673,7 +673,7 @@ cl_dealloc(PyObject *self)
|
||||||
else
|
else
|
||||||
clCloseDecompressor(SELF->ob_compressorHdl);
|
clCloseDecompressor(SELF->ob_compressorHdl);
|
||||||
}
|
}
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -713,7 +713,7 @@ doOpen(PyObject *self, PyObject *args, int (*open_func)(int, CL_Handle *),
|
||||||
if (!PyArg_Parse(args, "i", &scheme))
|
if (!PyArg_Parse(args, "i", &scheme))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
new = PyObject_NEW(clobject, &Cltype);
|
new = PyObject_New(clobject, &Cltype);
|
||||||
if (new == NULL)
|
if (new == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ int mode;
|
||||||
{
|
{
|
||||||
dbmobject *dp;
|
dbmobject *dp;
|
||||||
|
|
||||||
dp = PyObject_NEW(dbmobject, &Dbmtype);
|
dp = PyObject_New(dbmobject, &Dbmtype);
|
||||||
if (dp == NULL)
|
if (dp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
dp->di_size = -1;
|
dp->di_size = -1;
|
||||||
|
@ -82,7 +82,7 @@ dbm_dealloc(dp)
|
||||||
{
|
{
|
||||||
if ( dp->di_dbm )
|
if ( dp->di_dbm )
|
||||||
dbm_close(dp->di_dbm);
|
dbm_close(dp->di_dbm);
|
||||||
PyMem_DEL(dp);
|
PyObject_Del(dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
@ -54,7 +54,7 @@ newdlobject(handle)
|
||||||
PyUnivPtr *handle;
|
PyUnivPtr *handle;
|
||||||
{
|
{
|
||||||
dlobject *xp;
|
dlobject *xp;
|
||||||
xp = PyObject_NEW(dlobject, &Dltype);
|
xp = PyObject_New(dlobject, &Dltype);
|
||||||
if (xp == NULL)
|
if (xp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
xp->dl_handle = handle;
|
xp->dl_handle = handle;
|
||||||
|
@ -67,7 +67,7 @@ dl_dealloc(xp)
|
||||||
{
|
{
|
||||||
if (xp->dl_handle != NULL)
|
if (xp->dl_handle != NULL)
|
||||||
dlclose(xp->dl_handle);
|
dlclose(xp->dl_handle);
|
||||||
PyMem_DEL(xp);
|
PyObject_Del(xp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -332,7 +332,7 @@ generic_dealloc(g)
|
||||||
fl_free_object(g->ob_generic);
|
fl_free_object(g->ob_generic);
|
||||||
Py_XDECREF(g->ob_callback);
|
Py_XDECREF(g->ob_callback);
|
||||||
Py_XDECREF(g->ob_callback_arg);
|
Py_XDECREF(g->ob_callback_arg);
|
||||||
PyMem_DEL(g);
|
PyObject_Del(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define OFF(x) offsetof(FL_OBJECT, x)
|
#define OFF(x) offsetof(FL_OBJECT, x)
|
||||||
|
@ -461,7 +461,7 @@ newgenericobject(generic, methods)
|
||||||
PyMethodDef *methods;
|
PyMethodDef *methods;
|
||||||
{
|
{
|
||||||
genericobject *g;
|
genericobject *g;
|
||||||
g = PyObject_NEW(genericobject, &GenericObjecttype);
|
g = PyObject_New(genericobject, &GenericObjecttype);
|
||||||
if (g == NULL)
|
if (g == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
g-> ob_generic = generic;
|
g-> ob_generic = generic;
|
||||||
|
@ -1852,7 +1852,7 @@ form_dealloc(f)
|
||||||
if (f->ob_form->visible)
|
if (f->ob_form->visible)
|
||||||
fl_hide_form(f->ob_form);
|
fl_hide_form(f->ob_form);
|
||||||
fl_free_form(f->ob_form);
|
fl_free_form(f->ob_form);
|
||||||
PyMem_DEL(f);
|
PyObject_Del(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define OFF(x) offsetof(FL_FORM, x)
|
#define OFF(x) offsetof(FL_FORM, x)
|
||||||
|
@ -1931,7 +1931,7 @@ newformobject(form)
|
||||||
FL_FORM *form;
|
FL_FORM *form;
|
||||||
{
|
{
|
||||||
formobject *f;
|
formobject *f;
|
||||||
f = PyObject_NEW(formobject, &Formtype);
|
f = PyObject_New(formobject, &Formtype);
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
f->ob_form = form;
|
f->ob_form = form;
|
||||||
|
|
|
@ -59,7 +59,7 @@ newfhobject(fh)
|
||||||
"error creating new font handle");
|
"error creating new font handle");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
fhp = PyObject_NEW(fhobject, &Fhtype);
|
fhp = PyObject_New(fhobject, &Fhtype);
|
||||||
if (fhp == NULL)
|
if (fhp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
fhp->fh_fh = fh;
|
fhp->fh_fh = fh;
|
||||||
|
@ -196,7 +196,7 @@ fh_dealloc(fhp)
|
||||||
fhobject *fhp;
|
fhobject *fhp;
|
||||||
{
|
{
|
||||||
fmfreefont(fhp->fh_fh);
|
fmfreefont(fhp->fh_fh);
|
||||||
PyMem_DEL(fhp);
|
PyObject_Del(fhp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyTypeObject Fhtype = {
|
static PyTypeObject Fhtype = {
|
||||||
|
|
|
@ -93,7 +93,7 @@ int mode;
|
||||||
{
|
{
|
||||||
dbmobject *dp;
|
dbmobject *dp;
|
||||||
|
|
||||||
dp = PyObject_NEW(dbmobject, &Dbmtype);
|
dp = PyObject_New(dbmobject, &Dbmtype);
|
||||||
if (dp == NULL)
|
if (dp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
dp->di_size = -1;
|
dp->di_size = -1;
|
||||||
|
@ -117,7 +117,7 @@ dbm_dealloc(dp)
|
||||||
{
|
{
|
||||||
if ( dp->di_dbm )
|
if ( dp->di_dbm )
|
||||||
gdbm_close(dp->di_dbm);
|
gdbm_close(dp->di_dbm);
|
||||||
PyMem_DEL(dp);
|
PyObject_Del(dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
@ -529,7 +529,7 @@ calculate_path()
|
||||||
bufsz += strlen(exec_prefix) + 1;
|
bufsz += strlen(exec_prefix) + 1;
|
||||||
|
|
||||||
/* This is the only malloc call in this file */
|
/* This is the only malloc call in this file */
|
||||||
buf = malloc(bufsz);
|
buf = PyMem_Malloc(bufsz);
|
||||||
|
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
/* We can't exit, so print a warning and limp along */
|
/* We can't exit, so print a warning and limp along */
|
||||||
|
|
|
@ -104,7 +104,7 @@ newladobject(PyObject *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create and initialize the object */
|
/* Create and initialize the object */
|
||||||
if ((xp = PyObject_NEW(lad_t, &Ladtype)) == NULL) {
|
if ((xp = PyObject_New(lad_t, &Ladtype)) == NULL) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ static void
|
||||||
lad_dealloc(lad_t *xp)
|
lad_dealloc(lad_t *xp)
|
||||||
{
|
{
|
||||||
close(xp->x_fd);
|
close(xp->x_fd);
|
||||||
PyMem_DEL(xp);
|
PyObject_Del(xp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -56,7 +56,7 @@ newmd5object()
|
||||||
{
|
{
|
||||||
md5object *md5p;
|
md5object *md5p;
|
||||||
|
|
||||||
md5p = PyObject_NEW(md5object, &MD5type);
|
md5p = PyObject_New(md5object, &MD5type);
|
||||||
if (md5p == NULL)
|
if (md5p == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ static void
|
||||||
md5_dealloc(md5p)
|
md5_dealloc(md5p)
|
||||||
md5object *md5p;
|
md5object *md5p;
|
||||||
{
|
{
|
||||||
PyMem_DEL(md5p);
|
PyObject_Del(md5p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ mmap_object_dealloc(mmap_object * m_obj)
|
||||||
}
|
}
|
||||||
#endif /* UNIX */
|
#endif /* UNIX */
|
||||||
|
|
||||||
PyMem_DEL(m_obj);
|
PyObject_Del(m_obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -706,7 +706,7 @@ new_mmap_object (PyObject * self, PyObject * args, PyObject *kwdict)
|
||||||
)
|
)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
m_obj = PyObject_NEW (mmap_object, &mmap_object_type);
|
m_obj = PyObject_New (mmap_object, &mmap_object_type);
|
||||||
if (m_obj == NULL) {return NULL;}
|
if (m_obj == NULL) {return NULL;}
|
||||||
m_obj->size = (size_t) map_size;
|
m_obj->size = (size_t) map_size;
|
||||||
m_obj->pos = (size_t) 0;
|
m_obj->pos = (size_t) 0;
|
||||||
|
@ -757,7 +757,7 @@ new_mmap_object (PyObject * self, PyObject * args)
|
||||||
fseek(&_iob[fileno], 0, SEEK_SET);
|
fseek(&_iob[fileno], 0, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_obj = PyObject_NEW (mmap_object, &mmap_object_type);
|
m_obj = PyObject_New (mmap_object, &mmap_object_type);
|
||||||
|
|
||||||
if (fh) {
|
if (fh) {
|
||||||
m_obj->file_handle = fh;
|
m_obj->file_handle = fh;
|
||||||
|
|
|
@ -123,7 +123,7 @@ newmpzobject()
|
||||||
#ifdef MPZ_DEBUG
|
#ifdef MPZ_DEBUG
|
||||||
fputs( "mpz_object() called...\n", stderr );
|
fputs( "mpz_object() called...\n", stderr );
|
||||||
#endif /* def MPZ_DEBUG */
|
#endif /* def MPZ_DEBUG */
|
||||||
mpzp = PyObject_NEW(mpzobject, &MPZtype);
|
mpzp = PyObject_New(mpzobject, &MPZtype);
|
||||||
if (mpzp == NULL)
|
if (mpzp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -285,7 +285,7 @@ mpz_dealloc(mpzp)
|
||||||
fputs( "mpz_dealloc() called...\n", stderr );
|
fputs( "mpz_dealloc() called...\n", stderr );
|
||||||
#endif /* def MPZ_DEBUG */
|
#endif /* def MPZ_DEBUG */
|
||||||
mpz_clear(&mpzp->mpz);
|
mpz_clear(&mpzp->mpz);
|
||||||
PyMem_DEL(mpzp);
|
PyObject_Del(mpzp);
|
||||||
} /* mpz_dealloc() */
|
} /* mpz_dealloc() */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ new_instance(unused, args)
|
||||||
&PyClass_Type, &klass,
|
&PyClass_Type, &klass,
|
||||||
&PyDict_Type, &dict))
|
&PyDict_Type, &dict))
|
||||||
return NULL;
|
return NULL;
|
||||||
inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type);
|
inst = PyObject_New(PyInstanceObject, &PyInstance_Type);
|
||||||
if (inst == NULL)
|
if (inst == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
Py_INCREF(klass);
|
Py_INCREF(klass);
|
||||||
|
|
|
@ -353,11 +353,11 @@ nis_maplist ()
|
||||||
if (list->stat != NIS_TRUE)
|
if (list->stat != NIS_TRUE)
|
||||||
goto finally;
|
goto finally;
|
||||||
|
|
||||||
PyMem_DEL(server);
|
free(server);
|
||||||
return list->maps;
|
return list->maps;
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
PyMem_DEL(server);
|
free(server);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -295,7 +295,7 @@ parser_compare(PyAST_Object *left, PyAST_Object *right)
|
||||||
static PyObject*
|
static PyObject*
|
||||||
parser_newastobject(node *ast, int type)
|
parser_newastobject(node *ast, int type)
|
||||||
{
|
{
|
||||||
PyAST_Object* o = PyObject_NEW(PyAST_Object, &PyAST_Type);
|
PyAST_Object* o = PyObject_New(PyAST_Object, &PyAST_Type);
|
||||||
|
|
||||||
if (o != 0) {
|
if (o != 0) {
|
||||||
o->ast_node = ast;
|
o->ast_node = ast;
|
||||||
|
@ -317,7 +317,7 @@ static void
|
||||||
parser_free(PyAST_Object *ast)
|
parser_free(PyAST_Object *ast)
|
||||||
{
|
{
|
||||||
PyNode_Free(ast->ast_node);
|
PyNode_Free(ast->ast_node);
|
||||||
PyMem_DEL(ast);
|
PyObject_Del(ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -790,10 +790,10 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
|
||||||
PyObject *temp = PySequence_GetItem(elem, 1);
|
PyObject *temp = PySequence_GetItem(elem, 1);
|
||||||
|
|
||||||
/* check_terminal_tuple() already verified it's a string */
|
/* check_terminal_tuple() already verified it's a string */
|
||||||
strn = (char *)malloc(PyString_GET_SIZE(temp) + 1);
|
strn = (char *)PyMem_MALLOC(PyString_GET_SIZE(temp) + 1);
|
||||||
if (strn != NULL)
|
if (strn != NULL)
|
||||||
(void) strcpy(strn, PyString_AS_STRING(temp));
|
(void) strcpy(strn, PyString_AS_STRING(temp));
|
||||||
Py_XDECREF(temp);
|
Py_DECREF(temp);
|
||||||
|
|
||||||
if (PyObject_Length(elem) == 3) {
|
if (PyObject_Length(elem) == 3) {
|
||||||
PyObject* temp = PySequence_GetItem(elem, 2);
|
PyObject* temp = PySequence_GetItem(elem, 2);
|
||||||
|
|
|
@ -79,7 +79,7 @@ newPcreObject(arg)
|
||||||
PyObject *arg;
|
PyObject *arg;
|
||||||
{
|
{
|
||||||
PcreObject *self;
|
PcreObject *self;
|
||||||
self = PyObject_NEW(PcreObject, &Pcre_Type);
|
self = PyObject_New(PcreObject, &Pcre_Type);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
self->regex = NULL;
|
self->regex = NULL;
|
||||||
|
@ -95,7 +95,7 @@ PyPcre_dealloc(self)
|
||||||
{
|
{
|
||||||
if (self->regex) (pcre_free)(self->regex);
|
if (self->regex) (pcre_free)(self->regex);
|
||||||
if (self->regex_extra) (pcre_free)(self->regex_extra);
|
if (self->regex_extra) (pcre_free)(self->regex_extra);
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -471,7 +471,7 @@ newxmlparseobject( char *encoding, char *namespace_separator){
|
||||||
int i;
|
int i;
|
||||||
xmlparseobject *self;
|
xmlparseobject *self;
|
||||||
|
|
||||||
self = PyObject_NEW(xmlparseobject, &Xmlparsetype);
|
self = PyObject_New(xmlparseobject, &Xmlparsetype);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -512,7 +512,7 @@ xmlparse_dealloc( xmlparseobject *self )
|
||||||
for( i=0; handler_info[i].name!=NULL; i++ ){
|
for( i=0; handler_info[i].name!=NULL; i++ ){
|
||||||
Py_XDECREF( self->handlers[i] );
|
Py_XDECREF( self->handlers[i] );
|
||||||
}
|
}
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handlername2int( const char *name ){
|
static int handlername2int( const char *name ){
|
||||||
|
|
|
@ -377,7 +377,7 @@ call_readline(prompt)
|
||||||
char *prompt;
|
char *prompt;
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
char *p;
|
char *p, *q;
|
||||||
RETSIGTYPE (*old_inthandler)();
|
RETSIGTYPE (*old_inthandler)();
|
||||||
old_inthandler = signal(SIGINT, onintr);
|
old_inthandler = signal(SIGINT, onintr);
|
||||||
if (setjmp(jbuf)) {
|
if (setjmp(jbuf)) {
|
||||||
|
@ -391,8 +391,10 @@ call_readline(prompt)
|
||||||
rl_event_hook = PyOS_InputHook;
|
rl_event_hook = PyOS_InputHook;
|
||||||
p = readline(prompt);
|
p = readline(prompt);
|
||||||
signal(SIGINT, old_inthandler);
|
signal(SIGINT, old_inthandler);
|
||||||
|
|
||||||
|
/* We must return a buffer allocated with PyMem_Malloc. */
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
p = malloc(1);
|
p = PyMem_Malloc(1);
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
return p;
|
return p;
|
||||||
|
@ -400,10 +402,16 @@ call_readline(prompt)
|
||||||
n = strlen(p);
|
n = strlen(p);
|
||||||
if (n > 0)
|
if (n > 0)
|
||||||
add_history(p);
|
add_history(p);
|
||||||
if ((p = realloc(p, n+2)) != NULL) {
|
/* Copy the malloc'ed buffer into a PyMem_Malloc'ed one and
|
||||||
|
release the original. */
|
||||||
|
q = p;
|
||||||
|
p = PyMem_Malloc(n+2);
|
||||||
|
if (p != NULL) {
|
||||||
|
strncpy(p, q, n);
|
||||||
p[n] = '\n';
|
p[n] = '\n';
|
||||||
p[n+1] = '\0';
|
p[n+1] = '\0';
|
||||||
}
|
}
|
||||||
|
free(q);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,13 +64,14 @@ static void
|
||||||
reg_dealloc(re)
|
reg_dealloc(re)
|
||||||
regexobject *re;
|
regexobject *re;
|
||||||
{
|
{
|
||||||
PyMem_XDEL(re->re_patbuf.buffer);
|
if (re->re_patbuf.buffer)
|
||||||
|
PyMem_DEL(re->re_patbuf.buffer);
|
||||||
Py_XDECREF(re->re_translate);
|
Py_XDECREF(re->re_translate);
|
||||||
Py_XDECREF(re->re_lastok);
|
Py_XDECREF(re->re_lastok);
|
||||||
Py_XDECREF(re->re_groupindex);
|
Py_XDECREF(re->re_groupindex);
|
||||||
Py_XDECREF(re->re_givenpat);
|
Py_XDECREF(re->re_givenpat);
|
||||||
Py_XDECREF(re->re_realpat);
|
Py_XDECREF(re->re_realpat);
|
||||||
PyMem_DEL(re);
|
PyObject_Del(re);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -418,7 +419,7 @@ newregexobject(pattern, translate, givenpat, groupindex)
|
||||||
"translation table must be 256 bytes");
|
"translation table must be 256 bytes");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
re = PyObject_NEW(regexobject, &Regextype);
|
re = PyObject_New(regexobject, &Regextype);
|
||||||
if (re != NULL) {
|
if (re != NULL) {
|
||||||
char *error;
|
char *error;
|
||||||
re->re_patbuf.buffer = NULL;
|
re->re_patbuf.buffer = NULL;
|
||||||
|
|
|
@ -178,7 +178,7 @@ rotorobj_new(num_rotors, key)
|
||||||
{
|
{
|
||||||
Rotorobj *xp;
|
Rotorobj *xp;
|
||||||
|
|
||||||
xp = PyObject_NEW(Rotorobj, &Rotor_Type);
|
xp = PyObject_New(Rotorobj, &Rotor_Type);
|
||||||
if (xp == NULL)
|
if (xp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
set_key(xp, key);
|
set_key(xp, key);
|
||||||
|
@ -204,10 +204,14 @@ rotorobj_new(num_rotors, key)
|
||||||
return xp;
|
return xp;
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
PyMem_XDEL(xp->e_rotor);
|
if (xp->e_rotor)
|
||||||
PyMem_XDEL(xp->d_rotor);
|
PyMem_DEL(xp->e_rotor);
|
||||||
PyMem_XDEL(xp->positions);
|
if (xp->d_rotor)
|
||||||
PyMem_XDEL(xp->advances);
|
PyMem_DEL(xp->d_rotor);
|
||||||
|
if (xp->positions)
|
||||||
|
PyMem_DEL(xp->positions);
|
||||||
|
if (xp->advances)
|
||||||
|
PyMem_DEL(xp->advances);
|
||||||
Py_DECREF(xp);
|
Py_DECREF(xp);
|
||||||
return (Rotorobj*)PyErr_NoMemory();
|
return (Rotorobj*)PyErr_NoMemory();
|
||||||
}
|
}
|
||||||
|
@ -473,11 +477,15 @@ static void
|
||||||
rotor_dealloc(xp)
|
rotor_dealloc(xp)
|
||||||
Rotorobj *xp;
|
Rotorobj *xp;
|
||||||
{
|
{
|
||||||
PyMem_XDEL(xp->e_rotor);
|
if (xp->e_rotor)
|
||||||
PyMem_XDEL(xp->d_rotor);
|
PyMem_DEL(xp->e_rotor);
|
||||||
PyMem_XDEL(xp->positions);
|
if (xp->d_rotor)
|
||||||
PyMem_XDEL(xp->advances);
|
PyMem_DEL(xp->d_rotor);
|
||||||
PyMem_DEL(xp);
|
if (xp->positions)
|
||||||
|
PyMem_DEL(xp->positions);
|
||||||
|
if (xp->advances)
|
||||||
|
PyMem_DEL(xp->advances);
|
||||||
|
PyObject_Del(xp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -278,9 +278,9 @@ select_select(self, args)
|
||||||
wfd2obj = PyMem_NEW(pylist, FD_SETSIZE + 3);
|
wfd2obj = PyMem_NEW(pylist, FD_SETSIZE + 3);
|
||||||
efd2obj = PyMem_NEW(pylist, FD_SETSIZE + 3);
|
efd2obj = PyMem_NEW(pylist, FD_SETSIZE + 3);
|
||||||
if (rfd2obj == NULL || wfd2obj == NULL || efd2obj == NULL) {
|
if (rfd2obj == NULL || wfd2obj == NULL || efd2obj == NULL) {
|
||||||
PyMem_XDEL(rfd2obj);
|
if (rfd2obj) PyMem_DEL(rfd2obj);
|
||||||
PyMem_XDEL(wfd2obj);
|
if (wfd2obj) PyMem_DEL(wfd2obj);
|
||||||
PyMem_XDEL(efd2obj);
|
if (efd2obj) PyMem_DEL(efd2obj);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -380,7 +380,7 @@ staticforward PyTypeObject SHAtype;
|
||||||
static SHAobject *
|
static SHAobject *
|
||||||
newSHAobject()
|
newSHAobject()
|
||||||
{
|
{
|
||||||
return (SHAobject *)PyObject_NEW(SHAobject, &SHAtype);
|
return (SHAobject *)PyObject_New(SHAobject, &SHAtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Internal methods for a hashing object */
|
/* Internal methods for a hashing object */
|
||||||
|
@ -389,7 +389,7 @@ static void
|
||||||
SHA_dealloc(ptr)
|
SHA_dealloc(ptr)
|
||||||
PyObject *ptr;
|
PyObject *ptr;
|
||||||
{
|
{
|
||||||
PyMem_DEL(ptr);
|
PyObject_Del(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -389,7 +389,7 @@ BUILD_FUNC_DEF_4(PySocketSock_New,int,fd, int,family, int,type, int,proto)
|
||||||
{
|
{
|
||||||
PySocketSockObject *s;
|
PySocketSockObject *s;
|
||||||
PySocketSock_Type.ob_type = &PyType_Type;
|
PySocketSock_Type.ob_type = &PyType_Type;
|
||||||
s = PyObject_NEW(PySocketSockObject, &PySocketSock_Type);
|
s = PyObject_New(PySocketSockObject, &PySocketSock_Type);
|
||||||
if (s != NULL) {
|
if (s != NULL) {
|
||||||
s->sock_fd = fd;
|
s->sock_fd = fd;
|
||||||
s->sock_family = family;
|
s->sock_family = family;
|
||||||
|
@ -1368,7 +1368,7 @@ BUILD_FUNC_DEF_1(PySocketSock_dealloc,PySocketSockObject *,s)
|
||||||
{
|
{
|
||||||
if (s->sock_fd != -1)
|
if (s->sock_fd != -1)
|
||||||
(void) SOCKETCLOSE(s->sock_fd);
|
(void) SOCKETCLOSE(s->sock_fd);
|
||||||
PyMem_DEL(s);
|
PyObject_Del(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1948,7 +1948,7 @@ BUILD_FUNC_DEF_3(newSSLObject,
|
||||||
meth=SSLv2_client_method();
|
meth=SSLv2_client_method();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
self = PyObject_NEW(SSLObject, &SSL_Type); /* Create new object */
|
self = PyObject_New(SSLObject, &SSL_Type); /* Create new object */
|
||||||
if (self == NULL){
|
if (self == NULL){
|
||||||
PyErr_SetObject(SSLErrorObject,
|
PyErr_SetObject(SSLErrorObject,
|
||||||
PyString_FromString("newSSLObject error"));
|
PyString_FromString("newSSLObject error"));
|
||||||
|
@ -1962,7 +1962,7 @@ BUILD_FUNC_DEF_3(newSSLObject,
|
||||||
if (self->ctx == NULL) {
|
if (self->ctx == NULL) {
|
||||||
PyErr_SetObject(SSLErrorObject,
|
PyErr_SetObject(SSLErrorObject,
|
||||||
PyString_FromString("SSL_CTX_new error"));
|
PyString_FromString("SSL_CTX_new error"));
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1971,7 +1971,7 @@ BUILD_FUNC_DEF_3(newSSLObject,
|
||||||
PyErr_SetObject(SSLErrorObject,
|
PyErr_SetObject(SSLErrorObject,
|
||||||
PyString_FromString(
|
PyString_FromString(
|
||||||
"Both the key & certificate files must be specified"));
|
"Both the key & certificate files must be specified"));
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1983,7 +1983,7 @@ BUILD_FUNC_DEF_3(newSSLObject,
|
||||||
PyErr_SetObject(SSLErrorObject,
|
PyErr_SetObject(SSLErrorObject,
|
||||||
PyString_FromString(
|
PyString_FromString(
|
||||||
"SSL_CTX_use_PrivateKey_file error"));
|
"SSL_CTX_use_PrivateKey_file error"));
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1993,7 +1993,7 @@ BUILD_FUNC_DEF_3(newSSLObject,
|
||||||
PyErr_SetObject(SSLErrorObject,
|
PyErr_SetObject(SSLErrorObject,
|
||||||
PyString_FromString(
|
PyString_FromString(
|
||||||
"SSL_CTX_use_certificate_chain_file error"));
|
"SSL_CTX_use_certificate_chain_file error"));
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2008,7 +2008,7 @@ BUILD_FUNC_DEF_3(newSSLObject,
|
||||||
/* Actually negotiate SSL connection */
|
/* Actually negotiate SSL connection */
|
||||||
PyErr_SetObject(SSLErrorObject,
|
PyErr_SetObject(SSLErrorObject,
|
||||||
PyString_FromString("SSL_connect error"));
|
PyString_FromString("SSL_connect error"));
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
self->ssl->debug = 1;
|
self->ssl->debug = 1;
|
||||||
|
@ -2079,7 +2079,7 @@ static void SSL_dealloc(SSLObject *self)
|
||||||
SSL_free(self->ssl);
|
SSL_free(self->ssl);
|
||||||
Py_XDECREF(self->x_attr);
|
Py_XDECREF(self->x_attr);
|
||||||
Py_XDECREF(self->Socket);
|
Py_XDECREF(self->Socket);
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *SSL_getattr(SSLObject *self, char *name)
|
static PyObject *SSL_getattr(SSLObject *self, char *name)
|
||||||
|
|
|
@ -1152,7 +1152,7 @@ static char *mymemreplace(str, len, pat, pat_len, sub, sub_len, count, out_len)
|
||||||
goto return_same;
|
goto return_same;
|
||||||
new_len = len + nfound*(sub_len - pat_len);
|
new_len = len + nfound*(sub_len - pat_len);
|
||||||
|
|
||||||
new_s = (char *)malloc(new_len);
|
new_s = (char *)PyMem_MALLOC(new_len);
|
||||||
if (new_s == NULL) return NULL;
|
if (new_s == NULL) return NULL;
|
||||||
|
|
||||||
*out_len = new_len;
|
*out_len = new_len;
|
||||||
|
@ -1225,7 +1225,7 @@ strop_replace(self, args)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
new = PyString_FromStringAndSize(new_s, out_len);
|
new = PyString_FromStringAndSize(new_s, out_len);
|
||||||
free(new_s);
|
PyMem_FREE(new_s);
|
||||||
}
|
}
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,7 +139,7 @@ newsadobject(arg)
|
||||||
PyMem_DEL(ctldev);
|
PyMem_DEL(ctldev);
|
||||||
|
|
||||||
/* Create and initialize the object */
|
/* Create and initialize the object */
|
||||||
xp = PyObject_NEW(sadobject, &Sadtype);
|
xp = PyObject_New(sadobject, &Sadtype);
|
||||||
if (xp == NULL) {
|
if (xp == NULL) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -158,7 +158,7 @@ sad_dealloc(xp)
|
||||||
sadobject *xp;
|
sadobject *xp;
|
||||||
{
|
{
|
||||||
close(xp->x_fd);
|
close(xp->x_fd);
|
||||||
PyMem_DEL(xp);
|
PyObject_Del(xp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -412,7 +412,7 @@ sad_getattr(xp, name)
|
||||||
|
|
||||||
static sadstatusobject *
|
static sadstatusobject *
|
||||||
sads_alloc() {
|
sads_alloc() {
|
||||||
return PyObject_NEW(sadstatusobject, &Sadstatustype);
|
return PyObject_New(sadstatusobject, &Sadstatustype);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -340,7 +340,7 @@ capture_dealloc(self)
|
||||||
Py_DECREF(self->ob_svideo);
|
Py_DECREF(self->ob_svideo);
|
||||||
self->ob_svideo = NULL;
|
self->ob_svideo = NULL;
|
||||||
}
|
}
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -374,7 +374,7 @@ newcaptureobject(self, ptr, mustunlock)
|
||||||
{
|
{
|
||||||
captureobject *p;
|
captureobject *p;
|
||||||
|
|
||||||
p = PyObject_NEW(captureobject, &Capturetype);
|
p = PyObject_New(captureobject, &Capturetype);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
p->ob_svideo = self;
|
p->ob_svideo = self;
|
||||||
|
@ -994,7 +994,7 @@ svideo_dealloc(self)
|
||||||
{
|
{
|
||||||
if (self->ob_svideo != NULL)
|
if (self->ob_svideo != NULL)
|
||||||
(void) svCloseVideo(self->ob_svideo);
|
(void) svCloseVideo(self->ob_svideo);
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -1026,7 +1026,7 @@ newsvobject(svp)
|
||||||
{
|
{
|
||||||
svobject *p;
|
svobject *p;
|
||||||
|
|
||||||
p = PyObject_NEW(svobject, &Svtype);
|
p = PyObject_New(svobject, &Svtype);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
p->ob_svideo = svp;
|
p->ob_svideo = svp;
|
||||||
|
|
|
@ -58,12 +58,12 @@ static lockobject *
|
||||||
newlockobject()
|
newlockobject()
|
||||||
{
|
{
|
||||||
lockobject *self;
|
lockobject *self;
|
||||||
self = PyObject_NEW(lockobject, &Locktype);
|
self = PyObject_New(lockobject, &Locktype);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
self->lock_lock = PyThread_allocate_lock();
|
self->lock_lock = PyThread_allocate_lock();
|
||||||
if (self->lock_lock == NULL) {
|
if (self->lock_lock == NULL) {
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
self = NULL;
|
self = NULL;
|
||||||
PyErr_SetString(ThreadError, "can't allocate lock");
|
PyErr_SetString(ThreadError, "can't allocate lock");
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ lock_dealloc(self)
|
||||||
PyThread_release_lock(self->lock_lock);
|
PyThread_release_lock(self->lock_lock);
|
||||||
|
|
||||||
PyThread_free_lock(self->lock_lock);
|
PyThread_free_lock(self->lock_lock);
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -62,7 +62,7 @@ newXxoObject(arg)
|
||||||
PyObject *arg;
|
PyObject *arg;
|
||||||
{
|
{
|
||||||
XxoObject *self;
|
XxoObject *self;
|
||||||
self = PyObject_NEW(XxoObject, &Xxo_Type);
|
self = PyObject_New(XxoObject, &Xxo_Type);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
self->x_attr = NULL;
|
self->x_attr = NULL;
|
||||||
|
@ -76,7 +76,7 @@ Xxo_dealloc(self)
|
||||||
XxoObject *self;
|
XxoObject *self;
|
||||||
{
|
{
|
||||||
Py_XDECREF(self->x_attr);
|
Py_XDECREF(self->x_attr);
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -46,7 +46,7 @@ newcompobject(type)
|
||||||
PyTypeObject *type;
|
PyTypeObject *type;
|
||||||
{
|
{
|
||||||
compobject *self;
|
compobject *self;
|
||||||
self = PyObject_NEW(compobject, type);
|
self = PyObject_New(compobject, type);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
self->is_initialised = 0;
|
self->is_initialised = 0;
|
||||||
|
@ -369,7 +369,7 @@ Comp_dealloc(self)
|
||||||
if (self->is_initialised)
|
if (self->is_initialised)
|
||||||
deflateEnd(&self->zst);
|
deflateEnd(&self->zst);
|
||||||
Py_XDECREF(self->unused_data);
|
Py_XDECREF(self->unused_data);
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -378,7 +378,7 @@ Decomp_dealloc(self)
|
||||||
{
|
{
|
||||||
inflateEnd(&self->zst);
|
inflateEnd(&self->zst);
|
||||||
Py_XDECREF(self->unused_data);
|
Py_XDECREF(self->unused_data);
|
||||||
PyMem_DEL(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char comp_compress__doc__[] =
|
static char comp_compress__doc__[] =
|
||||||
|
|
|
@ -188,11 +188,11 @@ PyBuffer_New(size)
|
||||||
"size must be zero or positive");
|
"size must be zero or positive");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
b = (PyBufferObject *)malloc(sizeof(*b) + size);
|
/* PyObject_New is inlined */
|
||||||
|
b = (PyBufferObject *) PyObject_MALLOC(sizeof(*b) + size);
|
||||||
if ( b == NULL )
|
if ( b == NULL )
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
b->ob_type = &PyBuffer_Type;
|
PyObject_INIT((PyObject *)b, &PyBuffer_Type);
|
||||||
_Py_NewReference((PyObject *)b);
|
|
||||||
|
|
||||||
b->b_base = NULL;
|
b->b_base = NULL;
|
||||||
b->b_ptr = (void *)(b + 1);
|
b->b_ptr = (void *)(b + 1);
|
||||||
|
@ -212,7 +212,7 @@ buffer_dealloc(self)
|
||||||
PyBufferObject *self;
|
PyBufferObject *self;
|
||||||
{
|
{
|
||||||
Py_XDECREF(self->b_base);
|
Py_XDECREF(self->b_base);
|
||||||
free((void *)self);
|
PyObject_DEL(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
@ -147,7 +147,7 @@ class_dealloc(op)
|
||||||
Py_XDECREF(op->cl_getattr);
|
Py_XDECREF(op->cl_getattr);
|
||||||
Py_XDECREF(op->cl_setattr);
|
Py_XDECREF(op->cl_setattr);
|
||||||
Py_XDECREF(op->cl_delattr);
|
Py_XDECREF(op->cl_delattr);
|
||||||
free((ANY *)op);
|
PyObject_DEL(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -561,7 +561,7 @@ instance_dealloc(inst)
|
||||||
#endif /* Py_TRACE_REFS */
|
#endif /* Py_TRACE_REFS */
|
||||||
Py_DECREF(inst->in_class);
|
Py_DECREF(inst->in_class);
|
||||||
Py_XDECREF(inst->in_dict);
|
Py_XDECREF(inst->in_dict);
|
||||||
free((ANY *)inst);
|
PyObject_DEL(inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -1498,8 +1498,7 @@ PyMethod_New(func, self, class)
|
||||||
im = free_list;
|
im = free_list;
|
||||||
if (im != NULL) {
|
if (im != NULL) {
|
||||||
free_list = (PyMethodObject *)(im->im_self);
|
free_list = (PyMethodObject *)(im->im_self);
|
||||||
im->ob_type = &PyMethod_Type;
|
PyObject_INIT(im, &PyMethod_Type);
|
||||||
_Py_NewReference((PyObject *)im);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
im = PyObject_NEW(PyMethodObject, &PyMethod_Type);
|
im = PyObject_NEW(PyMethodObject, &PyMethod_Type);
|
||||||
|
@ -1691,8 +1690,8 @@ void
|
||||||
PyMethod_Fini()
|
PyMethod_Fini()
|
||||||
{
|
{
|
||||||
while (free_list) {
|
while (free_list) {
|
||||||
PyMethodObject *v = free_list;
|
PyMethodObject *im = free_list;
|
||||||
free_list = (PyMethodObject *)(v->im_self);
|
free_list = (PyMethodObject *)(im->im_self);
|
||||||
PyMem_DEL(v);
|
PyObject_DEL(im);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,7 +151,7 @@ PyCObject_dealloc(self)
|
||||||
else
|
else
|
||||||
(self->destructor)(self->cobject);
|
(self->destructor)(self->cobject);
|
||||||
}
|
}
|
||||||
PyMem_DEL(self);
|
PyObject_DEL(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -166,13 +166,14 @@ PyObject *
|
||||||
PyComplex_FromCComplex(cval)
|
PyComplex_FromCComplex(cval)
|
||||||
Py_complex cval;
|
Py_complex cval;
|
||||||
{
|
{
|
||||||
register PyComplexObject *op =
|
register PyComplexObject *op;
|
||||||
(PyComplexObject *) malloc(sizeof(PyComplexObject));
|
|
||||||
|
/* PyObject_New is inlined */
|
||||||
|
op = (PyComplexObject *) PyObject_MALLOC(sizeof(PyComplexObject));
|
||||||
if (op == NULL)
|
if (op == NULL)
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
op->ob_type = &PyComplex_Type;
|
PyObject_INIT(op, &PyComplex_Type);
|
||||||
op->cval = cval;
|
op->cval = cval;
|
||||||
_Py_NewReference((PyObject *)op);
|
|
||||||
return (PyObject *) op;
|
return (PyObject *) op;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +227,7 @@ static void
|
||||||
complex_dealloc(op)
|
complex_dealloc(op)
|
||||||
PyObject *op;
|
PyObject *op;
|
||||||
{
|
{
|
||||||
PyMem_DEL(op);
|
PyObject_DEL(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -277,7 +277,7 @@ dictresize(mp, minused)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newtable = (dictentry *) malloc(sizeof(dictentry) * newsize);
|
newtable = PyMem_NEW(dictentry, newsize);
|
||||||
if (newtable == NULL) {
|
if (newtable == NULL) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -301,7 +301,8 @@ dictresize(mp, minused)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PyMem_XDEL(oldtable);
|
if (oldtable != NULL)
|
||||||
|
PyMem_DEL(oldtable);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -488,8 +489,9 @@ dict_dealloc(mp)
|
||||||
Py_DECREF(ep->me_value);
|
Py_DECREF(ep->me_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PyMem_XDEL(mp->ma_table);
|
if (mp->ma_table != NULL)
|
||||||
PyMem_DEL(mp);
|
PyMem_DEL(mp->ma_table);
|
||||||
|
PyObject_DEL(mp);
|
||||||
Py_TRASHCAN_SAFE_END(mp)
|
Py_TRASHCAN_SAFE_END(mp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -215,7 +215,7 @@ file_dealloc(f)
|
||||||
if (f->f_mode != NULL) {
|
if (f->f_mode != NULL) {
|
||||||
Py_DECREF(f->f_mode);
|
Py_DECREF(f->f_mode);
|
||||||
}
|
}
|
||||||
free((char *)f);
|
PyObject_DEL(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -98,9 +98,6 @@ double (*_Py_math_funcs_hack[])() = {
|
||||||
#define BHEAD_SIZE 8 /* Enough for a 64-bit pointer */
|
#define BHEAD_SIZE 8 /* Enough for a 64-bit pointer */
|
||||||
#define N_FLOATOBJECTS ((BLOCK_SIZE - BHEAD_SIZE) / sizeof(PyFloatObject))
|
#define N_FLOATOBJECTS ((BLOCK_SIZE - BHEAD_SIZE) / sizeof(PyFloatObject))
|
||||||
|
|
||||||
#define PyMem_MALLOC malloc
|
|
||||||
#define PyMem_FREE free
|
|
||||||
|
|
||||||
struct _floatblock {
|
struct _floatblock {
|
||||||
struct _floatblock *next;
|
struct _floatblock *next;
|
||||||
PyFloatObject objects[N_FLOATOBJECTS];
|
PyFloatObject objects[N_FLOATOBJECTS];
|
||||||
|
@ -115,6 +112,7 @@ static PyFloatObject *
|
||||||
fill_free_list()
|
fill_free_list()
|
||||||
{
|
{
|
||||||
PyFloatObject *p, *q;
|
PyFloatObject *p, *q;
|
||||||
|
/* XXX Float blocks escape the object heap. Use PyObject_MALLOC ??? */
|
||||||
p = (PyFloatObject *) PyMem_MALLOC(sizeof(PyFloatBlock));
|
p = (PyFloatObject *) PyMem_MALLOC(sizeof(PyFloatBlock));
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return (PyFloatObject *) PyErr_NoMemory();
|
return (PyFloatObject *) PyErr_NoMemory();
|
||||||
|
@ -141,11 +139,11 @@ PyFloat_FromDouble(fval)
|
||||||
if ((free_list = fill_free_list()) == NULL)
|
if ((free_list = fill_free_list()) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
/* PyObject_New is inlined */
|
||||||
op = free_list;
|
op = free_list;
|
||||||
free_list = (PyFloatObject *)op->ob_type;
|
free_list = (PyFloatObject *)op->ob_type;
|
||||||
op->ob_type = &PyFloat_Type;
|
PyObject_INIT(op, &PyFloat_Type);
|
||||||
op->ob_fval = fval;
|
op->ob_fval = fval;
|
||||||
_Py_NewReference((PyObject *)op);
|
|
||||||
return (PyObject *) op;
|
return (PyObject *) op;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -779,7 +777,7 @@ PyFloat_Fini()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyMem_FREE(list);
|
PyMem_FREE(list); /* XXX PyObject_FREE ??? */
|
||||||
bf++;
|
bf++;
|
||||||
}
|
}
|
||||||
fsum += frem;
|
fsum += frem;
|
||||||
|
|
|
@ -180,28 +180,27 @@ PyFrame_New(tstate, code, globals, locals)
|
||||||
if (builtins != NULL && !PyDict_Check(builtins))
|
if (builtins != NULL && !PyDict_Check(builtins))
|
||||||
builtins = NULL;
|
builtins = NULL;
|
||||||
if (free_list == NULL) {
|
if (free_list == NULL) {
|
||||||
|
/* PyObject_New is inlined */
|
||||||
f = (PyFrameObject *)
|
f = (PyFrameObject *)
|
||||||
malloc(sizeof(PyFrameObject) +
|
PyObject_MALLOC(sizeof(PyFrameObject) +
|
||||||
extras*sizeof(PyObject *));
|
extras*sizeof(PyObject *));
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
return (PyFrameObject *)PyErr_NoMemory();
|
return (PyFrameObject *)PyErr_NoMemory();
|
||||||
f->ob_type = &PyFrame_Type;
|
PyObject_INIT(f, &PyFrame_Type);
|
||||||
_Py_NewReference((PyObject *)f);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
f = free_list;
|
f = free_list;
|
||||||
free_list = free_list->f_back;
|
free_list = free_list->f_back;
|
||||||
if (f->f_nlocals + f->f_stacksize < extras) {
|
if (f->f_nlocals + f->f_stacksize < extras) {
|
||||||
f = (PyFrameObject *)
|
f = (PyFrameObject *)
|
||||||
realloc(f, sizeof(PyFrameObject) +
|
PyObject_REALLOC(f, sizeof(PyFrameObject) +
|
||||||
extras*sizeof(PyObject *));
|
extras*sizeof(PyObject *));
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
return (PyFrameObject *)PyErr_NoMemory();
|
return (PyFrameObject *)PyErr_NoMemory();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
extras = f->f_nlocals + f->f_stacksize;
|
extras = f->f_nlocals + f->f_stacksize;
|
||||||
f->ob_type = &PyFrame_Type;
|
PyObject_INIT(f, &PyFrame_Type);
|
||||||
_Py_NewReference((PyObject *)f);
|
|
||||||
}
|
}
|
||||||
if (builtins == NULL) {
|
if (builtins == NULL) {
|
||||||
/* No builtins! Make up a minimal one. */
|
/* No builtins! Make up a minimal one. */
|
||||||
|
@ -376,6 +375,6 @@ PyFrame_Fini()
|
||||||
while (free_list != NULL) {
|
while (free_list != NULL) {
|
||||||
PyFrameObject *f = free_list;
|
PyFrameObject *f = free_list;
|
||||||
free_list = free_list->f_back;
|
free_list = free_list->f_back;
|
||||||
PyMem_DEL(f);
|
PyObject_DEL(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,7 +191,7 @@ func_dealloc(op)
|
||||||
Py_DECREF(op->func_name);
|
Py_DECREF(op->func_name);
|
||||||
Py_XDECREF(op->func_defaults);
|
Py_XDECREF(op->func_defaults);
|
||||||
Py_XDECREF(op->func_doc);
|
Py_XDECREF(op->func_doc);
|
||||||
PyMem_DEL(op);
|
PyObject_DEL(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
|
|
|
@ -94,9 +94,6 @@ err_ovf(msg)
|
||||||
#define BHEAD_SIZE 8 /* Enough for a 64-bit pointer */
|
#define BHEAD_SIZE 8 /* Enough for a 64-bit pointer */
|
||||||
#define N_INTOBJECTS ((BLOCK_SIZE - BHEAD_SIZE) / sizeof(PyIntObject))
|
#define N_INTOBJECTS ((BLOCK_SIZE - BHEAD_SIZE) / sizeof(PyIntObject))
|
||||||
|
|
||||||
#define PyMem_MALLOC malloc
|
|
||||||
#define PyMem_FREE free
|
|
||||||
|
|
||||||
struct _intblock {
|
struct _intblock {
|
||||||
struct _intblock *next;
|
struct _intblock *next;
|
||||||
PyIntObject objects[N_INTOBJECTS];
|
PyIntObject objects[N_INTOBJECTS];
|
||||||
|
@ -111,6 +108,7 @@ static PyIntObject *
|
||||||
fill_free_list()
|
fill_free_list()
|
||||||
{
|
{
|
||||||
PyIntObject *p, *q;
|
PyIntObject *p, *q;
|
||||||
|
/* XXX Int blocks escape the object heap. Use PyObject_MALLOC ??? */
|
||||||
p = (PyIntObject *) PyMem_MALLOC(sizeof(PyIntBlock));
|
p = (PyIntObject *) PyMem_MALLOC(sizeof(PyIntBlock));
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return (PyIntObject *) PyErr_NoMemory();
|
return (PyIntObject *) PyErr_NoMemory();
|
||||||
|
@ -164,11 +162,11 @@ PyInt_FromLong(ival)
|
||||||
if ((free_list = fill_free_list()) == NULL)
|
if ((free_list = fill_free_list()) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
/* PyObject_New is inlined */
|
||||||
v = free_list;
|
v = free_list;
|
||||||
free_list = (PyIntObject *)v->ob_type;
|
free_list = (PyIntObject *)v->ob_type;
|
||||||
v->ob_type = &PyInt_Type;
|
PyObject_INIT(v, &PyInt_Type);
|
||||||
v->ob_ival = ival;
|
v->ob_ival = ival;
|
||||||
_Py_NewReference((PyObject *)v);
|
|
||||||
#if NSMALLNEGINTS + NSMALLPOSINTS > 0
|
#if NSMALLNEGINTS + NSMALLPOSINTS > 0
|
||||||
if (-NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS) {
|
if (-NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS) {
|
||||||
/* save this one for a following allocation */
|
/* save this one for a following allocation */
|
||||||
|
@ -933,7 +931,7 @@ PyInt_Fini()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyMem_FREE(list);
|
PyMem_FREE(list); /* XXX PyObject_FREE ??? */
|
||||||
bf++;
|
bf++;
|
||||||
}
|
}
|
||||||
isum += irem;
|
isum += irem;
|
||||||
|
|
|
@ -70,7 +70,8 @@ PyList_New(size)
|
||||||
if (nbytes / sizeof(PyObject *) != (size_t)size) {
|
if (nbytes / sizeof(PyObject *) != (size_t)size) {
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
}
|
}
|
||||||
op = (PyListObject *) malloc(sizeof(PyListObject));
|
/* PyObject_NewVar is inlined */
|
||||||
|
op = (PyListObject *) PyObject_MALLOC(sizeof(PyListObject));
|
||||||
if (op == NULL) {
|
if (op == NULL) {
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
}
|
}
|
||||||
|
@ -78,17 +79,15 @@ PyList_New(size)
|
||||||
op->ob_item = NULL;
|
op->ob_item = NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
op->ob_item = (PyObject **) malloc(nbytes);
|
op->ob_item = (PyObject **) PyMem_MALLOC(nbytes);
|
||||||
if (op->ob_item == NULL) {
|
if (op->ob_item == NULL) {
|
||||||
free((ANY *)op);
|
PyObject_FREE(op);
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
op->ob_type = &PyList_Type;
|
PyObject_INIT_VAR(op, &PyList_Type, size);
|
||||||
op->ob_size = size;
|
|
||||||
for (i = 0; i < size; i++)
|
for (i = 0; i < size; i++)
|
||||||
op->ob_item[i] = NULL;
|
op->ob_item[i] = NULL;
|
||||||
_Py_NewReference((PyObject *)op);
|
|
||||||
return (PyObject *) op;
|
return (PyObject *) op;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,9 +224,9 @@ list_dealloc(op)
|
||||||
while (--i >= 0) {
|
while (--i >= 0) {
|
||||||
Py_XDECREF(op->ob_item[i]);
|
Py_XDECREF(op->ob_item[i]);
|
||||||
}
|
}
|
||||||
free((ANY *)op->ob_item);
|
PyMem_FREE(op->ob_item);
|
||||||
}
|
}
|
||||||
free((ANY *)op);
|
PyObject_DEL(op);
|
||||||
Py_TRASHCAN_SAFE_END(op)
|
Py_TRASHCAN_SAFE_END(op)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -501,7 +500,8 @@ list_ass_slice(a, ilow, ihigh, v)
|
||||||
else { /* Insert d items; recycle ihigh-ilow items */
|
else { /* Insert d items; recycle ihigh-ilow items */
|
||||||
NRESIZE(item, PyObject *, a->ob_size + d);
|
NRESIZE(item, PyObject *, a->ob_size + d);
|
||||||
if (item == NULL) {
|
if (item == NULL) {
|
||||||
PyMem_XDEL(recycle);
|
if (recycle != NULL)
|
||||||
|
PyMem_DEL(recycle);
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -995,7 +995,7 @@ static void
|
||||||
long_dealloc(v)
|
long_dealloc(v)
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
{
|
{
|
||||||
PyMem_DEL(v);
|
PyObject_DEL(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -46,8 +46,7 @@ PyCFunction_New(ml, self)
|
||||||
op = free_list;
|
op = free_list;
|
||||||
if (op != NULL) {
|
if (op != NULL) {
|
||||||
free_list = (PyCFunctionObject *)(op->m_self);
|
free_list = (PyCFunctionObject *)(op->m_self);
|
||||||
op->ob_type = &PyCFunction_Type;
|
PyObject_INIT(op, &PyCFunction_Type);
|
||||||
_Py_NewReference((PyObject *)op);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
op = PyObject_NEW(PyCFunctionObject, &PyCFunction_Type);
|
op = PyObject_NEW(PyCFunctionObject, &PyCFunction_Type);
|
||||||
|
@ -288,6 +287,6 @@ PyCFunction_Fini()
|
||||||
while (free_list) {
|
while (free_list) {
|
||||||
PyCFunctionObject *v = free_list;
|
PyCFunctionObject *v = free_list;
|
||||||
free_list = (PyCFunctionObject *)(v->m_self);
|
free_list = (PyCFunctionObject *)(v->m_self);
|
||||||
PyMem_DEL(v);
|
PyObject_DEL(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,7 @@ module_dealloc(m)
|
||||||
_PyModule_Clear((PyObject *)m);
|
_PyModule_Clear((PyObject *)m);
|
||||||
Py_DECREF(m->md_dict);
|
Py_DECREF(m->md_dict);
|
||||||
}
|
}
|
||||||
free((char *)m);
|
PyObject_DEL(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
156
Objects/object.c
156
Objects/object.c
|
@ -112,50 +112,68 @@ inc_count(tp)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MS_COREDLL
|
|
||||||
PyObject *
|
PyObject *
|
||||||
_PyObject_New(tp)
|
PyObject_Init(op, tp)
|
||||||
PyTypeObject *tp;
|
|
||||||
#else
|
|
||||||
PyObject *
|
|
||||||
_PyObject_New(tp,op)
|
|
||||||
PyTypeObject *tp;
|
|
||||||
PyObject *op;
|
PyObject *op;
|
||||||
#endif
|
PyTypeObject *tp;
|
||||||
{
|
{
|
||||||
#ifndef MS_COREDLL
|
if (op == NULL) {
|
||||||
PyObject *op = (PyObject *) malloc(tp->tp_basicsize);
|
PyErr_SetString(PyExc_SystemError,
|
||||||
#endif
|
"NULL object passed to PyObject_Init");
|
||||||
if (op == NULL)
|
return op;
|
||||||
return PyErr_NoMemory();
|
}
|
||||||
|
/* Any changes should be reflected in PyObject_INIT (objimpl.h) */
|
||||||
op->ob_type = tp;
|
op->ob_type = tp;
|
||||||
_Py_NewReference(op);
|
_Py_NewReference(op);
|
||||||
return op;
|
return op;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef MS_COREDLL
|
PyVarObject *
|
||||||
|
PyObject_InitVar(op, tp, size)
|
||||||
|
PyVarObject *op;
|
||||||
|
PyTypeObject *tp;
|
||||||
|
int size;
|
||||||
|
{
|
||||||
|
if (op == NULL) {
|
||||||
|
PyErr_SetString(PyExc_SystemError,
|
||||||
|
"NULL object passed to PyObject_InitVar");
|
||||||
|
return op;
|
||||||
|
}
|
||||||
|
/* Any changes should be reflected in PyObject_INIT_VAR */
|
||||||
|
op->ob_size = size;
|
||||||
|
op->ob_type = tp;
|
||||||
|
_Py_NewReference((PyObject *)op);
|
||||||
|
return op;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
_PyObject_New(tp)
|
||||||
|
PyTypeObject *tp;
|
||||||
|
{
|
||||||
|
PyObject *op;
|
||||||
|
op = (PyObject *) PyObject_MALLOC(_PyObject_SIZE(tp));
|
||||||
|
if (op == NULL)
|
||||||
|
return PyErr_NoMemory();
|
||||||
|
return PyObject_INIT(op, tp);
|
||||||
|
}
|
||||||
|
|
||||||
PyVarObject *
|
PyVarObject *
|
||||||
_PyObject_NewVar(tp, size)
|
_PyObject_NewVar(tp, size)
|
||||||
PyTypeObject *tp;
|
PyTypeObject *tp;
|
||||||
int size;
|
int size;
|
||||||
#else
|
|
||||||
PyVarObject *
|
|
||||||
_PyObject_NewVar(tp, size, op)
|
|
||||||
PyTypeObject *tp;
|
|
||||||
int size;
|
|
||||||
PyVarObject *op;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
#ifndef MS_COREDLL
|
PyVarObject *op;
|
||||||
PyVarObject *op = (PyVarObject *)
|
op = (PyVarObject *) PyObject_MALLOC(_PyObject_VAR_SIZE(tp, size));
|
||||||
malloc(tp->tp_basicsize + size * tp->tp_itemsize);
|
|
||||||
#endif
|
|
||||||
if (op == NULL)
|
if (op == NULL)
|
||||||
return (PyVarObject *)PyErr_NoMemory();
|
return (PyVarObject *)PyErr_NoMemory();
|
||||||
op->ob_type = tp;
|
return PyObject_INIT_VAR(op, tp, size);
|
||||||
op->ob_size = size;
|
}
|
||||||
_Py_NewReference((PyObject *)op);
|
|
||||||
return op;
|
void
|
||||||
|
_PyObject_Del(op)
|
||||||
|
PyObject *op;
|
||||||
|
{
|
||||||
|
PyObject_FREE(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -888,54 +906,7 @@ PyTypeObject *_Py_cobject_hack = &PyCObject_Type;
|
||||||
int (*_Py_abstract_hack) Py_FPROTO((PyObject *)) = &PyObject_Length;
|
int (*_Py_abstract_hack) Py_FPROTO((PyObject *)) = &PyObject_Length;
|
||||||
|
|
||||||
|
|
||||||
/* Malloc wrappers (see mymalloc.h) */
|
/* Python's malloc wrappers (see mymalloc.h) */
|
||||||
|
|
||||||
/* The Py_{Malloc,Realloc} wrappers call PyErr_NoMemory() on failure */
|
|
||||||
|
|
||||||
ANY *
|
|
||||||
Py_Malloc(nbytes)
|
|
||||||
size_t nbytes;
|
|
||||||
{
|
|
||||||
ANY *p;
|
|
||||||
#if _PyMem_EXTRA > 0
|
|
||||||
if (nbytes == 0)
|
|
||||||
nbytes = _PyMem_EXTRA;
|
|
||||||
#endif
|
|
||||||
p = malloc(nbytes);
|
|
||||||
if (p != NULL)
|
|
||||||
return p;
|
|
||||||
else {
|
|
||||||
PyErr_NoMemory();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ANY *
|
|
||||||
Py_Realloc(p, nbytes)
|
|
||||||
ANY *p;
|
|
||||||
size_t nbytes;
|
|
||||||
{
|
|
||||||
#if _PyMem_EXTRA > 0
|
|
||||||
if (nbytes == 0)
|
|
||||||
nbytes = _PyMem_EXTRA;
|
|
||||||
#endif
|
|
||||||
p = realloc(p, nbytes);
|
|
||||||
if (p != NULL)
|
|
||||||
return p;
|
|
||||||
else {
|
|
||||||
PyErr_NoMemory();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Py_Free(p)
|
|
||||||
ANY *p;
|
|
||||||
{
|
|
||||||
free(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The PyMem_{Malloc,Realloc} wrappers don't call anything on failure */
|
|
||||||
|
|
||||||
ANY *
|
ANY *
|
||||||
PyMem_Malloc(nbytes)
|
PyMem_Malloc(nbytes)
|
||||||
|
@ -945,7 +916,7 @@ PyMem_Malloc(nbytes)
|
||||||
if (nbytes == 0)
|
if (nbytes == 0)
|
||||||
nbytes = _PyMem_EXTRA;
|
nbytes = _PyMem_EXTRA;
|
||||||
#endif
|
#endif
|
||||||
return malloc(nbytes);
|
return PyMem_MALLOC(nbytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
ANY *
|
ANY *
|
||||||
|
@ -957,14 +928,39 @@ PyMem_Realloc(p, nbytes)
|
||||||
if (nbytes == 0)
|
if (nbytes == 0)
|
||||||
nbytes = _PyMem_EXTRA;
|
nbytes = _PyMem_EXTRA;
|
||||||
#endif
|
#endif
|
||||||
return realloc(p, nbytes);
|
return PyMem_REALLOC(p, nbytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PyMem_Free(p)
|
PyMem_Free(p)
|
||||||
ANY *p;
|
ANY *p;
|
||||||
{
|
{
|
||||||
free(p);
|
PyMem_FREE(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Python's object malloc wrappers (see objimpl.h) */
|
||||||
|
|
||||||
|
ANY *
|
||||||
|
PyObject_Malloc(nbytes)
|
||||||
|
size_t nbytes;
|
||||||
|
{
|
||||||
|
return PyObject_MALLOC(nbytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
ANY *
|
||||||
|
PyObject_Realloc(p, nbytes)
|
||||||
|
ANY *p;
|
||||||
|
size_t nbytes;
|
||||||
|
{
|
||||||
|
return PyObject_REALLOC(p, nbytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PyObject_Free(p)
|
||||||
|
ANY *p;
|
||||||
|
{
|
||||||
|
PyObject_FREE(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ static void
|
||||||
range_dealloc(r)
|
range_dealloc(r)
|
||||||
rangeobject *r;
|
rangeobject *r;
|
||||||
{
|
{
|
||||||
PyMem_DEL(r);
|
PyObject_DEL(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -57,8 +57,7 @@ PySlice_New(start, stop, step)
|
||||||
PyObject *stop;
|
PyObject *stop;
|
||||||
PyObject *step;
|
PyObject *step;
|
||||||
{
|
{
|
||||||
PySliceObject *obj =
|
PySliceObject *obj = PyObject_NEW(PySliceObject, &PySlice_Type);
|
||||||
(PySliceObject *) PyObject_NEW(PySliceObject, &PySlice_Type);
|
|
||||||
|
|
||||||
if (step == NULL) step = Py_None;
|
if (step == NULL) step = Py_None;
|
||||||
Py_INCREF(step);
|
Py_INCREF(step);
|
||||||
|
@ -115,7 +114,7 @@ slice_dealloc(r)
|
||||||
Py_DECREF(r->step);
|
Py_DECREF(r->step);
|
||||||
Py_DECREF(r->start);
|
Py_DECREF(r->start);
|
||||||
Py_DECREF(r->stop);
|
Py_DECREF(r->stop);
|
||||||
PyMem_DEL(r);
|
PyObject_DEL(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -92,19 +92,19 @@ PyString_FromStringAndSize(str, size)
|
||||||
return (PyObject *)op;
|
return (PyObject *)op;
|
||||||
}
|
}
|
||||||
#endif /* DONT_SHARE_SHORT_STRINGS */
|
#endif /* DONT_SHARE_SHORT_STRINGS */
|
||||||
|
|
||||||
|
/* PyObject_NewVar is inlined */
|
||||||
op = (PyStringObject *)
|
op = (PyStringObject *)
|
||||||
malloc(sizeof(PyStringObject) + size * sizeof(char));
|
PyObject_MALLOC(sizeof(PyStringObject) + size * sizeof(char));
|
||||||
if (op == NULL)
|
if (op == NULL)
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
op->ob_type = &PyString_Type;
|
PyObject_INIT_VAR(op, &PyString_Type, size);
|
||||||
op->ob_size = size;
|
|
||||||
#ifdef CACHE_HASH
|
#ifdef CACHE_HASH
|
||||||
op->ob_shash = -1;
|
op->ob_shash = -1;
|
||||||
#endif
|
#endif
|
||||||
#ifdef INTERN_STRINGS
|
#ifdef INTERN_STRINGS
|
||||||
op->ob_sinterned = NULL;
|
op->ob_sinterned = NULL;
|
||||||
#endif
|
#endif
|
||||||
_Py_NewReference((PyObject *)op);
|
|
||||||
if (str != NULL)
|
if (str != NULL)
|
||||||
memcpy(op->ob_sval, str, size);
|
memcpy(op->ob_sval, str, size);
|
||||||
op->ob_sval[size] = '\0';
|
op->ob_sval[size] = '\0';
|
||||||
|
@ -142,19 +142,19 @@ PyString_FromString(str)
|
||||||
return (PyObject *)op;
|
return (PyObject *)op;
|
||||||
}
|
}
|
||||||
#endif /* DONT_SHARE_SHORT_STRINGS */
|
#endif /* DONT_SHARE_SHORT_STRINGS */
|
||||||
|
|
||||||
|
/* PyObject_NewVar is inlined */
|
||||||
op = (PyStringObject *)
|
op = (PyStringObject *)
|
||||||
malloc(sizeof(PyStringObject) + size * sizeof(char));
|
PyObject_MALLOC(sizeof(PyStringObject) + size * sizeof(char));
|
||||||
if (op == NULL)
|
if (op == NULL)
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
op->ob_type = &PyString_Type;
|
PyObject_INIT_VAR(op, &PyString_Type, size);
|
||||||
op->ob_size = size;
|
|
||||||
#ifdef CACHE_HASH
|
#ifdef CACHE_HASH
|
||||||
op->ob_shash = -1;
|
op->ob_shash = -1;
|
||||||
#endif
|
#endif
|
||||||
#ifdef INTERN_STRINGS
|
#ifdef INTERN_STRINGS
|
||||||
op->ob_sinterned = NULL;
|
op->ob_sinterned = NULL;
|
||||||
#endif
|
#endif
|
||||||
_Py_NewReference((PyObject *)op);
|
|
||||||
strcpy(op->ob_sval, str);
|
strcpy(op->ob_sval, str);
|
||||||
#ifndef DONT_SHARE_SHORT_STRINGS
|
#ifndef DONT_SHARE_SHORT_STRINGS
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
|
@ -172,7 +172,7 @@ static void
|
||||||
string_dealloc(op)
|
string_dealloc(op)
|
||||||
PyObject *op;
|
PyObject *op;
|
||||||
{
|
{
|
||||||
PyMem_DEL(op);
|
PyObject_DEL(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -307,19 +307,18 @@ string_concat(a, bb)
|
||||||
return (PyObject *)a;
|
return (PyObject *)a;
|
||||||
}
|
}
|
||||||
size = a->ob_size + b->ob_size;
|
size = a->ob_size + b->ob_size;
|
||||||
|
/* PyObject_NewVar is inlined */
|
||||||
op = (PyStringObject *)
|
op = (PyStringObject *)
|
||||||
malloc(sizeof(PyStringObject) + size * sizeof(char));
|
PyObject_MALLOC(sizeof(PyStringObject) + size * sizeof(char));
|
||||||
if (op == NULL)
|
if (op == NULL)
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
op->ob_type = &PyString_Type;
|
PyObject_INIT_VAR(op, &PyString_Type, size);
|
||||||
op->ob_size = size;
|
|
||||||
#ifdef CACHE_HASH
|
#ifdef CACHE_HASH
|
||||||
op->ob_shash = -1;
|
op->ob_shash = -1;
|
||||||
#endif
|
#endif
|
||||||
#ifdef INTERN_STRINGS
|
#ifdef INTERN_STRINGS
|
||||||
op->ob_sinterned = NULL;
|
op->ob_sinterned = NULL;
|
||||||
#endif
|
#endif
|
||||||
_Py_NewReference((PyObject *)op);
|
|
||||||
memcpy(op->ob_sval, a->ob_sval, (int) a->ob_size);
|
memcpy(op->ob_sval, a->ob_sval, (int) a->ob_size);
|
||||||
memcpy(op->ob_sval + a->ob_size, b->ob_sval, (int) b->ob_size);
|
memcpy(op->ob_sval + a->ob_size, b->ob_sval, (int) b->ob_size);
|
||||||
op->ob_sval[size] = '\0';
|
op->ob_sval[size] = '\0';
|
||||||
|
@ -342,19 +341,18 @@ string_repeat(a, n)
|
||||||
Py_INCREF(a);
|
Py_INCREF(a);
|
||||||
return (PyObject *)a;
|
return (PyObject *)a;
|
||||||
}
|
}
|
||||||
|
/* PyObject_NewVar is inlined */
|
||||||
op = (PyStringObject *)
|
op = (PyStringObject *)
|
||||||
malloc(sizeof(PyStringObject) + size * sizeof(char));
|
PyObject_MALLOC(sizeof(PyStringObject) + size * sizeof(char));
|
||||||
if (op == NULL)
|
if (op == NULL)
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
op->ob_type = &PyString_Type;
|
PyObject_INIT_VAR(op, &PyString_Type, size);
|
||||||
op->ob_size = size;
|
|
||||||
#ifdef CACHE_HASH
|
#ifdef CACHE_HASH
|
||||||
op->ob_shash = -1;
|
op->ob_shash = -1;
|
||||||
#endif
|
#endif
|
||||||
#ifdef INTERN_STRINGS
|
#ifdef INTERN_STRINGS
|
||||||
op->ob_sinterned = NULL;
|
op->ob_sinterned = NULL;
|
||||||
#endif
|
#endif
|
||||||
_Py_NewReference((PyObject *)op);
|
|
||||||
for (i = 0; i < size; i += a->ob_size)
|
for (i = 0; i < size; i += a->ob_size)
|
||||||
memcpy(op->ob_sval+i, a->ob_sval, (int) a->ob_size);
|
memcpy(op->ob_sval+i, a->ob_sval, (int) a->ob_size);
|
||||||
op->ob_sval[size] = '\0';
|
op->ob_sval[size] = '\0';
|
||||||
|
@ -1498,7 +1496,7 @@ mymemreplace(str, len, pat, pat_len, sub, sub_len, count, out_len)
|
||||||
goto return_same;
|
goto return_same;
|
||||||
new_len = len + nfound*(sub_len - pat_len);
|
new_len = len + nfound*(sub_len - pat_len);
|
||||||
|
|
||||||
new_s = (char *)malloc(new_len);
|
new_s = (char *)PyMem_MALLOC(new_len);
|
||||||
if (new_s == NULL) return NULL;
|
if (new_s == NULL) return NULL;
|
||||||
|
|
||||||
*out_len = new_len;
|
*out_len = new_len;
|
||||||
|
@ -1593,7 +1591,7 @@ string_replace(self, args)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
new = PyString_FromStringAndSize(new_s, out_len);
|
new = PyString_FromStringAndSize(new_s, out_len);
|
||||||
free(new_s);
|
PyMem_FREE(new_s);
|
||||||
}
|
}
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
@ -2273,10 +2271,10 @@ _PyString_Resize(pv, newsize)
|
||||||
#endif
|
#endif
|
||||||
_Py_ForgetReference(v);
|
_Py_ForgetReference(v);
|
||||||
*pv = (PyObject *)
|
*pv = (PyObject *)
|
||||||
realloc((char *)v,
|
PyObject_REALLOC((char *)v,
|
||||||
sizeof(PyStringObject) + newsize * sizeof(char));
|
sizeof(PyStringObject) + newsize * sizeof(char));
|
||||||
if (*pv == NULL) {
|
if (*pv == NULL) {
|
||||||
PyMem_DEL(v);
|
PyObject_DEL(v);
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,10 +80,12 @@ PyTuple_New(size)
|
||||||
#ifdef COUNT_ALLOCS
|
#ifdef COUNT_ALLOCS
|
||||||
fast_tuple_allocs++;
|
fast_tuple_allocs++;
|
||||||
#endif
|
#endif
|
||||||
|
/* PyObject_InitVar is inlined */
|
||||||
#ifdef Py_TRACE_REFS
|
#ifdef Py_TRACE_REFS
|
||||||
op->ob_type = &PyTuple_Type;
|
|
||||||
op->ob_size = size;
|
op->ob_size = size;
|
||||||
|
op->ob_type = &PyTuple_Type;
|
||||||
#endif
|
#endif
|
||||||
|
_Py_NewReference((PyObject *)op);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
@ -96,17 +98,15 @@ PyTuple_New(size)
|
||||||
{
|
{
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
}
|
}
|
||||||
;
|
/* PyObject_NewVar is inlined */
|
||||||
op = (PyTupleObject *) malloc(nbytes);
|
op = (PyTupleObject *) PyObject_MALLOC(nbytes);
|
||||||
if (op == NULL)
|
if (op == NULL)
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
|
|
||||||
op->ob_type = &PyTuple_Type;
|
PyObject_INIT_VAR(op, &PyTuple_Type, size);
|
||||||
op->ob_size = size;
|
|
||||||
}
|
}
|
||||||
for (i = 0; i < size; i++)
|
for (i = 0; i < size; i++)
|
||||||
op->ob_item[i] = NULL;
|
op->ob_item[i] = NULL;
|
||||||
_Py_NewReference((PyObject *)op);
|
|
||||||
#if MAXSAVESIZE > 0
|
#if MAXSAVESIZE > 0
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
free_tuples[0] = op;
|
free_tuples[0] = op;
|
||||||
|
@ -193,7 +193,7 @@ tupledealloc(op)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
free((ANY *)op);
|
PyObject_DEL(op);
|
||||||
done:
|
done:
|
||||||
Py_TRASHCAN_SAFE_END(op)
|
Py_TRASHCAN_SAFE_END(op)
|
||||||
}
|
}
|
||||||
|
@ -530,11 +530,11 @@ _PyTuple_Resize(pv, newsize, last_is_sticky)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
sv = (PyTupleObject *)
|
sv = (PyTupleObject *)
|
||||||
realloc((char *)v,
|
PyObject_REALLOC((char *)v,
|
||||||
sizeof(PyTupleObject) + newsize * sizeof(PyObject *));
|
sizeof(PyTupleObject) + newsize * sizeof(PyObject *));
|
||||||
*pv = (PyObject *) sv;
|
*pv = (PyObject *) sv;
|
||||||
if (sv == NULL) {
|
if (sv == NULL) {
|
||||||
PyMem_DEL(v);
|
PyObject_DEL(v);
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -569,7 +569,7 @@ PyTuple_Fini()
|
||||||
while (p) {
|
while (p) {
|
||||||
q = p;
|
q = p;
|
||||||
p = (PyTupleObject *)(p->ob_item[0]);
|
p = (PyTupleObject *)(p->ob_item[0]);
|
||||||
PyMem_DEL(q);
|
PyObject_DEL(q);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -200,14 +200,13 @@ PyUnicodeObject *_PyUnicode_New(int length)
|
||||||
unicode = unicode_freelist;
|
unicode = unicode_freelist;
|
||||||
unicode_freelist = *(PyUnicodeObject **)unicode_freelist;
|
unicode_freelist = *(PyUnicodeObject **)unicode_freelist;
|
||||||
unicode_freelist_size--;
|
unicode_freelist_size--;
|
||||||
unicode->ob_type = &PyUnicode_Type;
|
PyObject_INIT(unicode, &PyUnicode_Type);
|
||||||
_Py_NewReference((PyObject *)unicode);
|
|
||||||
if (unicode->str) {
|
if (unicode->str) {
|
||||||
/* Keep-Alive optimization: we only upsize the buffer,
|
/* Keep-Alive optimization: we only upsize the buffer,
|
||||||
never downsize it. */
|
never downsize it. */
|
||||||
if ((unicode->length < length) &&
|
if ((unicode->length < length) &&
|
||||||
_PyUnicode_Resize(unicode, length)) {
|
_PyUnicode_Resize(unicode, length)) {
|
||||||
free(unicode->str);
|
PyMem_DEL(unicode->str);
|
||||||
goto onError;
|
goto onError;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,7 +232,7 @@ PyUnicodeObject *_PyUnicode_New(int length)
|
||||||
|
|
||||||
onError:
|
onError:
|
||||||
_Py_ForgetReference((PyObject *)unicode);
|
_Py_ForgetReference((PyObject *)unicode);
|
||||||
PyMem_DEL(unicode);
|
PyObject_DEL(unicode);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +242,7 @@ void _PyUnicode_Free(register PyUnicodeObject *unicode)
|
||||||
if (unicode_freelist_size < MAX_UNICODE_FREELIST_SIZE) {
|
if (unicode_freelist_size < MAX_UNICODE_FREELIST_SIZE) {
|
||||||
/* Keep-Alive optimization */
|
/* Keep-Alive optimization */
|
||||||
if (unicode->length >= KEEPALIVE_SIZE_LIMIT) {
|
if (unicode->length >= KEEPALIVE_SIZE_LIMIT) {
|
||||||
free(unicode->str);
|
PyMem_DEL(unicode->str);
|
||||||
unicode->str = NULL;
|
unicode->str = NULL;
|
||||||
unicode->length = 0;
|
unicode->length = 0;
|
||||||
}
|
}
|
||||||
|
@ -257,9 +256,9 @@ void _PyUnicode_Free(register PyUnicodeObject *unicode)
|
||||||
unicode_freelist_size++;
|
unicode_freelist_size++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
free(unicode->str);
|
PyMem_DEL(unicode->str);
|
||||||
Py_XDECREF(unicode->utf8str);
|
Py_XDECREF(unicode->utf8str);
|
||||||
PyMem_DEL(unicode);
|
PyObject_DEL(unicode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4662,9 +4661,9 @@ _PyUnicode_Fini()
|
||||||
PyUnicodeObject *v = u;
|
PyUnicodeObject *v = u;
|
||||||
u = *(PyUnicodeObject **)u;
|
u = *(PyUnicodeObject **)u;
|
||||||
if (v->str)
|
if (v->str)
|
||||||
free(v->str);
|
PyMem_DEL(v->str);
|
||||||
Py_XDECREF(v->utf8str);
|
Py_XDECREF(v->utf8str);
|
||||||
free(v);
|
PyObject_DEL(v);
|
||||||
}
|
}
|
||||||
Py_XDECREF(unicode_empty);
|
Py_XDECREF(unicode_empty);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ xx_dealloc(xp)
|
||||||
xxobject *xp;
|
xxobject *xp;
|
||||||
{
|
{
|
||||||
Py_XDECREF(xp->x_attr);
|
Py_XDECREF(xp->x_attr);
|
||||||
PyMem_DEL(xp);
|
PyObject_DEL(xp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
12
PC/_winreg.c
12
PC/_winreg.c
|
@ -370,7 +370,7 @@ PyHKEY_deallocFunc(PyObject *ob)
|
||||||
PyHKEYObject *obkey = (PyHKEYObject *)ob;
|
PyHKEYObject *obkey = (PyHKEYObject *)ob;
|
||||||
if (obkey->hkey)
|
if (obkey->hkey)
|
||||||
RegCloseKey((HKEY)obkey->hkey);
|
RegCloseKey((HKEY)obkey->hkey);
|
||||||
PyMem_DEL(ob);
|
PyObject_DEL(ob);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -604,12 +604,14 @@ PyHKEY_AsHKEY(PyObject *ob, HKEY *pHANDLE, BOOL bNoneOK)
|
||||||
PyObject *
|
PyObject *
|
||||||
PyHKEY_FromHKEY(HKEY h)
|
PyHKEY_FromHKEY(HKEY h)
|
||||||
{
|
{
|
||||||
PyHKEYObject *op = (PyHKEYObject *) malloc(sizeof(PyHKEYObject));
|
PyHKEYObject *op;
|
||||||
|
|
||||||
|
/* PyObject_New is inlined */
|
||||||
|
op = (PyHKEYObject *) PyObject_MALLOC(sizeof(PyHKEYObject));
|
||||||
if (op == NULL)
|
if (op == NULL)
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
op->ob_type = &PyHKEY_Type;
|
PyObject_INIT(op, &PyHKEY_Type);
|
||||||
op->hkey = h;
|
op->hkey = h;
|
||||||
_Py_NewReference((PyObject *)op);
|
|
||||||
return (PyObject *)op;
|
return (PyObject *)op;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1348,7 +1350,7 @@ PySetValueEx(PyObject *self, PyObject *args)
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
rc = RegSetValueEx(hKey, valueName, 0, typ, data, len);
|
rc = RegSetValueEx(hKey, valueName, 0, typ, data, len);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
PyMem_Free(data);
|
PyMem_DEL(data);
|
||||||
if (rc != ERROR_SUCCESS)
|
if (rc != ERROR_SUCCESS)
|
||||||
return PyErr_SetFromWindowsErrWithFunction(rc,
|
return PyErr_SetFromWindowsErrWithFunction(rc,
|
||||||
"RegSetValueEx");
|
"RegSetValueEx");
|
||||||
|
|
12
PC/winreg.c
12
PC/winreg.c
|
@ -370,7 +370,7 @@ PyHKEY_deallocFunc(PyObject *ob)
|
||||||
PyHKEYObject *obkey = (PyHKEYObject *)ob;
|
PyHKEYObject *obkey = (PyHKEYObject *)ob;
|
||||||
if (obkey->hkey)
|
if (obkey->hkey)
|
||||||
RegCloseKey((HKEY)obkey->hkey);
|
RegCloseKey((HKEY)obkey->hkey);
|
||||||
PyMem_DEL(ob);
|
PyObject_DEL(ob);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -604,12 +604,14 @@ PyHKEY_AsHKEY(PyObject *ob, HKEY *pHANDLE, BOOL bNoneOK)
|
||||||
PyObject *
|
PyObject *
|
||||||
PyHKEY_FromHKEY(HKEY h)
|
PyHKEY_FromHKEY(HKEY h)
|
||||||
{
|
{
|
||||||
PyHKEYObject *op = (PyHKEYObject *) malloc(sizeof(PyHKEYObject));
|
PyHKEYObject *op;
|
||||||
|
|
||||||
|
/* PyObject_New is inlined */
|
||||||
|
op = (PyHKEYObject *) PyObject_MALLOC(sizeof(PyHKEYObject));
|
||||||
if (op == NULL)
|
if (op == NULL)
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
op->ob_type = &PyHKEY_Type;
|
PyObject_INIT(op, &PyHKEY_Type);
|
||||||
op->hkey = h;
|
op->hkey = h;
|
||||||
_Py_NewReference((PyObject *)op);
|
|
||||||
return (PyObject *)op;
|
return (PyObject *)op;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1348,7 +1350,7 @@ PySetValueEx(PyObject *self, PyObject *args)
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
rc = RegSetValueEx(hKey, valueName, 0, typ, data, len);
|
rc = RegSetValueEx(hKey, valueName, 0, typ, data, len);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
PyMem_Free(data);
|
PyMem_DEL(data);
|
||||||
if (rc != ERROR_SUCCESS)
|
if (rc != ERROR_SUCCESS)
|
||||||
return PyErr_SetFromWindowsErrWithFunction(rc,
|
return PyErr_SetFromWindowsErrWithFunction(rc,
|
||||||
"RegSetValueEx");
|
"RegSetValueEx");
|
||||||
|
|
|
@ -89,7 +89,7 @@ PyOS_StdioReadline(prompt)
|
||||||
int n;
|
int n;
|
||||||
char *p;
|
char *p;
|
||||||
n = 100;
|
n = 100;
|
||||||
if ((p = malloc(n)) == NULL)
|
if ((p = PyMem_MALLOC(n)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
if (prompt)
|
if (prompt)
|
||||||
|
@ -99,7 +99,7 @@ PyOS_StdioReadline(prompt)
|
||||||
case 0: /* Normal case */
|
case 0: /* Normal case */
|
||||||
break;
|
break;
|
||||||
case 1: /* Interrupt */
|
case 1: /* Interrupt */
|
||||||
free(p);
|
PyMem_FREE(p);
|
||||||
return NULL;
|
return NULL;
|
||||||
case -1: /* EOF */
|
case -1: /* EOF */
|
||||||
case -2: /* Error */
|
case -2: /* Error */
|
||||||
|
@ -117,19 +117,21 @@ PyOS_StdioReadline(prompt)
|
||||||
n = strlen(p);
|
n = strlen(p);
|
||||||
while (n > 0 && p[n-1] != '\n') {
|
while (n > 0 && p[n-1] != '\n') {
|
||||||
int incr = n+2;
|
int incr = n+2;
|
||||||
p = realloc(p, n + incr);
|
p = PyMem_REALLOC(p, n + incr);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (my_fgets(p+n, incr, stdin) != 0)
|
if (my_fgets(p+n, incr, stdin) != 0)
|
||||||
break;
|
break;
|
||||||
n += strlen(p+n);
|
n += strlen(p+n);
|
||||||
}
|
}
|
||||||
return realloc(p, n+1);
|
return PyMem_REALLOC(p, n+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* By initializing this function pointer, systems embedding Python can
|
/* By initializing this function pointer, systems embedding Python can
|
||||||
override the readline function. */
|
override the readline function.
|
||||||
|
|
||||||
|
Note: Python expects in return a buffer allocated with PyMem_Malloc. */
|
||||||
|
|
||||||
char *(*PyOS_ReadlineFunctionPointer) Py_PROTO((char *));
|
char *(*PyOS_ReadlineFunctionPointer) Py_PROTO((char *));
|
||||||
|
|
||||||
|
|
|
@ -192,7 +192,7 @@ parsetok(tok, g, start, err_ret)
|
||||||
err_ret->offset = tok->cur - tok->buf;
|
err_ret->offset = tok->cur - tok->buf;
|
||||||
if (tok->buf != NULL) {
|
if (tok->buf != NULL) {
|
||||||
int len = tok->inp - tok->buf;
|
int len = tok->inp - tok->buf;
|
||||||
err_ret->text = malloc(len + 1);
|
err_ret->text = PyMem_NEW(char, len + 1);
|
||||||
if (err_ret->text != NULL) {
|
if (err_ret->text != NULL) {
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
strncpy(err_ret->text, tok->buf, len);
|
strncpy(err_ret->text, tok->buf, len);
|
||||||
|
|
|
@ -139,7 +139,7 @@ getgrammar(filename)
|
||||||
putc(' ', stderr);
|
putc(' ', stderr);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "^\n");
|
fprintf(stderr, "^\n");
|
||||||
free(err.text);
|
PyMem_DEL(err.text);
|
||||||
}
|
}
|
||||||
Py_Exit(1);
|
Py_Exit(1);
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ PyOS_Readline(prompt)
|
||||||
char *prompt;
|
char *prompt;
|
||||||
{
|
{
|
||||||
int n = 1000;
|
int n = 1000;
|
||||||
char *p = malloc(n);
|
char *p = PyMem_MALLOC(n);
|
||||||
char *q;
|
char *q;
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -209,7 +209,7 @@ PyOS_Readline(prompt)
|
||||||
n = strlen(p);
|
n = strlen(p);
|
||||||
if (n > 0 && p[n-1] != '\n')
|
if (n > 0 && p[n-1] != '\n')
|
||||||
p[n-1] = '\n';
|
p[n-1] = '\n';
|
||||||
return realloc(p, n+1);
|
return PyMem_REALLOC(p, n+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_STDARG_PROTOTYPES
|
#ifdef HAVE_STDARG_PROTOTYPES
|
||||||
|
|
|
@ -219,26 +219,27 @@ tok_nextc(tok)
|
||||||
if (new == NULL)
|
if (new == NULL)
|
||||||
tok->done = E_INTR;
|
tok->done = E_INTR;
|
||||||
else if (*new == '\0') {
|
else if (*new == '\0') {
|
||||||
free(new);
|
PyMem_FREE(new);
|
||||||
tok->done = E_EOF;
|
tok->done = E_EOF;
|
||||||
}
|
}
|
||||||
else if (tok->start != NULL) {
|
else if (tok->start != NULL) {
|
||||||
int start = tok->start - tok->buf;
|
int start = tok->start - tok->buf;
|
||||||
int oldlen = tok->cur - tok->buf;
|
int oldlen = tok->cur - tok->buf;
|
||||||
int newlen = oldlen + strlen(new);
|
int newlen = oldlen + strlen(new);
|
||||||
char *buf = realloc(tok->buf, newlen+1);
|
char *buf = tok->buf;
|
||||||
|
PyMem_RESIZE(buf, char, newlen+1);
|
||||||
tok->lineno++;
|
tok->lineno++;
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
free(tok->buf);
|
PyMem_DEL(tok->buf);
|
||||||
tok->buf = NULL;
|
tok->buf = NULL;
|
||||||
free(new);
|
PyMem_FREE(new);
|
||||||
tok->done = E_NOMEM;
|
tok->done = E_NOMEM;
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
tok->buf = buf;
|
tok->buf = buf;
|
||||||
tok->cur = tok->buf + oldlen;
|
tok->cur = tok->buf + oldlen;
|
||||||
strcpy(tok->buf + oldlen, new);
|
strcpy(tok->buf + oldlen, new);
|
||||||
free(new);
|
PyMem_FREE(new);
|
||||||
tok->inp = tok->buf + newlen;
|
tok->inp = tok->buf + newlen;
|
||||||
tok->end = tok->inp + 1;
|
tok->end = tok->inp + 1;
|
||||||
tok->start = tok->buf + start;
|
tok->start = tok->buf + start;
|
||||||
|
@ -246,7 +247,7 @@ tok_nextc(tok)
|
||||||
else {
|
else {
|
||||||
tok->lineno++;
|
tok->lineno++;
|
||||||
if (tok->buf != NULL)
|
if (tok->buf != NULL)
|
||||||
free(tok->buf);
|
PyMem_DEL(tok->buf);
|
||||||
tok->buf = new;
|
tok->buf = new;
|
||||||
tok->cur = tok->buf;
|
tok->cur = tok->buf;
|
||||||
tok->inp = strchr(tok->buf, '\0');
|
tok->inp = strchr(tok->buf, '\0');
|
||||||
|
|
|
@ -1875,7 +1875,7 @@ builtin_raw_input(self, args)
|
||||||
else { /* strip trailing '\n' */
|
else { /* strip trailing '\n' */
|
||||||
result = PyString_FromStringAndSize(s, strlen(s)-1);
|
result = PyString_FromStringAndSize(s, strlen(s)-1);
|
||||||
}
|
}
|
||||||
free(s);
|
PyMem_FREE(s);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (v != NULL) {
|
if (v != NULL) {
|
||||||
|
|
|
@ -2558,7 +2558,8 @@ call_function(func, arg, kw)
|
||||||
class);
|
class);
|
||||||
|
|
||||||
Py_DECREF(arg);
|
Py_DECREF(arg);
|
||||||
PyMem_XDEL(k);
|
if (k != NULL)
|
||||||
|
PyMem_DEL(k);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,7 @@ code_dealloc(co)
|
||||||
Py_XDECREF(co->co_filename);
|
Py_XDECREF(co->co_filename);
|
||||||
Py_XDECREF(co->co_name);
|
Py_XDECREF(co->co_name);
|
||||||
Py_XDECREF(co->co_lnotab);
|
Py_XDECREF(co->co_lnotab);
|
||||||
PyMem_DEL(co);
|
PyObject_DEL(co);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -124,7 +124,7 @@ _PyImport_Init()
|
||||||
++countD;
|
++countD;
|
||||||
for (scan = _PyImport_StandardFiletab; scan->suffix != NULL; ++scan)
|
for (scan = _PyImport_StandardFiletab; scan->suffix != NULL; ++scan)
|
||||||
++countS;
|
++countS;
|
||||||
filetab = malloc((countD + countS + 1) * sizeof(struct filedescr));
|
filetab = PyMem_NEW(struct filedescr, countD + countS + 1);
|
||||||
memcpy(filetab, _PyImport_DynLoadFiletab,
|
memcpy(filetab, _PyImport_DynLoadFiletab,
|
||||||
countD * sizeof(struct filedescr));
|
countD * sizeof(struct filedescr));
|
||||||
memcpy(filetab + countD, _PyImport_StandardFiletab,
|
memcpy(filetab + countD, _PyImport_StandardFiletab,
|
||||||
|
@ -2398,10 +2398,10 @@ initimp()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* API for embedding applications that want to add their own entries to the
|
/* API for embedding applications that want to add their own entries
|
||||||
table of built-in modules. This should normally be called *before*
|
to the table of built-in modules. This should normally be called
|
||||||
Py_Initialize(). When the malloc() or realloc() call fails, -1 is returned
|
*before* Py_Initialize(). When the table resize fails, -1 is
|
||||||
and the existing table is unchanged.
|
returned and the existing table is unchanged.
|
||||||
|
|
||||||
After a similar function by Just van Rossum. */
|
After a similar function by Just van Rossum. */
|
||||||
|
|
||||||
|
@ -2422,10 +2422,8 @@ PyImport_ExtendInittab(newtab)
|
||||||
;
|
;
|
||||||
|
|
||||||
/* Allocate new memory for the combined table */
|
/* Allocate new memory for the combined table */
|
||||||
if (our_copy == NULL)
|
p = our_copy;
|
||||||
p = malloc((i+n+1) * sizeof(struct _inittab));
|
PyMem_RESIZE(p, struct _inittab, i+n+1);
|
||||||
else
|
|
||||||
p = realloc(our_copy, (i+n+1) * sizeof(struct _inittab));
|
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
|
@ -514,17 +514,17 @@ r_object(p)
|
||||||
PyErr_SetString(PyExc_ValueError, "bad marshal data");
|
PyErr_SetString(PyExc_ValueError, "bad marshal data");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
buffer = (char *)Py_Malloc(n);
|
buffer = PyMem_NEW(char, n);
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return NULL;
|
return PyErr_NoMemory();
|
||||||
if (r_string(buffer, (int)n, p) != n) {
|
if (r_string(buffer, (int)n, p) != n) {
|
||||||
free(buffer);
|
PyMem_DEL(buffer);
|
||||||
PyErr_SetString(PyExc_EOFError,
|
PyErr_SetString(PyExc_EOFError,
|
||||||
"EOF read where object expected");
|
"EOF read where object expected");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
v = PyUnicode_DecodeUTF8(buffer, n, NULL);
|
v = PyUnicode_DecodeUTF8(buffer, n, NULL);
|
||||||
free(buffer);
|
PyMem_DEL(buffer);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -543,7 +543,7 @@ PyRun_InteractiveOne(fp, filename)
|
||||||
if (n == NULL) {
|
if (n == NULL) {
|
||||||
if (err.error == E_EOF) {
|
if (err.error == E_EOF) {
|
||||||
if (err.text)
|
if (err.text)
|
||||||
free(err.text);
|
PyMem_DEL(err.text);
|
||||||
return E_EOF;
|
return E_EOF;
|
||||||
}
|
}
|
||||||
err_input(&err);
|
err_input(&err);
|
||||||
|
@ -1009,7 +1009,7 @@ err_input(err)
|
||||||
v = Py_BuildValue("(ziiz)", err->filename,
|
v = Py_BuildValue("(ziiz)", err->filename,
|
||||||
err->lineno, err->offset, err->text);
|
err->lineno, err->offset, err->text);
|
||||||
if (err->text != NULL) {
|
if (err->text != NULL) {
|
||||||
free(err->text);
|
PyMem_DEL(err->text);
|
||||||
err->text = NULL;
|
err->text = NULL;
|
||||||
}
|
}
|
||||||
switch (err->error) {
|
switch (err->error) {
|
||||||
|
|
|
@ -71,7 +71,7 @@ tb_dealloc(tb)
|
||||||
Py_TRASHCAN_SAFE_BEGIN(tb)
|
Py_TRASHCAN_SAFE_BEGIN(tb)
|
||||||
Py_XDECREF(tb->tb_next);
|
Py_XDECREF(tb->tb_next);
|
||||||
Py_XDECREF(tb->tb_frame);
|
Py_XDECREF(tb->tb_frame);
|
||||||
PyMem_DEL(tb);
|
PyObject_DEL(tb);
|
||||||
Py_TRASHCAN_SAFE_END(tb)
|
Py_TRASHCAN_SAFE_END(tb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue