diff --git a/from_cpython/Include/object.h b/from_cpython/Include/object.h index 6e0c5c6b2fc4f3d5e142ab6daa9fc92c2501be31..3654595eed795fbb96be41e863a4b726ff6b3dee 100644 --- a/from_cpython/Include/object.h +++ b/from_cpython/Include/object.h @@ -26,7 +26,6 @@ An object has a 'reference count' that is increased or decreased when a pointer to the object is copied or deleted; when the reference count reaches zero there are no references to the object left and it can be removed from the heap. -[not true in Pyston] An object has a 'type' that determines what it represents and what kind of data it contains. An object's type is fixed when it is created. @@ -43,7 +42,6 @@ after allocation. (These restrictions are made so a reference to an object can be simply a pointer -- moving an object would require updating all the pointers, and changing an object's size would require moving it if there was another object right next to it.) -[This may not always be true in Pyston] Objects are always accessed through pointers of the type 'PyObject *'. The type 'PyObject' is a structure that only contains the reference count diff --git a/from_cpython/Include/objimpl.h b/from_cpython/Include/objimpl.h index 0bc4e6351f28479f72ff4af580d2b387bbdb7e6a..efa2595f8161de06f298029ebc0465f0829e03b2 100644 --- a/from_cpython/Include/objimpl.h +++ b/from_cpython/Include/objimpl.h @@ -160,17 +160,12 @@ PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t) PYSTON_NO #define PyObject_NewVar(type, typeobj, n) \ ( (type *) _PyObject_NewVar((typeobj), (n)) ) -// Pyston change: these are function calls now -#if 0 /* 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), (op) ) + ( Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op) ) #define PyObject_INIT_VAR(op, typeobj, size) \ ( Py_SIZE(op) = (size), PyObject_INIT((op), (typeobj)) ) -#endif -#define PyObject_INIT(op, typeobj) PyObject_Init((PyObject*)(op), (PyTypeObject*)(typeobj)) -#define PyObject_INIT_VAR(op, typeobj, size) PyObject_InitVar((PyVarObject*)(op), (PyTypeObject*)(typeobj), size) #define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize ) diff --git a/src/runtime/objmodel.cpp b/src/runtime/objmodel.cpp index 858e611d54e11f581945185c7a14665e2957fe54..9882d285caf7663022a99bbc3635b6f7af99c432 100644 --- a/src/runtime/objmodel.cpp +++ b/src/runtime/objmodel.cpp @@ -438,7 +438,7 @@ BoxedClass::BoxedClass(BoxedClass* base, int attrs_offset, int weaklist_offset, assert(tp_base->tp_alloc); tp_alloc = tp_base->tp_alloc; } else { - assert(object_cls == NULL); + assert(this == object_cls); tp_alloc = PystonType_GenericAlloc; } @@ -468,7 +468,7 @@ BoxedClass::BoxedClass(BoxedClass* base, int attrs_offset, int weaklist_offset, tp_free = default_free; if (!base) { - assert(object_cls == nullptr); + assert(this == object_cls); // we're constructing 'object' // Will have to add __base__ = None later } else { diff --git a/src/runtime/types.cpp b/src/runtime/types.cpp index 67a7484c7c759b48962a18924767cdf18b0700e2..3ada8a42952b94a860fc015c221b499b09de33ef 100644 --- a/src/runtime/types.cpp +++ b/src/runtime/types.cpp @@ -3480,11 +3480,15 @@ void setupRuntime() { // We have to do a little dance to get object_cls and type_cls set up, since the normal // object-creation routines look at the class to see the allocation size. - void* mem = PyObject_MALLOC(sizeof(BoxedClass)); - object_cls = ::new (mem) BoxedClass(NULL, 0, 0, sizeof(Box), false, "object"); - mem = PyObject_MALLOC(sizeof(BoxedClass)); - type_cls = ::new (mem) BoxedClass(object_cls, offsetof(BoxedClass, attrs), + object_cls = static_cast<BoxedClass*>(PyObject_MALLOC(sizeof(BoxedClass))); + PyObject_INIT(object_cls, NULL); + ::new (object_cls) BoxedClass(NULL, 0, 0, sizeof(Box), false, "object"); + + type_cls = static_cast<BoxedClass*>(PyObject_MALLOC(sizeof(BoxedClass))); + PyObject_INIT(type_cls, type_cls); + ::new (type_cls) BoxedClass(object_cls, offsetof(BoxedClass, attrs), offsetof(BoxedClass, tp_weaklist), sizeof(BoxedHeapClass), false, "type"); + type_cls->has_safe_tp_dealloc = false; type_cls->tp_flags |= Py_TPFLAGS_TYPE_SUBCLASS; type_cls->tp_itemsize = sizeof(BoxedHeapClass::SlotOffset);