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