Commit d8b4aafb authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fix some more issues in the macro-to-function conversion

The macros would cast to PyObject*, but our functions would just take a PyObject* --
which is an issue if the argument is something else (like a PyListObject*).
We need to have wrapper macros that cast and then call the underlying function.
parent 6a83fd81
...@@ -123,7 +123,8 @@ PyAPI_DATA(PyTypeObject*) dictvalues_cls; ...@@ -123,7 +123,8 @@ PyAPI_DATA(PyTypeObject*) dictvalues_cls;
#define PyDictValues_Type (*dictvalues_cls) #define PyDictValues_Type (*dictvalues_cls)
// Pyston changes: these aren't direct macros any more [they potentially could be though] // Pyston changes: these aren't direct macros any more [they potentially could be though]
PyAPI_FUNC(bool) PyDict_Check(PyObject*) PYSTON_NOEXCEPT; PyAPI_FUNC(bool) _PyDict_Check(PyObject*) PYSTON_NOEXCEPT;
#define PyDict_Check(op) _PyDict_Check((PyObject*)(op))
#if 0 #if 0
#define PyDict_Check(op) \ #define PyDict_Check(op) \
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS) PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
......
...@@ -49,7 +49,8 @@ PyAPI_DATA(PyTypeObject*) list_cls; ...@@ -49,7 +49,8 @@ PyAPI_DATA(PyTypeObject*) list_cls;
#define PyList_Type (*list_cls) #define PyList_Type (*list_cls)
// Pyston changes: these aren't direct macros any more [they potentially could be though] // Pyston changes: these aren't direct macros any more [they potentially could be though]
PyAPI_FUNC(bool) PyList_Check(PyObject*) PYSTON_NOEXCEPT; PyAPI_FUNC(bool) _PyList_Check(PyObject*) PYSTON_NOEXCEPT;
#define PyList_Check(op) _PyList_Check((PyObject*)(op))
#if 0 #if 0
#define PyList_Check(op) \ #define PyList_Check(op) \
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS) PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS)
...@@ -71,9 +72,9 @@ PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *) PYSTON_NOEXCEP ...@@ -71,9 +72,9 @@ PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *) PYSTON_NOEXCEP
/* Macro, trading safety for speed */ /* Macro, trading safety for speed */
// Pyston changes: these aren't direct macros any more [they potentially could be though] // Pyston changes: these aren't direct macros any more [they potentially could be though]
#define PyList_GET_ITEM(op, i) PyList_GetItem(op, i) #define PyList_GET_ITEM(op, i) PyList_GetItem((PyObject*)(op), (i))
#define PyList_SET_ITEM(op, i, v) PyList_SetItem(op, i, v) #define PyList_SET_ITEM(op, i, v) PyList_SetItem((PyObject*)(op), (i), (v))
#define PyList_GET_SIZE(op) PyList_Size(op) #define PyList_GET_SIZE(op) PyList_Size((PyObject*)(op))
//#define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i]) //#define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])
//#define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v)) //#define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
//#define PyList_GET_SIZE(op) Py_SIZE(op) //#define PyList_GET_SIZE(op) Py_SIZE(op)
......
...@@ -21,7 +21,8 @@ PyAPI_DATA(PyTypeObject*) long_cls; ...@@ -21,7 +21,8 @@ PyAPI_DATA(PyTypeObject*) long_cls;
#define PyLong_Type (*long_cls) #define PyLong_Type (*long_cls)
// Pyston changes: these aren't direct macros any more [they potentially could be though] // Pyston changes: these aren't direct macros any more [they potentially could be though]
PyAPI_FUNC(bool) PyLong_Check(PyObject*) PYSTON_NOEXCEPT; PyAPI_FUNC(bool) _PyLong_Check(PyObject*) PYSTON_NOEXCEPT;
#define PyLong_Check(op) _PyLong_Check((PyObject*)(op))
#if 0 #if 0
#define PyLong_Check(op) \ #define PyLong_Check(op) \
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS) PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS)
......
...@@ -499,7 +499,8 @@ PyAPI_DATA(PyTypeObject*) type_cls; ...@@ -499,7 +499,8 @@ PyAPI_DATA(PyTypeObject*) type_cls;
//PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */ //PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */
// Pyston changes: these aren't direct macros any more [they potentially could be though] // Pyston changes: these aren't direct macros any more [they potentially could be though]
PyAPI_FUNC(bool) PyType_Check(PyObject*) PYSTON_NOEXCEPT; PyAPI_FUNC(bool) _PyType_Check(PyObject*) PYSTON_NOEXCEPT;
#define PyType_Check(op) _PyType_Check((PyObject*)(op))
#if 0 #if 0
#define PyType_Check(op) \ #define PyType_Check(op) \
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS) PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS)
......
...@@ -39,7 +39,8 @@ PyAPI_DATA(PyTypeObject*) ellipsis_cls; ...@@ -39,7 +39,8 @@ PyAPI_DATA(PyTypeObject*) ellipsis_cls;
// Pyston changes: these aren't direct macros any more [they potentially could be though] // Pyston changes: these aren't direct macros any more [they potentially could be though]
//#define PySlice_Check(op) (Py_TYPE(op) == &PySlice_Type) //#define PySlice_Check(op) (Py_TYPE(op) == &PySlice_Type)
PyAPI_FUNC(bool) PySlice_Check(PyObject*) PYSTON_NOEXCEPT; PyAPI_FUNC(bool) _PySlice_Check(PyObject*) PYSTON_NOEXCEPT;
#define PySlice_Check(op) _PySlice_Check((PyObject*)(op))
PyAPI_FUNC(PyObject *) PySlice_New(PyObject* start, PyObject* stop, PyAPI_FUNC(PyObject *) PySlice_New(PyObject* start, PyObject* stop,
PyObject* step) PYSTON_NOEXCEPT; PyObject* step) PYSTON_NOEXCEPT;
......
...@@ -42,7 +42,8 @@ PyAPI_DATA(PyTypeObject*) tuple_cls; ...@@ -42,7 +42,8 @@ PyAPI_DATA(PyTypeObject*) tuple_cls;
#define PyTuple_Type (*tuple_cls) #define PyTuple_Type (*tuple_cls)
// Pyston changes: these aren't direct macros any more [they potentially could be though] // Pyston changes: these aren't direct macros any more [they potentially could be though]
PyAPI_FUNC(bool) PyTuple_Check(PyObject*) PYSTON_NOEXCEPT; PyAPI_FUNC(bool) _PyTuple_Check(PyObject*) PYSTON_NOEXCEPT;
#define PyTuple_Check(op) _PyTuple_Check((PyObject*)(op))
#if 0 #if 0
#define PyTuple_Check(op) \ #define PyTuple_Check(op) \
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS) PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS)
......
...@@ -435,7 +435,8 @@ PyAPI_DATA(PyTypeObject*) unicode_cls; ...@@ -435,7 +435,8 @@ PyAPI_DATA(PyTypeObject*) unicode_cls;
//PyAPI_DATA(PyTypeObject) PyUnicode_Type; //PyAPI_DATA(PyTypeObject) PyUnicode_Type;
// Pyston changes: these aren't direct macros any more [they potentially could be though] // Pyston changes: these aren't direct macros any more [they potentially could be though]
PyAPI_FUNC(bool) PyUnicode_Check(PyObject*) PYSTON_NOEXCEPT; PyAPI_FUNC(bool) _PyUnicode_Check(PyObject*) PYSTON_NOEXCEPT;
#define PyUnicode_Check(op) _PyUnicode_Check((PyObject*)(op))
#if 0 #if 0
#define PyUnicode_Check(op) \ #define PyUnicode_Check(op) \
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS) PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
......
...@@ -34,12 +34,10 @@ namespace pyston { ...@@ -34,12 +34,10 @@ namespace pyston {
BoxedClass* method_cls; BoxedClass* method_cls;
#define MAKE_CHECK(NAME, cls_name) \ #define MAKE_CHECK(NAME, cls_name) \
extern "C" bool Py##NAME##_Check(PyObject* op) noexcept { return isSubclass(op->cls, cls_name); }
#define MAKE_CHECK2(NAME, cls_name) \
extern "C" bool _Py##NAME##_Check(PyObject* op) noexcept { return isSubclass(op->cls, cls_name); } extern "C" bool _Py##NAME##_Check(PyObject* op) noexcept { return isSubclass(op->cls, cls_name); }
MAKE_CHECK2(Int, int_cls) MAKE_CHECK(Int, int_cls)
MAKE_CHECK2(String, str_cls) MAKE_CHECK(String, str_cls)
MAKE_CHECK(Long, long_cls) MAKE_CHECK(Long, long_cls)
MAKE_CHECK(List, list_cls) MAKE_CHECK(List, list_cls)
MAKE_CHECK(Tuple, tuple_cls) MAKE_CHECK(Tuple, tuple_cls)
......
import os.path
import sys
import subprocess
PYSTON_DIR = os.path.join(os.path.dirname(__file__), '..')
STDMODULE_DIR = os.path.join(PYSTON_DIR, "from_cpython/Modules")
def find_module_source(module_name):
for pattern in ("%smodule.c", "%s.c"):
src = pattern % module_name
if os.path.exists(os.path.join(STDMODULE_DIR, src)):
return src
print "couldn't find", module_name
return None
def main():
already_supported = ('__builtin__', '_collections', '_functools', '_md5', '_random', '_sha', '_sha256', '_sha512', '_sre', '_struct', 'binascii', 'datetime', 'errno', 'fcntl', 'gc', 'itertools', 'math', 'operator', 'posix', 'pwd', 'resource', 'select', 'signal', 'sys', 'thread', 'time')
for module_name in sys.builtin_module_names:
if module_name.startswith("__"):
continue
if module_name in already_supported:
continue
src = find_module_source(module_name)
if not src:
continue
args = ["make", "EXTRA_STDMODULE_SRCS=%s" % src, "ERROR_LIMIT=0"]
print ' '.join(args), "> %s.log" % module_name
log_fn = "%s.log" % module_name
f = open(log_fn, 'w')
p = subprocess.Popen(args, cwd=PYSTON_DIR, stdout=f, stderr=subprocess.STDOUT)
code = p.wait()
f.close()
if code == 0:
print module_name, "worked!"
else:
print module_name, "didn't work",
s = open(log_fn).read()
if "undefined reference to" in s:
print "Compiled but didn't link, %d link errors" % (s.count('\n') - 3)
else:
print s.split('\n')[-3]
if __name__ == "__main__":
main()
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