Commit de372d48 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Import some more CPython header files, and make some small Pyston tweaks to others

parent d9a7134d
......@@ -25,6 +25,15 @@
#include <limits.h>
// These belong in pyconfig.h:
#define HAVE_STDARG_PROTOTYPES
#define HAVE_LONG_LONG 1
#define PY_LONG_LONG long long
#define SIZEOF_VOID_P 8
#define SIZEOF_SIZE_T 8
#define SIZEOF_INT 4
// These include orders come from CPython:
#include "patchlevel.h"
......@@ -35,15 +44,21 @@
#include "object.h"
#include "objimpl.h"
#include "pydebug.h"
#include "intobject.h"
#include "boolobject.h"
#include "longobject.h"
#include "floatobject.h"
#ifndef WITHOUT_COMPLEX
#include "complexobject.h"
#endif
#include "stringobject.h"
#include "listobject.h"
#include "dictobject.h"
#include "tupleobject.h"
#include "methodobject.h"
#include "pycapsule.h"
#include "iterobject.h"
#include "descrobject.h"
#include "warnings.h"
......@@ -55,6 +70,10 @@
#include "abstract.h"
// directly from CPython:
/* Argument must be a char or an int in [-128, 127] or [0, 255]. */
#define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
#ifdef __cplusplus
extern "C" {
#endif
......
......@@ -11,7 +11,9 @@ extern "C" {
typedef PyIntObject PyBoolObject;
PyAPI_DATA(PyTypeObject) PyBool_Type;
// Pyston change: this is no longer a static object
PyAPI_DATA(PyTypeObject*) bool_cls;
#define PyBool_Type (*bool_cls)
#define PyBool_Check(x) (Py_TYPE(x) == &PyBool_Type)
......
// This file is originally from CPython 2.7, with modifications for Pyston
/* Complex number structure */
#ifndef Py_COMPLEXOBJECT_H
#define Py_COMPLEXOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
double real;
double imag;
} Py_complex;
/* Operations on complex numbers from complexmodule.c */
#define c_sum _Py_c_sum
#define c_diff _Py_c_diff
#define c_neg _Py_c_neg
#define c_prod _Py_c_prod
#define c_quot _Py_c_quot
#define c_pow _Py_c_pow
#define c_abs _Py_c_abs
PyAPI_FUNC(Py_complex) c_sum(Py_complex, Py_complex);
PyAPI_FUNC(Py_complex) c_diff(Py_complex, Py_complex);
PyAPI_FUNC(Py_complex) c_neg(Py_complex);
PyAPI_FUNC(Py_complex) c_prod(Py_complex, Py_complex);
PyAPI_FUNC(Py_complex) c_quot(Py_complex, Py_complex);
PyAPI_FUNC(Py_complex) c_pow(Py_complex, Py_complex);
PyAPI_FUNC(double) c_abs(Py_complex);
/* Complex object interface */
/*
PyComplexObject represents a complex number with double-precision
real and imaginary parts.
*/
typedef struct {
PyObject_HEAD
Py_complex cval;
} PyComplexObject;
PyAPI_DATA(PyTypeObject) PyComplex_Type;
#define PyComplex_Check(op) PyObject_TypeCheck(op, &PyComplex_Type)
#define PyComplex_CheckExact(op) (Py_TYPE(op) == &PyComplex_Type)
PyAPI_FUNC(PyObject *) PyComplex_FromCComplex(Py_complex);
PyAPI_FUNC(PyObject *) PyComplex_FromDoubles(double real, double imag);
PyAPI_FUNC(double) PyComplex_RealAsDouble(PyObject *op);
PyAPI_FUNC(double) PyComplex_ImagAsDouble(PyObject *op);
PyAPI_FUNC(Py_complex) PyComplex_AsCComplex(PyObject *op);
/* Format the object based on the format_spec, as defined in PEP 3101
(Advanced String Formatting). */
PyAPI_FUNC(PyObject *) _PyComplex_FormatAdvanced(PyObject *obj,
char *format_spec,
Py_ssize_t format_spec_len);
#ifdef __cplusplus
}
#endif
#endif /* !Py_COMPLEXOBJECT_H */
......@@ -22,7 +22,9 @@ typedef struct {
#endif
typedef void PyFloatObject;
PyAPI_DATA(PyTypeObject) PyFloat_Type;
// Pyston change: this is no longer a static object
PyAPI_DATA(PyTypeObject*) float_cls;
#define PyFloat_Type (*float_cls)
#define PyFloat_Check(op) PyObject_TypeCheck(op, &PyFloat_Type)
#define PyFloat_CheckExact(op) (Py_TYPE(op) == &PyFloat_Type)
......
......@@ -31,7 +31,9 @@ typedef struct {
#endif
typedef void PyIntObject;
PyAPI_DATA(PyTypeObject) PyInt_Type;
// Pyston change: this is no longer a static object
PyAPI_DATA(PyTypeObject*) int_cls;
#define PyInt_Type (*int_cls)
// Pyston changes: these aren't direct macros any more [they potentially could be though]
PyAPI_FUNC(bool) PyInt_Check(PyObject*);
......
......@@ -43,7 +43,9 @@ typedef struct {
#endif
typedef void PyListObject;
PyAPI_DATA(PyTypeObject) PyList_Type;
// Pyston change: this is no longer a static object
PyAPI_DATA(PyTypeObject*) list_cls;
#define PyList_Type (*list_cls)
// Pyston changes: these aren't direct macros any more [they potentially could be though]
PyAPI_FUNC(bool) PyList_Check(PyObject*);
......
......@@ -15,7 +15,9 @@ typedef struct _longobject PyLongObject; /* Revealed in longintrepr.h */
#endif
typedef void PyLongObject;
PyAPI_DATA(PyTypeObject) PyLong_Type;
// Pyston change: this is no longer a static object
PyAPI_DATA(PyTypeObject*) long_cls;
#define PyLong_Type (*long_cls)
// Pyston changes: these aren't direct macros any more [they potentially could be though]
PyAPI_FUNC(bool) PyLong_Check(PyObject*);
......
......@@ -112,22 +112,25 @@ struct _object {
PyObject_HEAD
};
struct _varobject {
PyObject_VAR_HEAD
};
// Pyston change: hacks to allow C++ features
#ifndef __cplusplus
typedef struct _object PyObject;
typedef struct _varobject PyVarObject;
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
#else
namespace pyston {
class Box;
class BoxVar;
}
typedef pyston::Box PyObject;
typedef pyston::BoxVar PyVarObject;
#define Py_TYPE(ob) ((ob)->cls)
#endif
typedef struct {
PyObject_VAR_HEAD
} PyVarObject;
// Pyston change: removed Py_REFCNT, moved Py_TYPE to above
#define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
......
......@@ -163,7 +163,7 @@ PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t);
/* Macros trading binary compatibility for speed. See also pymem.h.
Note that these macros expect non-NULL object pointers.*/
#define PyObject_INIT(op, typeobj) \
( Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
( Py_TYPE(op) = (typeobj), (op) )
#define PyObject_INIT_VAR(op, typeobj, size) \
( Py_SIZE(op) = (size), PyObject_INIT((op), (typeobj)) )
......
// This file is originally from CPython 2.7, with modifications for Pyston
/* Capsule objects let you wrap a C "void *" pointer in a Python
object. They're a way of passing data through the Python interpreter
without creating your own custom type.
Capsules are used for communication between extension modules.
They provide a way for an extension module to export a C interface
to other extension modules, so that extension modules can use the
Python import mechanism to link to one another.
For more information, please see "c-api/capsule.html" in the
documentation.
*/
#ifndef Py_CAPSULE_H
#define Py_CAPSULE_H
#ifdef __cplusplus
extern "C" {
#endif
PyAPI_DATA(PyTypeObject) PyCapsule_Type;
typedef void (*PyCapsule_Destructor)(PyObject *);
#define PyCapsule_CheckExact(op) (Py_TYPE(op) == &PyCapsule_Type)
PyAPI_FUNC(PyObject *) PyCapsule_New(
void *pointer,
const char *name,
PyCapsule_Destructor destructor);
PyAPI_FUNC(void *) PyCapsule_GetPointer(PyObject *capsule, const char *name);
PyAPI_FUNC(PyCapsule_Destructor) PyCapsule_GetDestructor(PyObject *capsule);
PyAPI_FUNC(const char *) PyCapsule_GetName(PyObject *capsule);
PyAPI_FUNC(void *) PyCapsule_GetContext(PyObject *capsule);
PyAPI_FUNC(int) PyCapsule_IsValid(PyObject *capsule, const char *name);
PyAPI_FUNC(int) PyCapsule_SetPointer(PyObject *capsule, void *pointer);
PyAPI_FUNC(int) PyCapsule_SetDestructor(PyObject *capsule, PyCapsule_Destructor destructor);
PyAPI_FUNC(int) PyCapsule_SetName(PyObject *capsule, const char *name);
PyAPI_FUNC(int) PyCapsule_SetContext(PyObject *capsule, void *context);
PyAPI_FUNC(void *) PyCapsule_Import(const char *name, int no_block);
#ifdef __cplusplus
}
#endif
#endif /* !Py_CAPSULE_H */
// This file is originally from CPython 2.7, with modifications for Pyston
#ifndef Py_PYDEBUG_H
#define Py_PYDEBUG_H
#ifdef __cplusplus
extern "C" {
#endif
PyAPI_DATA(int) Py_DebugFlag;
PyAPI_DATA(int) Py_VerboseFlag;
PyAPI_DATA(int) Py_InteractiveFlag;
PyAPI_DATA(int) Py_InspectFlag;
PyAPI_DATA(int) Py_OptimizeFlag;
PyAPI_DATA(int) Py_NoSiteFlag;
PyAPI_DATA(int) Py_BytesWarningFlag;
PyAPI_DATA(int) Py_UseClassExceptionsFlag;
PyAPI_DATA(int) Py_FrozenFlag;
PyAPI_DATA(int) Py_TabcheckFlag;
PyAPI_DATA(int) Py_UnicodeFlag;
PyAPI_DATA(int) Py_IgnoreEnvironmentFlag;
PyAPI_DATA(int) Py_DivisionWarningFlag;
PyAPI_DATA(int) Py_DontWriteBytecodeFlag;
PyAPI_DATA(int) Py_NoUserSiteDirectory;
/* _XXX Py_QnewFlag should go away in 3.0. It's true iff -Qnew is passed,
on the command line, and is used in 2.2 by ceval.c to make all "/" divisions
true divisions (which they will be in 3.0). */
PyAPI_DATA(int) _Py_QnewFlag;
/* Warn about 3.x issues */
PyAPI_DATA(int) Py_Py3kWarningFlag;
PyAPI_DATA(int) Py_HashRandomizationFlag;
/* this is a wrapper around getenv() that pays attention to
Py_IgnoreEnvironmentFlag. It should be used for getting variables like
PYTHONPATH and PYTHONHOME from the environment */
#define Py_GETENV(s) (Py_IgnoreEnvironmentFlag ? NULL : getenv(s))
PyAPI_FUNC(void) Py_FatalError(const char *message);
#ifdef __cplusplus
}
#endif
#endif /* !Py_PYDEBUG_H */
......@@ -117,67 +117,123 @@ PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**);
/* Predefined exceptions */
PyAPI_DATA(PyObject *) PyExc_BaseException;
PyAPI_DATA(PyObject *) PyExc_Exception;
PyAPI_DATA(PyObject *) PyExc_StopIteration;
PyAPI_DATA(PyObject *) PyExc_GeneratorExit;
PyAPI_DATA(PyObject *) PyExc_StandardError;
PyAPI_DATA(PyObject *) PyExc_ArithmeticError;
PyAPI_DATA(PyObject *) PyExc_LookupError;
PyAPI_DATA(PyObject *) PyExc_AssertionError;
PyAPI_DATA(PyObject *) PyExc_AttributeError;
PyAPI_DATA(PyObject *) PyExc_EOFError;
PyAPI_DATA(PyObject *) PyExc_FloatingPointError;
PyAPI_DATA(PyObject *) PyExc_EnvironmentError;
PyAPI_DATA(PyObject *) PyExc_IOError;
PyAPI_DATA(PyObject *) PyExc_OSError;
PyAPI_DATA(PyObject *) PyExc_ImportError;
PyAPI_DATA(PyObject *) PyExc_IndexError;
PyAPI_DATA(PyObject *) PyExc_KeyError;
PyAPI_DATA(PyObject *) PyExc_KeyboardInterrupt;
PyAPI_DATA(PyObject *) PyExc_MemoryError;
PyAPI_DATA(PyObject *) PyExc_NameError;
PyAPI_DATA(PyObject *) PyExc_OverflowError;
PyAPI_DATA(PyObject *) PyExc_RuntimeError;
PyAPI_DATA(PyObject *) PyExc_NotImplementedError;
PyAPI_DATA(PyObject *) PyExc_SyntaxError;
PyAPI_DATA(PyObject *) PyExc_IndentationError;
PyAPI_DATA(PyObject *) PyExc_TabError;
PyAPI_DATA(PyObject *) PyExc_ReferenceError;
PyAPI_DATA(PyObject *) PyExc_SystemError;
PyAPI_DATA(PyObject *) PyExc_SystemExit;
PyAPI_DATA(PyObject *) PyExc_TypeError;
PyAPI_DATA(PyObject *) PyExc_UnboundLocalError;
PyAPI_DATA(PyObject *) PyExc_UnicodeError;
PyAPI_DATA(PyObject *) PyExc_UnicodeEncodeError;
PyAPI_DATA(PyObject *) PyExc_UnicodeDecodeError;
PyAPI_DATA(PyObject *) PyExc_UnicodeTranslateError;
PyAPI_DATA(PyObject *) PyExc_ValueError;
PyAPI_DATA(PyObject *) PyExc_ZeroDivisionError;
// Pyston change: make these just expand to casts around our internal types, which are declared
// as PyTypeObject's.
// TODO not sure if this is worth it -- a fair amount of confusion (duplicating these names) for fairly
// little gain (getting to treat them as PyTypeObject's and using our own names)
#define PyExc_BaseException ((PyObject*)BaseException)
PyAPI_DATA(PyTypeObject *) BaseException;
#define PyExc_Exception ((PyObject*)Exception)
PyAPI_DATA(PyTypeObject *) Exception;
#define PyExc_StopIteration ((PyObject*)StopIteration)
PyAPI_DATA(PyTypeObject *) StopIteration;
#define PyExc_GeneratorExit ((PyObject*)GeneratorExit)
PyAPI_DATA(PyTypeObject *) GeneratorExit;
#define PyExc_StandardError ((PyObject*)StandardError)
PyAPI_DATA(PyTypeObject *) StandardError;
#define PyExc_ArithmeticError ((PyObject*)ArithmeticError)
PyAPI_DATA(PyTypeObject *) ArithmeticError;
#define PyExc_LookupError ((PyObject*)LookupError)
PyAPI_DATA(PyTypeObject *) LookupError;
#define PyExc_AssertionError ((PyObject*)AssertionError)
PyAPI_DATA(PyTypeObject *) AssertionError;
#define PyExc_AttributeError ((PyObject*)AttributeError)
PyAPI_DATA(PyTypeObject *) AttributeError;
#define PyExc_EOFError ((PyObject*)EOFError)
PyAPI_DATA(PyTypeObject *) EOFError;
#define PyExc_FloatingPointError ((PyObject*)FloatingPointError)
PyAPI_DATA(PyTypeObject *) FloatingPointError;
#define PyExc_EnvironmentError ((PyObject*)EnvironmentError)
PyAPI_DATA(PyTypeObject *) EnvironmentError;
#define PyExc_IOError ((PyObject*)IOError)
PyAPI_DATA(PyTypeObject *) IOError;
#define PyExc_OSError ((PyObject*)OSError)
PyAPI_DATA(PyTypeObject *) OSError;
#define PyExc_ImportError ((PyObject*)ImportError)
PyAPI_DATA(PyTypeObject *) ImportError;
#define PyExc_IndexError ((PyObject*)IndexError)
PyAPI_DATA(PyTypeObject *) IndexError;
#define PyExc_KeyError ((PyObject*)KeyError)
PyAPI_DATA(PyTypeObject *) KeyError;
#define PyExc_KeyboardInterrupt ((PyObject*)KeyboardInterrupt)
PyAPI_DATA(PyTypeObject *) KeyboardInterrupt;
#define PyExc_MemoryError ((PyObject*)MemoryError)
PyAPI_DATA(PyTypeObject *) MemoryError;
#define PyExc_NameError ((PyObject*)NameError)
PyAPI_DATA(PyTypeObject *) NameError;
#define PyExc_OverflowError ((PyObject*)OverflowError)
PyAPI_DATA(PyTypeObject *) OverflowError;
#define PyExc_RuntimeError ((PyObject*)RuntimeError)
PyAPI_DATA(PyTypeObject *) RuntimeError;
#define PyExc_NotImplementedError ((PyObject*)NotImplementedError)
PyAPI_DATA(PyTypeObject *) NotImplementedError;
#define PyExc_SyntaxError ((PyObject*)SyntaxError)
PyAPI_DATA(PyTypeObject *) SyntaxError;
#define PyExc_IndentationError ((PyObject*)IndentationError)
PyAPI_DATA(PyTypeObject *) IndentationError;
#define PyExc_TabError ((PyObject*)TabError)
PyAPI_DATA(PyTypeObject *) TabError;
#define PyExc_ReferenceError ((PyObject*)ReferenceError)
PyAPI_DATA(PyTypeObject *) ReferenceError;
#define PyExc_SystemError ((PyObject*)SystemError)
PyAPI_DATA(PyTypeObject *) SystemError;
#define PyExc_SystemExit ((PyObject*)SystemExit)
PyAPI_DATA(PyTypeObject *) SystemExit;
#define PyExc_TypeError ((PyObject*)TypeError)
PyAPI_DATA(PyTypeObject *) TypeError;
#define PyExc_UnboundLocalError ((PyObject*)UnboundLocalError)
PyAPI_DATA(PyTypeObject *) UnboundLocalError;
#define PyExc_UnicodeError ((PyObject*)UnicodeError)
PyAPI_DATA(PyTypeObject *) UnicodeError;
#define PyExc_UnicodeEncodeError ((PyObject*)UnicodeEncodeError)
PyAPI_DATA(PyTypeObject *) UnicodeEncodeError;
#define PyExc_UnicodeDecodeError ((PyObject*)UnicodeDecodeError)
PyAPI_DATA(PyTypeObject *) UnicodeDecodeError;
#define PyExc_UnicodeTranslateError ((PyObject*)UnicodeTranslateError)
PyAPI_DATA(PyTypeObject *) UnicodeTranslateError;
#define PyExc_ValueError ((PyObject*)ValueError)
PyAPI_DATA(PyTypeObject *) ValueError;
#define PyExc_ZeroDivisionError ((PyObject*)ZeroDivisionError)
PyAPI_DATA(PyTypeObject *) ZeroDivisionError;
#ifdef MS_WINDOWS
PyAPI_DATA(PyObject *) PyExc_WindowsError;
#define PyExc_WindowsError ((PyObject*)WindowsError)
PyAPI_DATA(PyTypeObject *) WindowsError;
#endif
#ifdef __VMS
PyAPI_DATA(PyObject *) PyExc_VMSError;
#define PyExc_VMSError ((PyObject*)VMSError)
PyAPI_DATA(PyTypeObject *) VMSError;
#endif
PyAPI_DATA(PyObject *) PyExc_BufferError;
#define PyExc_BufferError ((PyObject*)BufferError)
PyAPI_DATA(PyTypeObject *) BufferError;
PyAPI_DATA(PyObject *) PyExc_MemoryErrorInst;
PyAPI_DATA(PyObject *) PyExc_RecursionErrorInst;
#define PyExc_MemoryErrorInst ((PyObject*)MemoryErrorInst)
PyAPI_DATA(PyTypeObject *) MemoryErrorInst;
#define PyExc_RecursionErrorInst ((PyObject*)RecursionErrorInst)
PyAPI_DATA(PyTypeObject *) RecursionErrorInst;
/* Predefined warning categories */
PyAPI_DATA(PyObject *) PyExc_Warning;
PyAPI_DATA(PyObject *) PyExc_UserWarning;
PyAPI_DATA(PyObject *) PyExc_DeprecationWarning;
PyAPI_DATA(PyObject *) PyExc_PendingDeprecationWarning;
PyAPI_DATA(PyObject *) PyExc_SyntaxWarning;
PyAPI_DATA(PyObject *) PyExc_RuntimeWarning;
PyAPI_DATA(PyObject *) PyExc_FutureWarning;
PyAPI_DATA(PyObject *) PyExc_ImportWarning;
PyAPI_DATA(PyObject *) PyExc_UnicodeWarning;
PyAPI_DATA(PyObject *) PyExc_BytesWarning;
#define PyExc_Warning ((PyObject*)Warning)
PyAPI_DATA(PyTypeObject *) Warning;
#define PyExc_UserWarning ((PyObject*)UserWarning)
PyAPI_DATA(PyTypeObject *) UserWarning;
#define PyExc_DeprecationWarning ((PyObject*)DeprecationWarning)
PyAPI_DATA(PyTypeObject *) DeprecationWarning;
#define PyExc_PendingDeprecationWarning ((PyObject*)PendingDeprecationWarning)
PyAPI_DATA(PyTypeObject *) PendingDeprecationWarning;
#define PyExc_SyntaxWarning ((PyObject*)SyntaxWarning)
PyAPI_DATA(PyTypeObject *) SyntaxWarning;
#define PyExc_RuntimeWarning ((PyObject*)RuntimeWarning)
PyAPI_DATA(PyTypeObject *) RuntimeWarning;
#define PyExc_FutureWarning ((PyObject*)FutureWarning)
PyAPI_DATA(PyTypeObject *) FutureWarning;
#define PyExc_ImportWarning ((PyObject*)ImportWarning)
PyAPI_DATA(PyTypeObject *) ImportWarning;
#define PyExc_UnicodeWarning ((PyObject*)UnicodeWarning)
PyAPI_DATA(PyTypeObject *) UnicodeWarning;
#define PyExc_BytesWarning ((PyObject*)BytesWarning)
PyAPI_DATA(PyTypeObject *) BytesWarning;
/* Convenience functions */
......@@ -216,7 +272,8 @@ PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
/* Export the old function so that the existing API remains available: */
PyAPI_FUNC(void) PyErr_BadInternalCall(void);
PyAPI_FUNC(void) _PyErr_BadInternalCall(char *filename, int lineno);
// Pyston change: changed this from char* to const char*
PyAPI_FUNC(void) _PyErr_BadInternalCall(const char *filename, int lineno);
/* Mask the old API with a call to the new API for code compiled under
Python 2.0: */
#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
......
......@@ -7,14 +7,9 @@
#include <stdint.h>
// Pyston change: these are just hard-coded for now:
#define SIZEOF_VOID_P 8
#define SIZEOF_SIZE_T 8
#define SIZEOF_INT 4
typedef ssize_t Py_ssize_t;
#define Py_FORMAT_PARSETUPLE(func,p1,p2)
#define Py_GCC_ATTRIBUTE(x) __attribute__(x)
#define HAVE_LONG_LONG 1
#define PY_LONG_LONG long long
......
......@@ -57,7 +57,9 @@ typedef struct {
#define SSTATE_INTERNED_IMMORTAL 2
PyAPI_DATA(PyTypeObject) PyBaseString_Type;
PyAPI_DATA(PyTypeObject) PyString_Type;
// Pyston change: this is no longer a static object
PyAPI_DATA(PyTypeObject*) str_cls;
#define PyString_Type (*str_cls)
// Pyston changes: these aren't direct macros any more [they potentially could be though]
PyAPI_FUNC(bool) PyString_Check(PyObject*);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment