Commit 1354c854 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Add a bunch of CAPI support

This gets pycurl and PIL working.

Unfortunately I can't figure out a great way to test this; pycurl
has external dependencies, and PIL only works with some workarounds
that I don't want to check in.  I think these features are
innoccuous enough that it's worth getting these in.
parent abb040c5
......@@ -74,6 +74,7 @@
#include "setobject.h"
#include "methodobject.h"
#include "moduleobject.h"
#include "funcobject.h"
#include "classobject.h"
#include "cobject.h"
#include "fileobject.h"
......
// This file is originally from CPython 2.7, with modifications for Pyston
/* Function object interface */
#ifndef Py_FUNCOBJECT_H
#define Py_FUNCOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Function objects and code objects should not be confused with each other:
*
* Function objects are created by the execution of the 'def' statement.
* They reference a code object in their func_code attribute, which is a
* purely syntactic object, i.e. nothing more than a compiled version of some
* source code lines. There is one code object per source code "fragment",
* but each code object can be referenced by zero or many function objects
* depending only on how many times the 'def' statement in the source was
* executed so far.
*/
// Pyston change: not our object format
#if 0
typedef struct {
PyObject_HEAD
PyObject *func_code; /* A code object */
PyObject *func_globals; /* A dictionary (other mappings won't do) */
PyObject *func_defaults; /* NULL or a tuple */
PyObject *func_closure; /* NULL or a tuple of cell objects */
PyObject *func_doc; /* The __doc__ attribute, can be anything */
PyObject *func_name; /* The __name__ attribute, a string object */
PyObject *func_dict; /* The __dict__ attribute, a dict or NULL */
PyObject *func_weakreflist; /* List of weak references */
PyObject *func_module; /* The __module__ attribute, can be anything */
/* Invariant:
* func_closure contains the bindings for func_code->co_freevars, so
* PyTuple_Size(func_closure) == PyCode_GetNumFree(func_code)
* (func_closure may be NULL if PyCode_GetNumFree(func_code) == 0).
*/
} PyFunctionObject;
#endif
// Pyston change: not a static object any more
//PyAPI_DATA(PyTypeObject) PyFunction_Type;
PyAPI_DATA(PyTypeObject*) function_cls;
#define PyFunction_Type (*function_cls)
#define PyFunction_Check(op) (Py_TYPE(op) == &PyFunction_Type)
PyAPI_FUNC(PyObject *) PyFunction_New(PyObject *, PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyFunction_GetCode(PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyFunction_GetGlobals(PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyFunction_GetModule(PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyFunction_GetDefaults(PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(int) PyFunction_SetDefaults(PyObject *, PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyFunction_GetClosure(PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(int) PyFunction_SetClosure(PyObject *, PyObject *) PYSTON_NOEXCEPT;
// Pyston change: no longer macros
#if 0
/* Macros for direct access to these values. Type checks are *not*
done, so use with care. */
#define PyFunction_GET_CODE(func) \
(((PyFunctionObject *)func) -> func_code)
#define PyFunction_GET_GLOBALS(func) \
(((PyFunctionObject *)func) -> func_globals)
#define PyFunction_GET_MODULE(func) \
(((PyFunctionObject *)func) -> func_module)
#define PyFunction_GET_DEFAULTS(func) \
(((PyFunctionObject *)func) -> func_defaults)
#define PyFunction_GET_CLOSURE(func) \
(((PyFunctionObject *)func) -> func_closure)
#endif
#define PyFunction_GET_CODE(func) (PyFunction_GetCode((PyObject *)(func)))
#define PyFunction_GET_GLOBALS(func) (PyFunction_GetGlobals((PyObject *)(func)))
#define PyFunction_GET_MODULE(func) (PyFunction_GetModule((PyObject *)(func)))
#define PyFunction_GET_DEFAULTS(func) (PyFunction_GetDefaults((PyObject *)(func)))
#define PyFunction_GET_CLOSURE(func) (PyFunction_GetClosure((PyObject *)(func)))
// Pyston change: not a static object any more
#if 0
/* The classmethod and staticmethod types lives here, too */
PyAPI_DATA(PyTypeObject) PyClassMethod_Type;
PyAPI_DATA(PyTypeObject) PyStaticMethod_Type;
#endif
PyAPI_DATA(PyTypeObject*) classmethod_cls;
#define PyClassMethod_Type (*classmethod_cls)
PyAPI_DATA(PyTypeObject*) staticmethod_cls;
#define PyStaticMethod_Type (*staticmethod_cls)
PyAPI_FUNC(PyObject *) PyClassMethod_New(PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyStaticMethod_New(PyObject *) PYSTON_NOEXCEPT;
#ifdef __cplusplus
}
#endif
#endif /* !Py_FUNCOBJECT_H */
......@@ -1044,6 +1044,9 @@ PyAPI_FUNC(void) _PyTrash_thread_destroy_chain(void) PYSTON_NOEXCEPT;
#define PyTrash_UNWIND_LEVEL 50
// Pyston change: I don't think we need this since destructors
// are run differently
#if 0
/* Note the workaround for when the thread state is NULL (issue #17703) */
#define Py_TRASHCAN_SAFE_BEGIN(op) \
do { \
......@@ -1064,6 +1067,9 @@ PyAPI_FUNC(void) _PyTrash_thread_destroy_chain(void) PYSTON_NOEXCEPT;
else \
_PyTrash_thread_deposit_object((PyObject*)op); \
} while (0);
#endif
#define Py_TRASHCAN_SAFE_BEGIN(op) do {
#define Py_TRASHCAN_SAFE_END(op) } while (0);
#ifdef __cplusplus
}
......
......@@ -60,6 +60,8 @@
#define HAVE_TIMES 1
#define HAVE_STRUCT_TM_TM_ZONE 1
#define HAVE_MKTIME 1
#define HAVE_PROTOTYPES 1
#define STDC_HEADERS 1
#define TIME_WITH_SYS_TIME
#define HAVE_GETTIMEOFDAY 1
......
......@@ -714,7 +714,7 @@ void Assembler::cmp(Register reg, Immediate imm) {
int reg_idx = reg.regnum;
int rex = REX_W;
if (reg_idx > 8) {
if (reg_idx >= 8) {
rex |= REX_B;
reg_idx -= 8;
}
......
......@@ -1241,6 +1241,26 @@ extern "C" void PyEval_InitThreads(void) noexcept {
// nothing to do here
}
extern "C" void PyEval_AcquireThread(PyThreadState* tstate) noexcept {
Py_FatalError("Unimplemented");
}
extern "C" void PyEval_ReleaseThread(PyThreadState* tstate) noexcept {
Py_FatalError("Unimplemented");
}
extern "C" PyThreadState* PyThreadState_Get(void) noexcept {
Py_FatalError("Unimplemented");
}
extern "C" PyThreadState* PyEval_SaveThread(void) noexcept {
Py_FatalError("Unimplemented");
}
extern "C" void PyEval_RestoreThread(PyThreadState* tstate) noexcept {
Py_FatalError("Unimplemented");
}
extern "C" char* PyModule_GetName(PyObject* m) noexcept {
PyObject* d;
PyObject* nameobj;
......
......@@ -437,6 +437,18 @@ Box* dictContains(BoxedDict* self, Box* k) {
return boxBool(self->d.count(k) != 0);
}
/* Return 1 if `key` is in dict `op`, 0 if not, and -1 on error. */
extern "C" int PyDict_Contains(PyObject* op, PyObject* key) noexcept {
BoxedDict* mp = (BoxedDict*)op;
try {
return mp->getOrNull(key) ? 1 : 0;
} catch (ExcInfo e) {
setCAPIException(e);
return -1;
}
}
Box* dictNonzero(BoxedDict* self) {
return boxBool(self->d.size());
}
......
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