Commit 7c7bb89b authored by Kevin Modzelewski's avatar Kevin Modzelewski

Harden the CAPI include files a bit

Remove some definitions that should no longer be in there
(structs for which we have Pyston-internal definitions).

Instead of doing "typedef void PyIntObject", do
"struct _PyIntObject; typedef struct _PyIntObject PyIntObject;"
which prevents spurious things like type conversions or
sizeof(void)'s.
parent eb9aef0a
......@@ -9,7 +9,10 @@ extern "C" {
#endif
typedef PyIntObject PyBoolObject;
// Pyston change: Try to avoid having to support mixing ints and bools
// typedef PyIntObject PyBoolObject;
struct _PyBoolObject;
typedef struct _PyBoolObject PyBoolObject;
// Pyston change: this is no longer a static object
PyAPI_DATA(PyTypeObject*) bool_cls;
......
......@@ -39,12 +39,18 @@ PyComplexObject represents a complex number with double-precision
real and imaginary parts.
*/
// Pyston change: this is not our object format
#if 0
typedef struct {
PyObject_HEAD
Py_complex cval;
} PyComplexObject;
#endif
PyAPI_DATA(PyTypeObject) PyComplex_Type;
// Pyston change: this is not a static object any more
// PyAPI_DATA(PyTypeObject) PyComplex_Type;
PyAPI_DATA(PyTypeObject*) complex_cls;
#define PyComplex_Type (*complex_cls)
#define PyComplex_Check(op) PyObject_TypeCheck(op, &PyComplex_Type)
#define PyComplex_CheckExact(op) (Py_TYPE(op) == &PyComplex_Type)
......
......@@ -39,6 +39,8 @@ struct wrapperbase {
/* Various kinds of descriptor objects */
// Pyston change: these are not our object layouts
#if 0
#define PyDescr_COMMON \
PyObject_HEAD \
PyTypeObject *d_type; \
......@@ -68,11 +70,17 @@ typedef struct {
struct wrapperbase *d_base;
void *d_wrapped; /* This can be any function pointer */
} PyWrapperDescrObject;
#endif
// (Pyston TODO: add opaque definitions of those names)
// Pyston change: these are not static objects any more
#if 0
PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;
PyAPI_DATA(PyTypeObject) PyDictProxy_Type;
PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type;
PyAPI_DATA(PyTypeObject) PyMemberDescr_Type;
#endif
// (Pyston TODO: add #defines to our names)
PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);
......
......@@ -20,7 +20,8 @@ typedef struct {
double ob_fval;
} PyFloatObject;
#endif
typedef void PyFloatObject;
struct _PyFloatObject;
typedef struct _PyFloatObject PyFloatObject;
// Pyston change: this is no longer a static object
PyAPI_DATA(PyTypeObject*) float_cls;
......@@ -62,7 +63,7 @@ PyAPI_FUNC(PyObject *) PyFloat_FromDouble(double);
speed. */
PyAPI_FUNC(double) PyFloat_AsDouble(PyObject *);
// Pyston changes: these aren't direct macros any more [they potentially could be though]
#define PyFloat_AS_DOUBLE(op) PyFloat_AsDouble(op)
#define PyFloat_AS_DOUBLE(op) PyFloat_AsDouble((PyObject*)op)
//#define PyFloat_AS_DOUBLE(op) (((PyFloatObject *)(op))->ob_fval)
/* Write repr(v) into the char buffer argument, followed by null byte. The
......
......@@ -29,7 +29,8 @@ typedef struct {
long ob_ival;
} PyIntObject;
#endif
typedef void PyIntObject;
struct _PyIntObject;
typedef struct _PyIntObject PyIntObject;
// Pyston change: this is no longer a static object
PyAPI_DATA(PyTypeObject*) int_cls;
......
......@@ -41,7 +41,8 @@ typedef struct {
Py_ssize_t allocated;
} PyListObject;
#endif
typedef void PyListObject;
struct _PyListObject;
typedef struct _PyListObject PyListObject;
// Pyston change: this is no longer a static object
PyAPI_DATA(PyTypeObject*) list_cls;
......
......@@ -13,7 +13,8 @@ extern "C" {
#if 0
typedef struct _longobject PyLongObject; /* Revealed in longintrepr.h */
#endif
typedef void PyLongObject;
struct _PyLongObject;
typedef struct _PyLongObject PyLongObject;
// Pyston change: this is no longer a static object
PyAPI_DATA(PyTypeObject*) long_cls;
......
......@@ -35,4 +35,7 @@
#define Py_USING_UNICODE 1
#define Py_UNICODE_SIZE 4
// Added this for some Pyston modifications:
#define MAX_PYSTRING_SIZE (PY_SSIZE_T_MAX/2 - (1<<20))
#endif /*Py_PYCONFIG_H*/
......@@ -8,6 +8,8 @@ extern "C" {
/* Error objects */
// Pyston change: these are not our object formats
#if 0
typedef struct {
PyObject_HEAD
PyObject *dict;
......@@ -72,6 +74,8 @@ typedef struct {
PyObject *winerror;
} PyWindowsErrorObject;
#endif
#endif
// (Pyston TODO: add opaque definitions of those names)
/* Error handling definitions */
......
......@@ -51,11 +51,8 @@ typedef struct {
*/
} PyStringObject;
#endif
// Pyston change: substitute this filler object that has the right size:
typedef struct {
PyObject_HEAD; // not a VAR_HEAD for now
char _filler[8];
} PyStringObject;
struct _PyStringObject;
typedef struct _PyStringObject PyStringObject;
#define SSTATE_NOT_INTERNED 0
#define SSTATE_INTERNED_MORTAL 1
......
......@@ -34,7 +34,8 @@ typedef struct {
*/
} PyTupleObject;
#endif
//typedef void PyTupleObject;
struct _PyTupleObject;
typedef struct _PyTupleObject PyTupleObject;
PyAPI_DATA(PyTypeObject) PyTuple_Type;
......
......@@ -414,6 +414,8 @@ extern "C" {
/* --- Unicode Type ------------------------------------------------------- */
// Pyston change: this is not our object format
#if 0
typedef struct {
PyObject_HEAD
Py_ssize_t length; /* Length of raw Unicode data in buffer */
......@@ -423,8 +425,14 @@ typedef struct {
string, or NULL; this is used for
implementing the buffer protocol */
} PyUnicodeObject;
#endif
struct _PyUnicodeObject;
typedef struct _PyUnicodeObject PyUnicodeObject;
PyAPI_DATA(PyTypeObject) PyUnicode_Type;
// Pyston change: this is no longer a static object
PyAPI_DATA(PyTypeObject*) unicode_cls;
#define PyUnicode_Type (*unicode_cls)
//PyAPI_DATA(PyTypeObject) PyUnicode_Type;
// Pyston changes: these aren't direct macros any more [they potentially could be though]
PyAPI_FUNC(bool) PyUnicode_Check(PyObject*);
......@@ -434,6 +442,8 @@ PyAPI_FUNC(bool) PyUnicode_Check(PyObject*);
#endif
#define PyUnicode_CheckExact(op) (Py_TYPE(op) == &PyUnicode_Type)
// Pyston changes: these aren't direct macros any more [they potentially could be though]
#if 0
/* Fast access macros */
#define PyUnicode_GET_SIZE(op) \
(((PyUnicodeObject *)(op))->length)
......@@ -443,6 +453,11 @@ PyAPI_FUNC(bool) PyUnicode_Check(PyObject*);
(((PyUnicodeObject *)(op))->str)
#define PyUnicode_AS_DATA(op) \
((const char *)((PyUnicodeObject *)(op))->str)
#endif
Py_ssize_t PyUnicode_GET_SIZE(PyObject*);
Py_ssize_t PyUnicode_GET_DATA_SIZE(PyObject*);
Py_UNICODE * PyUnicode_AS_UNICODE(PyObject*);
const char * PyUnicode_AS_DATA(PyObject*);
/* --- Constants ---------------------------------------------------------- */
......
......@@ -141,7 +141,9 @@ static char table_a2b_base64[] = {
#define BASE64_PAD '='
/* Max binary chunk size; limited only by available memory */
#define BASE64_MAXBIN (PY_SSIZE_T_MAX/2 - sizeof(PyStringObject) - 3)
// Pyston change: remove hardcoded assumptions about way strings are represented
//#define BASE64_MAXBIN (PY_SSIZE_T_MAX/2 - sizeof(PyStringObject) - 3)
#define BASE64_MAXBIN (MAX_PYSTRING_SIZE - 3)
static unsigned char table_b2a_base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
......
......@@ -936,6 +936,22 @@ extern "C" Py_ssize_t PyNumber_AsSsize_t(PyObject* o, PyObject* exc) {
Py_FatalError("unimplemented");
}
extern "C" Py_ssize_t PyUnicode_GET_SIZE(PyObject*) {
Py_FatalError("unimplemented");
}
extern "C" Py_ssize_t PyUnicode_GET_DATA_SIZE(PyObject*) {
Py_FatalError("unimplemented");
}
extern "C" Py_UNICODE* PyUnicode_AS_UNICODE(PyObject*) {
Py_FatalError("unimplemented");
}
extern "C" const char* PyUnicode_AS_DATA(PyObject*) {
Py_FatalError("unimplemented");
}
BoxedModule* importTestExtension(const std::string& name) {
std::string pathname_name = "test/test_extension/" + name + ".pyston.so";
const char* pathname = pathname_name.c_str();
......
......@@ -303,7 +303,6 @@ public:
BoxedString(const std::string&& s) __attribute__((visibility("default"))) : Box(str_cls), s(std::move(s)) {}
BoxedString(const std::string& s) __attribute__((visibility("default"))) : Box(str_cls), s(s) {}
};
static_assert(sizeof(BoxedString) == sizeof(PyStringObject), "");
class BoxedUnicode : public Box {
// TODO implementation
......
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