[Patches] PyMem [3/8] - Include/pycore.h

Vladimir Marangozov Vladimir.Marangozov@inrialpes.fr
Fri, 25 Feb 2000 13:26:46 +0100 (CET)


The new header pycore.h

I'm not sure I fully understand the business with MS_COREDLL for Windows.
Could somebody explain it to me? When & why exactly is this symbol defined?


-- 
       Vladimir MARANGOZOV          | Vladimir.Marangozov@inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252

--
I confirm that, to the best of my knowledge and belief, this contribution is
free of any claims of third parties under copyright, patent or other rights
or interests ("claims").  To the extent that I have any such claims, I
hereby grant to CNRI a nonexclusive, irrevocable, royalty-free, worldwide
license to reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part of the
Python software and its related documentation, or any derivative versions
thereof, at no cost to CNRI or its licensed users, and to authorize others
to do so.

I acknowledge that CNRI may, at its sole discretion, decide whether or not
to incorporate this contribution in the Python software and its related
documentation.  I further grant CNRI permission to use my name and other
identifying information provided to CNRI by me for use in connection with
the Python software and its related documentation.

-------------------------------[ cut here ]---------------------------  
#ifndef Py_PYCORE_H
#define Py_PYCORE_H
/***********************************************************
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
The Netherlands.

                        All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI or Corporation for National Research Initiatives or
CNRI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.

While CWI is the initial source for this software, a modified version
is made available by the Corporation for National Research Initiatives
(CNRI) at the Internet address ftp://ftp.python.org.

STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.

******************************************************************/

/* Private core interfaces.

   BEWARE: pycore.h should be included only in files which belong
   to the Python core implementation. Never include this file in
   an extension module! */

#include "patchlevel.h"
#include "config.h"

/* config.h may or may not define DL_IMPORT */
#ifndef DL_IMPORT       /* declarations for DLL import/export */
#define DL_IMPORT(RTYPE) RTYPE
#endif
#ifndef DL_EXPORT       /* declarations for DLL import/export */
#define DL_EXPORT(RTYPE) RTYPE
#endif

#ifdef SYMANTEC__CFM68K__
#define UsingSharedLibs
#endif

#if defined(__sgi) && defined(WITH_THREAD) && !defined(_SGI_MP_SOURCE)
#define _SGI_MP_SOURCE
#endif

#include <stdio.h>
#include <string.h>
#include <errno.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif

#include "myproto.h"

/*
   Core memory allocator
   =====================

   To make sure the interpreter is user-malloc friendly, all other
   memory or object core APIs are implemented on top of this one.

   These can be changed to make the interpreter use another allocator.

   The easiest way to change the core allocator *and* to avoid the wrapper
   overhead for extension modules that call PyMem_{Malloc, Realloc, Free}
   is to proceed as follows:

        1) Replace the implementation of PyMem_{Malloc, Realloc, Free}
           in mymalloc.c with the new allocator.

        2) Redefine hereafter PyCore_{MALLOC, REALLOC, FREE} as
           PyMem_{Malloc, Realloc, Free}.

           XXX These should probably move to configure.
*/
#define PyCore_MALLOC		malloc
#define PyCore_REALLOC		realloc
#define PyCore_FREE		free


/* We hereby redefine the type-oriented macros in mymalloc.h
   so that the Python core can use its own malloc functions. */

#include "mymalloc.h"   /* for ANY and the public interfaces */

#undef PyMem_NEW
#undef PyMem_RESIZE
#undef PyMem_DEL
#undef PyMem_XDEL	/* deprecated */


/* Raw memory interface. */

#ifdef __cplusplus
extern "C" {
#endif

#ifdef NEED_TO_DECLARE_MALLOC_AND_FRIEND
extern ANY *PyCore_MALLOC Py_PROTO((size_t));
extern ANY *PyCore_REALLOC Py_PROTO((ANY *, size_t));
extern void PyCore_FREE Py_PROTO((ANY *));
#endif

#ifdef __cplusplus
}
#endif

#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. */

#ifdef MALLOC_ZERO_RETURNS_NULL
/* XXX Always allocate one extra byte, since some malloc's return NULL
   XXX for malloc(0) or realloc(p, 0). */
#define _PyMem_EXTRA 1
#else
#define _PyMem_EXTRA 0
#endif

#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)

/*
   Core object allocator
   =====================

   PyObject_NEW/NEW_VAR are left unchanged. They call _PyObject_New/NewVar.
   PyObject_DEL is inlined to avoid the overhead of calling _PyObject_Del.
*/
#include "object.h"
#include "objimpl.h"

#undef PyObject_DEL

#ifndef MS_COREDLL
#define PyObject_DEL(op) PyMem_FREE(op)
#else
#define PyObject_DEL(op) free((ANY *)(op))
#endif

#endif /* !Py_PYCORE_H */