Commit 3407b2de authored by Marius Wachtler's avatar Marius Wachtler

Merge pull request #1229 from Daetalus/scipy_fixing_1_nexedi

Some fixings that let scipy tests pass.
parents e7174486 2c79c3fb
......@@ -190,8 +190,7 @@ typedef struct bufferinfo {
pointed to by strides in simple case.*/
int readonly;
int ndim;
// Pyston change: changed this from char* to const char*
const char *format;
PYSTON_CONST char *format;
Py_ssize_t *shape;
Py_ssize_t *strides;
Py_ssize_t *suboffsets;
......
......@@ -16,6 +16,12 @@
#define PYSTON_NOEXCEPT
#endif
#ifdef _PYSTON_API
#define PYSTON_CONST const
#else
#define PYSTON_CONST
#endif
#define Py_PROTO(x) x
// Pyston change: these are just hard-coded for now:
......
......@@ -3557,6 +3557,12 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept {
if (base == NULL)
base = cls->tp_base = object_cls;
// Initialize the base class
if (base != NULL && unlikely(base->tp_dict == NULL) && !(base->is_pyston_class)) {
int ret = PyType_Ready(base);
assert(ret == 0);
}
// CPython only increfs the base if it picked one, not if it one was passed in.
// Not sure why.
Py_INCREF(base);
......
......@@ -220,7 +220,7 @@ extern "C" Box* complexDivFloat(BoxedComplex* lhs, BoxedFloat* rhs) {
if (!PyComplex_Check(lhs))
raiseExcHelper(TypeError, "descriptor '__div__' requires a 'complex' object but received a '%s'",
getTypeName(lhs));
assert(rhs->cls == float_cls);
assert(PyFloat_Check(rhs));
if (rhs->d == 0.0) {
raiseDivZeroExc();
}
......
......@@ -110,16 +110,40 @@ extern "C" unsigned long PyInt_AsUnsignedLongMask(PyObject* op) noexcept {
}
extern "C" long PyInt_AsLong(PyObject* op) noexcept {
// This method should do quite a bit more, including checking tp_as_number->nb_int (or calling __int__?)
PyNumberMethods* nb;
BoxedInt* io;
long val;
if (PyInt_Check(op))
if (op && PyInt_Check(op))
return static_cast<BoxedInt*>(op)->n;
if (op->cls == long_cls)
return PyLong_AsLong(op);
if (op == NULL || (nb = Py_TYPE(op)->tp_as_number) == NULL || nb->nb_int == NULL) {
PyErr_SetString(PyExc_TypeError, "an integer is required");
return -1;
}
io = (BoxedInt*)(*nb->nb_int)(op);
if (io == NULL)
return -1;
if (!PyInt_Check(io)) {
if (PyLong_Check(io)) {
/* got a long? => retry int conversion */
val = PyLong_AsLong((PyObject*)io);
Py_DECREF(io);
if ((val == -1) && PyErr_Occurred())
return -1;
return val;
} else {
Py_DECREF(io);
PyErr_SetString(PyExc_TypeError, "__int__ method should return an integer");
return -1;
}
}
val = static_cast<BoxedInt*>(io)->n;
Py_DECREF(io);
PyErr_SetString(PyExc_TypeError, "an integer is required");
return -1;
return val;
}
extern "C" Py_ssize_t PyInt_AsSsize_t(PyObject* op) noexcept {
......
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/build/lib.linux-x86_64-2.7/basic_test.so
COMMAND python setup.py build --build-lib ${CMAKE_CURRENT_BINARY_DIR}/build/lib.linux-x86_64-2.7
DEPENDS basic_test.c descr_test.c slots_test.c
DEPENDS basic_test.c descr_test.c slots_test.c type_test.c
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/basic_test.pyston.so
COMMAND ${CMAKE_BINARY_DIR}/pyston setup.py build --build-lib ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS pyston copy_stdlib copy_libpyston basic_test.c descr_test.c slots_test.c
DEPENDS pyston copy_stdlib copy_libpyston basic_test.c descr_test.c slots_test.c type_test.c
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_target(ext_cpython DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/build/lib.linux-x86_64-2.7/basic_test.so)
......
......@@ -6,6 +6,7 @@ extensions = [
Extension("basic_test", sources = ["basic_test.c"]),
Extension("descr_test", sources = ["descr_test.c"]),
Extension("slots_test", sources = ["slots_test.c"]),
Extension("type_test", sources = ["type_test.c"]),
]
def relpath(fn):
......
#include <Python.h>
typedef struct {
PyObject_HEAD
} SimpleObject;
static PyTypeObject BaseObjectType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
"type_test.Base", /* tp_name */
sizeof(SimpleObject), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"Act as a ase type.", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
static PyTypeObject SubObjectType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
"type_test.Sub", /* tp_name */
sizeof(SimpleObject), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"Act as a subtype", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
&BaseObjectType,/* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
PyMODINIT_FUNC
inittype_test(void)
{
PyObject* m;
SubObjectType.tp_new = PyType_GenericNew;
if (PyType_Ready(&SubObjectType) < 0)
return;
m = Py_InitModule3("type_test", NULL,
"A module that creates two extension type.");
if (m == NULL)
return;
Py_INCREF(&SubObjectType);
PyModule_AddObject(m, "Sub", (PyObject *)&SubObjectType);
}
......@@ -68,3 +68,9 @@ for x in data:
arg2=y)))
except Exception as e:
print(e.message)
class F(float):
pass
print(1j.__truediv__(F(1)))
......@@ -39,6 +39,14 @@ class D(object):
def __int__(self):
return self.n
class E(object):
def __int__(self):
print "__int__ called"
return 42
print(chr(E()))
for a in (False, True, 2, 3.0, D(4), D(C(5)), D(False)):
i = int.__new__(C, a)
print type(i), i, type(int(a))
......
import type_test
print("Hello")
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