1997-05-02 12:00:11 +08:00
|
|
|
#ifndef Py_PYTHON_H
|
|
|
|
#define Py_PYTHON_H
|
1997-05-02 11:55:52 +08:00
|
|
|
/* Since this is a "meta-include" file, no #ifdef __cplusplus / extern "C" { */
|
|
|
|
|
|
|
|
/* Include nearly all Python header files */
|
|
|
|
|
1999-01-03 20:40:24 +08:00
|
|
|
#include "patchlevel.h"
|
2001-07-26 21:41:06 +08:00
|
|
|
#include "pyconfig.h"
|
1997-05-02 11:55:52 +08:00
|
|
|
|
2002-07-07 11:59:34 +08: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 13:46:01 +08:00
|
|
|
#ifdef HAVE_LIMITS_H
|
|
|
|
#include <limits.h>
|
2002-07-12 13:01:20 +08:00
|
|
|
#else
|
|
|
|
#error "limits.h is required by std C -- why isn't HAVE_LIMITS_H defined?"
|
2000-09-26 13:46:01 +08:00
|
|
|
#endif
|
|
|
|
|
1998-05-27 02:38:07 +08:00
|
|
|
#if defined(__sgi) && defined(WITH_THREAD) && !defined(_SGI_MP_SOURCE)
|
|
|
|
#define _SGI_MP_SOURCE
|
|
|
|
#endif
|
|
|
|
|
1997-05-02 11:55:52 +08:00
|
|
|
#include <stdio.h>
|
2000-09-10 09:02:41 +08:00
|
|
|
#ifndef NULL
|
|
|
|
# error "Python.h requires that stdio.h define NULL."
|
|
|
|
#endif
|
|
|
|
|
1997-05-02 11:55:52 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
2002-01-12 19:05:12 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2001-07-16 00:58:05 +08:00
|
|
|
|
2001-12-05 04:06:11 +08: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-24 03:28:35 +08:00
|
|
|
#include <assert.h>
|
|
|
|
|
2002-05-16 02:24:06 +08:00
|
|
|
#include "pyport.h"
|
|
|
|
|
2002-06-04 23:07:08 +08: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 18:03:50 +08: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 06:19:30 +08:00
|
|
|
#include "pymem.h"
|
|
|
|
|
1997-05-02 11:55:52 +08:00
|
|
|
#include "object.h"
|
|
|
|
#include "objimpl.h"
|
|
|
|
|
|
|
|
#include "pydebug.h"
|
|
|
|
|
2000-04-06 04:11:21 +08:00
|
|
|
#include "unicodeobject.h"
|
1997-05-02 11:55:52 +08:00
|
|
|
#include "intobject.h"
|
2002-04-04 06:41:51 +08:00
|
|
|
#include "boolobject.h"
|
1997-05-02 11:55:52 +08:00
|
|
|
#include "longobject.h"
|
|
|
|
#include "floatobject.h"
|
|
|
|
#ifndef WITHOUT_COMPLEX
|
|
|
|
#include "complexobject.h"
|
|
|
|
#endif
|
|
|
|
#include "rangeobject.h"
|
|
|
|
#include "stringobject.h"
|
1998-10-07 22:36:10 +08:00
|
|
|
#include "bufferobject.h"
|
1997-05-02 11:55:52 +08:00
|
|
|
#include "tupleobject.h"
|
|
|
|
#include "listobject.h"
|
1997-05-14 05:23:32 +08:00
|
|
|
#include "dictobject.h"
|
2002-04-27 03:40:56 +08:00
|
|
|
#include "enumobject.h"
|
1997-05-02 11:55:52 +08: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-26 04:04:14 +08:00
|
|
|
#include "cellobject.h"
|
2001-04-21 03:13:02 +08:00
|
|
|
#include "iterobject.h"
|
2001-08-02 12:15:00 +08:00
|
|
|
#include "descrobject.h"
|
2001-10-06 05:55:19 +08:00
|
|
|
#include "weakrefobject.h"
|
1997-05-02 11:55:52 +08:00
|
|
|
|
2000-03-11 06:34:00 +08:00
|
|
|
#include "codecs.h"
|
1997-05-02 11:55:52 +08:00
|
|
|
#include "pyerrors.h"
|
|
|
|
|
1997-07-19 07:59:26 +08:00
|
|
|
#include "pystate.h"
|
|
|
|
|
1997-05-02 11:55:52 +08:00
|
|
|
#include "modsupport.h"
|
|
|
|
#include "pythonrun.h"
|
2001-07-16 10:29:45 +08:00
|
|
|
#include "ceval.h"
|
1997-05-02 11:55:52 +08:00
|
|
|
#include "sysmodule.h"
|
|
|
|
#include "intrcheck.h"
|
|
|
|
#include "import.h"
|
|
|
|
|
|
|
|
#include "abstract.h"
|
|
|
|
|
2002-06-21 06:23:15 +08:00
|
|
|
/* _Py_Mangle is defined in compile.c */
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(int) _Py_Mangle(char *p, char *name, \
|
2002-06-21 06:23:15 +08:00
|
|
|
char *buffer, size_t maxlen);
|
|
|
|
|
2002-03-26 06:21:58 +08:00
|
|
|
/* PyArg_GetInt is deprecated and should not be used, use PyArg_Parse(). */
|
1997-05-02 11:55:52 +08:00
|
|
|
#define PyArg_GetInt(v, a) PyArg_Parse((v), "i", (a))
|
2002-03-26 04:46:46 +08:00
|
|
|
|
|
|
|
/* PyArg_NoArgs should not be necessary.
|
|
|
|
Set ml_flags in the PyMethodDef to METH_NOARGS. */
|
1997-05-02 11:55:52 +08: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-29 04:29:48 +08:00
|
|
|
/* These definitions must match corresponding definitions in graminit.h.
|
1997-05-08 01:46:13 +08: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 08:46:46 +08:00
|
|
|
#ifdef HAVE_PTH
|
2000-05-08 21:41:38 +08:00
|
|
|
/* GNU pth user-space thread support */
|
|
|
|
#include <pth.h>
|
|
|
|
#endif
|
2002-06-09 21:33:54 +08: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 12:00:11 +08:00
|
|
|
#endif /* !Py_PYTHON_H */
|