1997-05-02 06:00:11 +02:00
|
|
|
#ifndef Py_PYTHON_H
|
|
|
|
#define Py_PYTHON_H
|
1997-05-02 05:55:52 +02:00
|
|
|
/* Since this is a "meta-include" file, no #ifdef __cplusplus / extern "C" { */
|
|
|
|
|
|
|
|
/* Include nearly all Python header files */
|
|
|
|
|
1999-01-03 13:40:24 +01:00
|
|
|
#include "patchlevel.h"
|
2001-07-26 15:41:06 +02:00
|
|
|
#include "pyconfig.h"
|
1997-05-02 05:55:52 +02:00
|
|
|
|
2002-07-07 05:59:34 +02:00
|
|
|
/* Cyclic gc is always enabled, starting with release 2.3a1. Supply the
|
|
|
|
* old symbol for the benefit of extension modules written before then
|
|
|
|
* that may be conditionalizing on it. The core doesn't use it anymore.
|
|
|
|
*/
|
|
|
|
#ifndef WITH_CYCLE_GC
|
|
|
|
#define WITH_CYCLE_GC 1
|
|
|
|
#endif
|
|
|
|
|
2000-09-26 07:46:01 +02:00
|
|
|
#ifdef HAVE_LIMITS_H
|
|
|
|
#include <limits.h>
|
2002-07-12 07:01:20 +02:00
|
|
|
#else
|
|
|
|
#error "limits.h is required by std C -- why isn't HAVE_LIMITS_H defined?"
|
2000-09-26 07:46:01 +02:00
|
|
|
#endif
|
|
|
|
|
1998-05-26 20:38:07 +02:00
|
|
|
#if defined(__sgi) && defined(WITH_THREAD) && !defined(_SGI_MP_SOURCE)
|
|
|
|
#define _SGI_MP_SOURCE
|
|
|
|
#endif
|
|
|
|
|
1997-05-02 05:55:52 +02:00
|
|
|
#include <stdio.h>
|
2000-09-10 03:02:41 +02:00
|
|
|
#ifndef NULL
|
|
|
|
# error "Python.h requires that stdio.h define NULL."
|
|
|
|
#endif
|
|
|
|
|
1997-05-02 05:55:52 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
2002-01-12 12:05:12 +01:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2001-07-15 18:58:05 +02:00
|
|
|
|
2001-12-04 21:06:11 +01:00
|
|
|
/* CAUTION: Build setups should ensure that NDEBUG is defined on the
|
|
|
|
* compiler command line when building Python in release mode; else
|
|
|
|
* assert() calls won't be removed.
|
|
|
|
*/
|
2000-07-23 21:28:35 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
2002-05-15 20:24:06 +02:00
|
|
|
#include "pyport.h"
|
|
|
|
|
2002-06-04 17:07:08 +02:00
|
|
|
/* pyconfig.h or pyport.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
|
|
|
|
|
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
When WITH_PYMALLOC is defined, define PYMALLOC_DEBUG to enable the debug
allocator. This can be done independent of build type (release or debug).
A debug build automatically defines PYMALLOC_DEBUG when pymalloc is
enabled. It's a detected error to define PYMALLOC_DEBUG when pymalloc
isn't enabled.
Two debugging entry points defined only under PYMALLOC_DEBUG:
+ _PyMalloc_DebugCheckAddress(const void *p) can be used (e.g., from gdb)
to sanity-check a memory block obtained from pymalloc. It sprays
info to stderr (see next) and dies via Py_FatalError if the block is
detectably damaged.
+ _PyMalloc_DebugDumpAddress(const void *p) can be used to spray info
about a debug memory block to stderr.
A tiny start at implementing "API family" checks isn't good for
anything yet.
_PyMalloc_DebugRealloc() has been optimized to do little when the new
size is <= old size. However, if the new size is larger, it really
can't call the underlying realloc() routine without either violating its
contract, or knowing something non-trivial about how the underlying
realloc() works. A memcpy is always done in this case.
This was a disaster for (and only) one of the std tests: test_bufio
creates single text file lines up to a million characters long. On
Windows, fileobject.c's get_line() uses the horridly funky
getline_via_fgets(), which keeps growing and growing a string object
hoping to find a newline. It grew the string object 1000 bytes each
time, so for a million-character string it took approximately forever
(I gave up after a few minutes).
So, also:
fileobject.c, getline_via_fgets(): When a single line is outrageously
long, grow the string object at a mildly exponential rate, instead of
just 1000 bytes at a time.
That's enough so that a debug-build test_bufio finishes in about 5 seconds
on my Win98SE box. I'm curious to try this on Win2K, because it has very
different memory behavior than Win9X, and test_bufio always took a factor
of 10 longer to complete on Win2K. It *could* be that the endless
reallocs were simply killing it on Win2K even in the release build.
2002-03-23 11:03:50 +01:00
|
|
|
/* Debug-mode build with pymalloc implies PYMALLOC_DEBUG.
|
|
|
|
* PYMALLOC_DEBUG is in error if pymalloc is not in use.
|
|
|
|
*/
|
|
|
|
#if defined(Py_DEBUG) && defined(WITH_PYMALLOC) && !defined(PYMALLOC_DEBUG)
|
|
|
|
#define PYMALLOC_DEBUG
|
|
|
|
#endif
|
|
|
|
#if defined(PYMALLOC_DEBUG) && !defined(WITH_PYMALLOC)
|
|
|
|
#error "PYMALLOC_DEBUG requires WITH_PYMALLOC"
|
|
|
|
#endif
|
2000-08-01 00:19:30 +02:00
|
|
|
#include "pymem.h"
|
|
|
|
|
1997-05-02 05:55:52 +02:00
|
|
|
#include "object.h"
|
|
|
|
#include "objimpl.h"
|
|
|
|
|
|
|
|
#include "pydebug.h"
|
|
|
|
|
2000-04-05 22:11:21 +02:00
|
|
|
#include "unicodeobject.h"
|
1997-05-02 05:55:52 +02:00
|
|
|
#include "intobject.h"
|
2002-04-04 00:41:51 +02:00
|
|
|
#include "boolobject.h"
|
1997-05-02 05:55:52 +02:00
|
|
|
#include "longobject.h"
|
|
|
|
#include "floatobject.h"
|
|
|
|
#ifndef WITHOUT_COMPLEX
|
|
|
|
#include "complexobject.h"
|
|
|
|
#endif
|
|
|
|
#include "rangeobject.h"
|
|
|
|
#include "stringobject.h"
|
1998-10-07 16:36:10 +02:00
|
|
|
#include "bufferobject.h"
|
1997-05-02 05:55:52 +02:00
|
|
|
#include "tupleobject.h"
|
|
|
|
#include "listobject.h"
|
1997-05-13 23:23:32 +02:00
|
|
|
#include "dictobject.h"
|
2002-04-26 21:40:56 +02:00
|
|
|
#include "enumobject.h"
|
1997-05-02 05:55:52 +02:00
|
|
|
#include "methodobject.h"
|
|
|
|
#include "moduleobject.h"
|
|
|
|
#include "funcobject.h"
|
|
|
|
#include "classobject.h"
|
|
|
|
#include "fileobject.h"
|
|
|
|
#include "cobject.h"
|
|
|
|
#include "traceback.h"
|
|
|
|
#include "sliceobject.h"
|
2001-01-25 21:04:14 +01:00
|
|
|
#include "cellobject.h"
|
2001-04-20 21:13:02 +02:00
|
|
|
#include "iterobject.h"
|
2001-08-02 06:15:00 +02:00
|
|
|
#include "descrobject.h"
|
2001-10-05 23:55:19 +02:00
|
|
|
#include "weakrefobject.h"
|
1997-05-02 05:55:52 +02:00
|
|
|
|
2000-03-10 23:34:00 +01:00
|
|
|
#include "codecs.h"
|
1997-05-02 05:55:52 +02:00
|
|
|
#include "pyerrors.h"
|
|
|
|
|
1997-07-19 01:59:26 +02:00
|
|
|
#include "pystate.h"
|
|
|
|
|
1997-05-02 05:55:52 +02:00
|
|
|
#include "modsupport.h"
|
|
|
|
#include "pythonrun.h"
|
2001-07-16 04:29:45 +02:00
|
|
|
#include "ceval.h"
|
1997-05-02 05:55:52 +02:00
|
|
|
#include "sysmodule.h"
|
|
|
|
#include "intrcheck.h"
|
|
|
|
#include "import.h"
|
|
|
|
|
|
|
|
#include "abstract.h"
|
|
|
|
|
2002-06-21 00:23:15 +02:00
|
|
|
/* _Py_Mangle is defined in compile.c */
|
2002-08-12 09:21:58 +02:00
|
|
|
PyAPI_FUNC(int) _Py_Mangle(char *p, char *name, \
|
2002-06-21 00:23:15 +02:00
|
|
|
char *buffer, size_t maxlen);
|
|
|
|
|
2002-03-25 23:21:58 +01:00
|
|
|
/* PyArg_GetInt is deprecated and should not be used, use PyArg_Parse(). */
|
1997-05-02 05:55:52 +02:00
|
|
|
#define PyArg_GetInt(v, a) PyArg_Parse((v), "i", (a))
|
2002-03-25 21:46:46 +01:00
|
|
|
|
|
|
|
/* PyArg_NoArgs should not be necessary.
|
|
|
|
Set ml_flags in the PyMethodDef to METH_NOARGS. */
|
1997-05-02 05:55:52 +02:00
|
|
|
#define PyArg_NoArgs(v) PyArg_Parse(v, "")
|
|
|
|
|
|
|
|
/* Convert a possibly signed character to a nonnegative int */
|
|
|
|
/* XXX This assumes characters are 8 bits wide */
|
|
|
|
#ifdef __CHAR_UNSIGNED__
|
|
|
|
#define Py_CHARMASK(c) (c)
|
|
|
|
#else
|
|
|
|
#define Py_CHARMASK(c) ((c) & 0xff)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "pyfpe.h"
|
|
|
|
|
2000-05-28 22:29:48 +02:00
|
|
|
/* These definitions must match corresponding definitions in graminit.h.
|
1997-05-07 19:46:13 +02:00
|
|
|
There's code in compile.c that checks that they are the same. */
|
|
|
|
#define Py_single_input 256
|
|
|
|
#define Py_file_input 257
|
|
|
|
#define Py_eval_input 258
|
|
|
|
|
2000-09-19 02:46:46 +02:00
|
|
|
#ifdef HAVE_PTH
|
2000-05-08 15:41:38 +02:00
|
|
|
/* GNU pth user-space thread support */
|
|
|
|
#include <pth.h>
|
|
|
|
#endif
|
2002-06-09 15:33:54 +02:00
|
|
|
|
|
|
|
/* Define macros for inline documentation. */
|
|
|
|
#define PyDoc_VAR(name) static char name[]
|
|
|
|
#define PyDoc_STRVAR(name,str) PyDoc_VAR(name) = PyDoc_STR(str)
|
|
|
|
#ifdef WITH_DOC_STRINGS
|
|
|
|
#define PyDoc_STR(str) str
|
|
|
|
#else
|
|
|
|
#define PyDoc_STR(str) ""
|
|
|
|
#endif
|
|
|
|
|
1997-05-02 06:00:11 +02:00
|
|
|
#endif /* !Py_PYTHON_H */
|