Commit 88868143 authored by Kevin Modzelewski's avatar Kevin Modzelewski

This is kinda working

parent 8ebaa1ea
...@@ -26,7 +26,6 @@ An object has a 'reference count' that is increased or decreased when a ...@@ -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 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 reaches zero there are no references to the object left and it can be
removed from the heap. removed from the heap.
[not true in Pyston]
An object has a 'type' that determines what it represents and what kind 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. 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 ...@@ -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 object can be simply a pointer -- moving an object would require
updating all the pointers, and changing an object's size 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.) 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 *'. Objects are always accessed through pointers of the type 'PyObject *'.
The type 'PyObject' is a structure that only contains the reference count The type 'PyObject' is a structure that only contains the reference count
......
...@@ -160,17 +160,12 @@ PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t) PYSTON_NO ...@@ -160,17 +160,12 @@ PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t) PYSTON_NO
#define PyObject_NewVar(type, typeobj, n) \ #define PyObject_NewVar(type, typeobj, n) \
( (type *) _PyObject_NewVar((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. /* Macros trading binary compatibility for speed. See also pymem.h.
Note that these macros expect non-NULL object pointers.*/ Note that these macros expect non-NULL object pointers.*/
#define PyObject_INIT(op, typeobj) \ #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) \ #define PyObject_INIT_VAR(op, typeobj, size) \
( Py_SIZE(op) = (size), PyObject_INIT((op), (typeobj)) ) ( 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 ) #define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize )
......
...@@ -438,7 +438,7 @@ BoxedClass::BoxedClass(BoxedClass* base, int attrs_offset, int weaklist_offset, ...@@ -438,7 +438,7 @@ BoxedClass::BoxedClass(BoxedClass* base, int attrs_offset, int weaklist_offset,
assert(tp_base->tp_alloc); assert(tp_base->tp_alloc);
tp_alloc = tp_base->tp_alloc; tp_alloc = tp_base->tp_alloc;
} else { } else {
assert(object_cls == NULL); assert(this == object_cls);
tp_alloc = PystonType_GenericAlloc; tp_alloc = PystonType_GenericAlloc;
} }
...@@ -468,7 +468,7 @@ BoxedClass::BoxedClass(BoxedClass* base, int attrs_offset, int weaklist_offset, ...@@ -468,7 +468,7 @@ BoxedClass::BoxedClass(BoxedClass* base, int attrs_offset, int weaklist_offset,
tp_free = default_free; tp_free = default_free;
if (!base) { if (!base) {
assert(object_cls == nullptr); assert(this == object_cls);
// we're constructing 'object' // we're constructing 'object'
// Will have to add __base__ = None later // Will have to add __base__ = None later
} else { } else {
......
...@@ -3480,11 +3480,15 @@ void setupRuntime() { ...@@ -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 // 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. // object-creation routines look at the class to see the allocation size.
void* mem = PyObject_MALLOC(sizeof(BoxedClass)); object_cls = static_cast<BoxedClass*>(PyObject_MALLOC(sizeof(BoxedClass)));
object_cls = ::new (mem) BoxedClass(NULL, 0, 0, sizeof(Box), false, "object"); PyObject_INIT(object_cls, NULL);
mem = PyObject_MALLOC(sizeof(BoxedClass)); ::new (object_cls) BoxedClass(NULL, 0, 0, sizeof(Box), false, "object");
type_cls = ::new (mem) BoxedClass(object_cls, offsetof(BoxedClass, attrs),
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"); offsetof(BoxedClass, tp_weaklist), sizeof(BoxedHeapClass), false, "type");
type_cls->has_safe_tp_dealloc = false; type_cls->has_safe_tp_dealloc = false;
type_cls->tp_flags |= Py_TPFLAGS_TYPE_SUBCLASS; type_cls->tp_flags |= Py_TPFLAGS_TYPE_SUBCLASS;
type_cls->tp_itemsize = sizeof(BoxedHeapClass::SlotOffset); type_cls->tp_itemsize = sizeof(BoxedHeapClass::SlotOffset);
......
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