Commit 08509b08 authored by Kevin Modzelewski's avatar Kevin Modzelewski

get enough dealloc/traverse/clear functions in to get it to try the GC

parent 05fcd11f
......@@ -71,13 +71,14 @@ void setupAST() {
// ::create takes care of registering the class as a GC root.
#define MAKE_CLS(name, base_cls) \
BoxedClass* name##_cls = BoxedClass::create(type_cls, base_cls, 0, 0, sizeof(BoxedAST), false, STRINGIFY(name)); \
BoxedClass* name##_cls \
= BoxedClass::create(type_cls, base_cls, 0, 0, sizeof(BoxedAST), false, STRINGIFY(name), NULL, NULL, false); \
ast_module->giveAttrBorrowed(STRINGIFY(name), name##_cls); \
type_to_cls[AST_TYPE::name] = name##_cls; \
name##_cls->giveAttr("__module__", boxString("_ast")); \
name##_cls->freeze()
AST_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedAST), false, "AST");
AST_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedAST), false, "AST", NULL, NULL, false);
// ::create takes care of registering the class as a GC root.
AST_cls->giveAttr("__module__", boxString("_ast"));
AST_cls->freeze();
......
......@@ -1208,6 +1208,13 @@ public:
BoxedEnumerate* self = static_cast<BoxedEnumerate*>(_self);
return boxBool(self->iterator != self->iterator_end);
}
static void dealloc(Box* b) noexcept {
Py_FatalError("unimplemented");
}
static int traverse(Box* self, visitproc visit, void *arg) noexcept {
Py_FatalError("unimplemented");
}
};
Box* globals() {
......@@ -1842,7 +1849,7 @@ void setupBuiltins() {
"Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is "
"the `nil' object; Ellipsis represents `...' in slices.");
ellipsis_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(Box), false, "ellipsis");
ellipsis_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(Box), false, "ellipsis", NULL, NULL, false);
ellipsis_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)ellipsisRepr, STR, 1)));
Ellipsis = new (ellipsis_cls) Box();
assert(Ellipsis->cls);
......@@ -1857,7 +1864,8 @@ void setupBuiltins() {
"print", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)print, NONE, 0, true, true), "print",
print_doc));
notimplemented_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(Box), false, "NotImplementedType");
notimplemented_cls
= BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(Box), false, "NotImplementedType", NULL, NULL, false);
notimplemented_cls->giveAttr("__repr__",
new BoxedFunction(FunctionMetadata::create((void*)notimplementedRepr, STR, 1)));
notimplemented_cls->freeze();
......@@ -1969,7 +1977,7 @@ void setupBuiltins() {
{ None, None, None, autoDecref(boxInt(-1)) }, NULL, import_doc));
enumerate_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedEnumerate),
false, "enumerate");
false, "enumerate", BoxedEnumerate::dealloc, NULL, true, BoxedEnumerate::traverse, NOCLEAR);
enumerate_cls->giveAttr(
"__new__", new BoxedFunction(FunctionMetadata::create((void*)BoxedEnumerate::new_, UNKNOWN, 3, false, false),
{ autoDecref(boxInt(0)) }));
......
......@@ -180,6 +180,10 @@ public:
}
Py_RETURN_TRUE;
}
static void dealloc(Box* b) noexcept {
Py_FatalError("unimplemented");
}
};
......@@ -223,7 +227,8 @@ void setupThread() {
thread_module->giveAttr("_count", new BoxedBuiltinFunctionOrMethod(
FunctionMetadata::create((void*)threadCount, BOXED_INT, 0), "_count"));
thread_lock_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedThreadLock), false, "lock");
thread_lock_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedThreadLock), false, "lock",
BoxedThreadLock::dealloc, NULL, false);
thread_lock_cls->tp_dealloc = BoxedThreadLock::threadLockDestructor;
thread_lock_cls->has_safe_tp_dealloc = true;
thread_lock_cls->instances_are_nonzero = true;
......@@ -245,7 +250,7 @@ void setupThread() {
thread_lock_cls->freeze();
ThreadError = BoxedClass::create(type_cls, Exception, Exception->attrs_offset, Exception->tp_weaklistoffset,
Exception->tp_basicsize, false, "error");
Exception->tp_basicsize, false, "error", NULL, NULL, false);
ThreadError->giveAttr("__module__", boxString("thread"));
ThreadError->freeze();
......
......@@ -1641,10 +1641,14 @@ extern "C" int PyMethod_ClearFreeList(void) noexcept {
}
void setupClassobj() {
classobj_cls = BoxedClass::create(type_cls, object_cls, offsetof(BoxedClassobj, attrs),
offsetof(BoxedClassobj, weakreflist), sizeof(BoxedClassobj), false, "classobj");
instance_cls = BoxedClass::create(type_cls, object_cls, offsetof(BoxedInstance, attrs),
offsetof(BoxedInstance, weakreflist), sizeof(BoxedInstance), false, "instance");
classobj_cls
= BoxedClass::create(type_cls, object_cls, offsetof(BoxedClassobj, attrs), offsetof(BoxedClassobj, weakreflist),
sizeof(BoxedClassobj), false, "classobj", (destructor)BoxedClassobj::dealloc, NULL, true,
(traverseproc)BoxedClassobj::traverse, (inquiry)BoxedClassobj::clear);
instance_cls
= BoxedClass::create(type_cls, object_cls, offsetof(BoxedInstance, attrs), offsetof(BoxedInstance, weakreflist),
sizeof(BoxedInstance), false, "instance", (destructor)BoxedInstance::dealloc, NULL, true,
(traverseproc)BoxedInstance::traverse, (inquiry)BoxedInstance::clear);
classobj_cls->giveAttr("__new__",
new BoxedFunction(FunctionMetadata::create((void*)classobjNew, UNKNOWN, 4, false, false)));
......
......@@ -49,6 +49,16 @@ public:
Box** weakreflist;
BoxedClassobj(BoxedString* name, BoxedTuple* bases) : bases(bases), name(name) {}
static void dealloc(Box* b) noexcept {
Py_FatalError("unimplemented");
}
static int traverse(Box* self, visitproc visit, void *arg) noexcept {
Py_FatalError("unimplemented");
}
static int clear(Box* self) noexcept {
Py_FatalError("unimplemented");
}
};
class BoxedInstance : public Box {
......@@ -62,6 +72,16 @@ public:
BoxedInstance(BoxedClassobj* inst_cls) : inst_cls(inst_cls) {}
DEFAULT_CLASS(instance_cls);
static void dealloc(Box* b) noexcept {
Py_FatalError("unimplemented");
}
static int traverse(Box* self, visitproc visit, void *arg) noexcept {
Py_FatalError("unimplemented");
}
static int clear(Box* self) noexcept {
Py_FatalError("unimplemented");
}
};
Box* instance_getattro(Box* cls, Box* attr) noexcept;
......
......@@ -111,7 +111,7 @@ extern "C" int PyCode_GetArgCount(PyCodeObject* op) noexcept {
}
void setupCode() {
code_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedCode), false, "code");
code_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedCode), false, "code", NULL, NULL, false);
code_cls->giveAttrBorrowed("__new__", None); // Hacky way of preventing users from instantiating this
......
......@@ -812,15 +812,19 @@ void setupDict() {
static PySequenceMethods dict_as_sequence;
dict_cls->tp_as_sequence = &dict_as_sequence;
dict_iterator_cls = BoxedClass::create(type_cls, object_cls, 0, 0,
sizeof(BoxedDictIterator), false, "dictionary-itemiterator");
dict_keys_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedDictView),
false, "dict_keys");
dict_values_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedDictView),
false, "dict_values");
dict_items_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedDictView),
false, "dict_items");
dict_iterator_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedDictIterator), false,
"dictionary-itemiterator", (destructor)BoxedDictIterator::dealloc, NULL,
true, (traverseproc)BoxedDictIterator::traverse, NOCLEAR);
dict_keys_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedDictView), false, "dict_keys",
(destructor)BoxedDictView::dealloc, NULL, true,
(traverseproc)BoxedDictView::traverse, NOCLEAR);
dict_values_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedDictView), false, "dict_values",
(destructor)BoxedDictView::dealloc, NULL, true,
(traverseproc)BoxedDictView::traverse, NOCLEAR);
dict_items_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedDictView), false, "dict_items",
(destructor)BoxedDictView::dealloc, NULL, true,
(traverseproc)BoxedDictView::traverse, NOCLEAR);
dict_iterator_cls->instances_are_nonzero = dict_keys_cls->instances_are_nonzero
= dict_values_cls->instances_are_nonzero = dict_items_cls->instances_are_nonzero = true;
......
......@@ -37,6 +37,17 @@ public:
BoxedDictIterator(BoxedDict* d, IteratorType type);
DEFAULT_CLASS(dict_iterator_cls);
static void dealloc(BoxedDictIterator* o) noexcept {
PyObject_GC_UnTrack(o);
Py_DECREF(o->d);
o->cls->tp_free(o);
}
static int traverse(BoxedDictIterator* self, visitproc visit, void *arg) noexcept {
Py_VISIT(self->d);
return 0;
}
};
Box* dictGetitem(BoxedDict* self, Box* k);
......@@ -55,6 +66,17 @@ class BoxedDictView : public Box {
public:
BoxedDict* d;
BoxedDictView(BoxedDict* d);
static void dealloc(BoxedDictIterator* o) noexcept {
PyObject_GC_UnTrack(o);
Py_DECREF(o->d);
o->cls->tp_free(o);
}
static int traverse(BoxedDictIterator* self, visitproc visit, void *arg) noexcept {
Py_VISIT(self->d);
return 0;
}
};
Box* dictViewKeysIter(Box* self);
......
......@@ -130,6 +130,16 @@ public:
return fi->frame_obj;
}
static void dealloc(Box* b) noexcept {
Py_FatalError("unimplemented");
}
static int traverse(Box* self, visitproc visit, void *arg) noexcept {
Py_FatalError("unimplemented");
}
static int clear(Box* self) noexcept {
Py_FatalError("unimplemented");
}
};
Box* getFrame(int depth) {
......@@ -141,8 +151,9 @@ Box* getFrame(int depth) {
}
void setupFrame() {
frame_cls
= BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedFrame), false, "frame");
frame_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedFrame), false, "frame",
(destructor)BoxedFrame::dealloc, NULL, true, (traverseproc)BoxedFrame::traverse,
(inquiry)BoxedFrame::clear);
frame_cls->tp_dealloc = BoxedFrame::simpleDestructor;
frame_cls->has_safe_tp_dealloc = true;
......
......@@ -423,12 +423,6 @@ Box* generatorName(Box* _self, void* context) {
return self->function->md->source->getName();
}
void generatorDestructor(Box* b) {
assert(isSubclass(b->cls, generator_cls));
BoxedGenerator* self = static_cast<BoxedGenerator*>(b);
freeGeneratorStack(self);
}
extern "C" int PyGen_NeedsFinalizing(PyGenObject* gen) noexcept {
Py_FatalError("unimplemented");
#if 0
......@@ -450,11 +444,21 @@ extern "C" int PyGen_NeedsFinalizing(PyGenObject* gen) noexcept {
#endif
}
static void generator_dealloc(BoxedGenerator* self) noexcept {
assert(isSubclass(self->cls, generator_cls));
freeGeneratorStack(self);
Py_FatalError("unimplemented");
}
static int generator_traverse(BoxedGenerator* self, visitproc visit, void *arg) noexcept {
Py_FatalError("unimplemented");
}
void setupGenerator() {
generator_cls
= BoxedClass::create(type_cls, object_cls, 0, offsetof(BoxedGenerator, weakreflist),
sizeof(BoxedGenerator), false, "generator");
generator_cls->tp_dealloc = generatorDestructor;
generator_cls = BoxedClass::create(type_cls, object_cls, 0, offsetof(BoxedGenerator, weakreflist),
sizeof(BoxedGenerator), false, "generator", (destructor)generator_dealloc, NULL,
true, (traverseproc)generator_traverse, NOCLEAR);
generator_cls->has_safe_tp_dealloc = true;
generator_cls->giveAttr(
"__iter__", new BoxedFunction(FunctionMetadata::create((void*)generatorIter, typeFromClass(generator_cls), 1)));
......
......@@ -933,7 +933,7 @@ void setupImport() {
imp_module->giveAttr("C_BUILTIN", boxInt(SearchResult::C_BUILTIN));
imp_module->giveAttr("PY_FROZEN", boxInt(SearchResult::PY_FROZEN));
null_importer_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(Box), false, "NullImporter");
null_importer_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(Box), false, "NullImporter", NULL, NULL, false);
null_importer_cls->giveAttr(
"__init__",
new BoxedFunction(FunctionMetadata::create((void*)nullImporterInit, NONE, 2, false, false), { None }));
......
......@@ -130,6 +130,13 @@ public:
static Box* xrangeIteratorNext(Box* s) __attribute__((visibility("default"))) {
return boxInt(xrangeIteratorNextUnboxed(s));
}
static void dealloc(Box* b) noexcept {
Py_FatalError("unimplemented");
}
static int traverse(Box* self, visitproc visit, void *arg) noexcept {
Py_FatalError("unimplemented");
}
};
Box* xrange(Box* cls, Box* start, Box* stop, Box** args) {
......@@ -236,9 +243,10 @@ Box* xrangeReduce(Box* self) {
}
void setupXrange() {
xrange_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedXrange), false, "xrange");
xrange_iterator_cls = BoxedClass::create(type_cls, object_cls, 0, 0,
sizeof(BoxedXrangeIterator), false, "rangeiterator");
xrange_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedXrange), false, "xrange", NULL, NULL, false);
xrange_iterator_cls
= BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedXrangeIterator), false, "rangeiterator",
BoxedXrangeIterator::dealloc, NULL, true, BoxedXrangeIterator::traverse, NOCLEAR);
static PySequenceMethods xrange_as_sequence;
xrange_cls->tp_as_sequence = &xrange_as_sequence;
......
......@@ -189,7 +189,9 @@ bool calliter_hasnext(Box* b) {
void setupIter() {
seqiter_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedSeqIter), false, "iterator");
seqiter_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedSeqIter), false, "iterator",
(destructor)BoxedSeqIter::dealloc, NULL, true,
(traverseproc)BoxedSeqIter::traverse, NOCLEAR);
seqiter_cls->giveAttr("next", new BoxedFunction(FunctionMetadata::create((void*)seqiterNext, UNKNOWN, 1)));
seqiter_cls->giveAttr("__hasnext__",
......@@ -201,8 +203,9 @@ void setupIter() {
seqiter_cls->tp_iter = PyObject_SelfIter;
seqiter_cls->tp_iternext = seqiter_next;
seqreviter_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedSeqIter),
false, "reversed");
seqreviter_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedSeqIter), false, "reversed",
(destructor)BoxedSeqIter::dealloc, NULL, true,
(traverseproc)BoxedSeqIter::traverse, NOCLEAR);
seqreviter_cls->giveAttr("next", new BoxedFunction(FunctionMetadata::create((void*)seqiterNext, UNKNOWN, 1)));
seqreviter_cls->giveAttr("__hasnext__",
......@@ -213,8 +216,9 @@ void setupIter() {
seqreviter_cls->tp_iter = PyObject_SelfIter;
seqreviter_cls->tp_iternext = seqiter_next;
iterwrapper_cls = BoxedClass::create(type_cls, object_cls, 0, 0,
sizeof(BoxedIterWrapper), false, "iterwrapper");
iterwrapper_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedIterWrapper), false, "iterwrapper",
(destructor)BoxedIterWrapper::dealloc, NULL, true,
(traverseproc)BoxedIterWrapper::traverse, NOCLEAR);
iterwrapper_cls->giveAttr("next", new BoxedFunction(FunctionMetadata::create((void*)iterwrapperNext, UNKNOWN, 1)));
iterwrapper_cls->giveAttr("__hasnext__",
......
......@@ -36,6 +36,19 @@ public:
BoxedSeqIter(Box* b, int64_t start) : b(b), idx(start), next(NULL) {}
DEFAULT_CLASS(seqiter_cls);
static void dealloc(BoxedSeqIter* o) noexcept {
PyObject_GC_UnTrack(o);
Py_DECREF(o->b);
Py_XDECREF(o->next);
o->cls->tp_free(o);
}
static int traverse(BoxedSeqIter* self, visitproc visit, void *arg) noexcept {
Py_VISIT(self->b);
Py_VISIT(self->next);
return 0;
}
};
extern BoxedClass* iterwrapper_cls;
......@@ -49,6 +62,19 @@ public:
BoxedIterWrapper(Box* iter) : iter(iter), next(NULL) {}
DEFAULT_CLASS(iterwrapper_cls);
static void dealloc(BoxedIterWrapper* o) noexcept {
PyObject_GC_UnTrack(o);
Py_DECREF(o->iter);
Py_XDECREF(o->next);
o->cls->tp_free(o);
}
static int traverse(BoxedIterWrapper* self, visitproc visit, void *arg) noexcept {
Py_VISIT(self->iter);
Py_VISIT(self->next);
return 0;
}
};
bool calliter_hasnext(Box* b);
......
......@@ -1321,10 +1321,12 @@ void setupList() {
static PyMappingMethods list_as_mapping;
list_cls->tp_as_mapping = &list_as_mapping;
list_iterator_cls = BoxedClass::create(type_cls, object_cls, 0, 0,
sizeof(BoxedListIterator), false, "listiterator");
list_reverse_iterator_cls = BoxedClass::create(type_cls, object_cls, 0, 0,
sizeof(BoxedListIterator), false, "listreverseiterator");
list_iterator_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedListIterator), false, "listiterator",
(destructor)BoxedListIterator::dealloc, NULL, true,
(traverseproc)BoxedListIterator::traverse, NOCLEAR);
list_reverse_iterator_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedListIterator), false,
"listreverseiterator", (destructor)BoxedListIterator::dealloc, NULL,
true, (traverseproc)BoxedListIterator::traverse, NOCLEAR);
list_iterator_cls->instances_are_nonzero = list_reverse_iterator_cls->instances_are_nonzero = true;
list_cls->giveAttr("__len__", new BoxedFunction(FunctionMetadata::create((void*)listLen, BOXED_INT, 1)));
......
......@@ -29,6 +29,17 @@ public:
BoxedListIterator(BoxedList* l, int start);
DEFAULT_CLASS(list_iterator_cls);
static void dealloc(BoxedListIterator* o) noexcept {
PyObject_GC_UnTrack(o);
Py_DECREF(o->l);
o->cls->tp_free(o);
}
static int traverse(BoxedListIterator* self, visitproc visit, void *arg) noexcept {
Py_VISIT(self->l);
return 0;
}
};
Box* listIter(Box* self) noexcept;
......
......@@ -414,10 +414,12 @@ BoxedClass::BoxedClass(BoxedClass* base, int attrs_offset, int weaklist_offset,
bool ok_noclear = (clear == NOCLEAR);
if (ok_noclear)
clear = NULL;
if (is_gc) {
ASSERT(traverse, "%s", name);
ASSERT(dealloc, "%s", name);
}
if (clear)
assert(traverse);
if (traverse)
assert(dealloc);
if (dealloc)
assert(traverse || !is_gc);
ASSERT(((bool)traverse == (bool)clear) || ok_noclear, "%s", name);
classes.push_back(this);
......
......@@ -43,6 +43,17 @@ public:
++it;
return rtn;
}
static void dealloc(BoxedSetIterator* o) noexcept {
PyObject_GC_UnTrack(o);
Py_DECREF(o->s);
o->cls->tp_free(o);
}
static int traverse(BoxedSetIterator* self, visitproc visit, void *arg) noexcept {
Py_VISIT(self->s);
return 0;
}
};
Box* setiteratorHasnext(BoxedSetIterator* self) {
......@@ -804,6 +815,7 @@ using namespace pyston::set;
void BoxedSet::dealloc(Box* _o) noexcept {
BoxedSet* o = (BoxedSet*)_o;
PyObject_GC_UnTrack(o);
for (auto p : o->s) {
Py_DECREF(p.value);
}
......@@ -852,8 +864,9 @@ void setupSet() {
set_cls->tp_dealloc = frozenset_cls->tp_dealloc = BoxedSet::dealloc;
set_cls->has_safe_tp_dealloc = frozenset_cls->has_safe_tp_dealloc = true;
set_iterator_cls = BoxedClass::create(type_cls, object_cls, 0, 0,
sizeof(BoxedSetIterator), false, "setiterator");
set_iterator_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedSetIterator), false, "setiterator",
(destructor)BoxedSetIterator::dealloc, NULL, true,
(traverseproc)BoxedSetIterator::traverse, NOCLEAR);
set_iterator_cls->giveAttr("__iter__", new BoxedFunction(FunctionMetadata::create(
(void*)setiteratorIter, typeFromClass(set_iterator_cls), 1)));
set_iterator_cls->giveAttr("__hasnext__",
......
......@@ -2405,6 +2405,17 @@ public:
++self->it;
return characters[c & UCHAR_MAX];
}
static void dealloc(BoxedStringIterator* o) noexcept {
PyObject_GC_UnTrack(o);
Py_DECREF(o->s);
o->cls->tp_free(o);
}
static int traverse(BoxedStringIterator* self, visitproc visit, void *arg) noexcept {
Py_VISIT(self->s);
return 0;
}
};
Box* strIter(BoxedString* self) noexcept {
......@@ -2801,8 +2812,9 @@ void setupStr() {
str_cls->tp_flags |= Py_TPFLAGS_HAVE_NEWBUFFER;
str_iterator_cls = BoxedClass::create(type_cls, object_cls, 0, 0,
sizeof(BoxedStringIterator), false, "striterator");
str_iterator_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedStringIterator), false, "striterator",
(destructor)BoxedStringIterator::dealloc, NULL, true,
(traverseproc)BoxedStringIterator::traverse, NOCLEAR);
str_iterator_cls->giveAttr(
"__hasnext__", new BoxedFunction(FunctionMetadata::create((void*)BoxedStringIterator::hasnext, BOXED_BOOL, 1)));
str_iterator_cls->giveAttr(
......
......@@ -35,6 +35,13 @@ public:
BoxedSuper(BoxedClass* type, Box* obj, BoxedClass* obj_type) : type(type), obj(obj), obj_type(obj_type) {}
DEFAULT_CLASS(super_cls);
static void dealloc(Box* b) noexcept {
Py_FatalError("unimplemented");
}
static int traverse(Box* self, visitproc visit, void *arg) noexcept {
Py_FatalError("unimplemented");
}
};
static const char* class_str = "__class__";
......@@ -185,7 +192,8 @@ Box* superInit(Box* _self, Box* _type, Box* obj) {
void setupSuper() {
super_cls
= BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedSuper), false, "super");
= BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedSuper), false, "super",
(destructor)BoxedSuper::dealloc, NULL, true, (traverseproc)BoxedSuper::traverse, NOCLEAR);
// super_cls->giveAttr("__getattribute__", new BoxedFunction(FunctionMetadata::create((void*)superGetattribute,
// UNKNOWN, 2)));
......
......@@ -105,8 +105,9 @@ void BoxedTraceback::here(LineInfo lineInfo, Box** tb) {
}
void setupTraceback() {
traceback_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedTraceback),
false, "traceback");
traceback_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedTraceback), false, "traceback",
(destructor)BoxedTraceback::dealloc, NULL, true,
(traverseproc)BoxedTraceback::traverse, (inquiry)BoxedTraceback::clear);
traceback_cls->giveAttr("getLines",
new BoxedFunction(FunctionMetadata::create((void*)BoxedTraceback::getLines, UNKNOWN, 1)));
......
......@@ -41,6 +41,16 @@ public:
// somewhat equivalent to PyTraceBack_Here
static void here(LineInfo lineInfo, Box** tb);
static void dealloc(Box* b) noexcept {
Py_FatalError("unimplemented");
}
static int traverse(Box* self, visitproc visit, void *arg) noexcept {
Py_FatalError("unimplemented");
}
static int clear(Box* self) noexcept {
Py_FatalError("unimplemented");
}
};
void printTraceback(Box* b);
......
......@@ -675,8 +675,9 @@ void setupTuple() {
static PyMappingMethods tuple_as_mapping;
tuple_cls->tp_as_mapping = &tuple_as_mapping;
tuple_iterator_cls = BoxedClass::create(type_cls, object_cls, 0, 0,
sizeof(BoxedTupleIterator), false, "tuple");
tuple_iterator_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedTupleIterator), false,
"tupleiterator", (destructor)BoxedTupleIterator::dealloc, NULL, true,
(traverseproc)BoxedTupleIterator::traverse, NOCLEAR);
tuple_cls->giveAttr("__new__",
new BoxedFunction(FunctionMetadata::create((void*)tupleNew, UNKNOWN, 1, true, true)));
......
......@@ -28,6 +28,17 @@ public:
BoxedTupleIterator(BoxedTuple* t);
DEFAULT_CLASS(tuple_iterator_cls);
static void dealloc(BoxedTupleIterator* o) noexcept {
PyObject_GC_UnTrack(o);
Py_DECREF(o->t);
o->cls->tp_free(o);
}
static int traverse(BoxedTupleIterator* self, visitproc visit, void *arg) noexcept {
Py_VISIT(self->t);
return 0;
}
};
Box* tupleIter(Box* self) noexcept;
......
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