Commit 71b2fa6b authored by Kevin Modzelewski's avatar Kevin Modzelewski

coming along

parent da6f4229
......@@ -647,6 +647,9 @@ public:
this->setattr(attr, val, NULL);
}
// for debugging mostly:
void clearAttrs();
// getattr() does the equivalent of PyDict_GetItem(obj->dict, attr): it looks up the attribute's value on the
// object's attribute storage. it doesn't look at other objects or do any descriptor logic.
template <Rewritable rewritable = REWRITABLE>
......
......@@ -395,11 +395,21 @@ extern "C" void PyString_InternInPlace(PyObject** p) noexcept {
num_interned_strings.log();
entry = (BoxedString*)PyGC_AddRoot(s);
Py_INCREF(s);
// CPython returns mortal but in our current implementation they are inmortal
s->interned_state = SSTATE_INTERNED_IMMORTAL;
}
}
extern "C" void _Py_ReleaseInternedStrings() noexcept {
//printf("%ld interned strings\n", interned_strings.size());
for (const auto& p : interned_strings) {
Py_DECREF(p.second);
}
interned_strings.clear();
}
extern "C" int _PyString_CheckInterned(PyObject* p) noexcept {
RELEASE_ASSERT(PyString_Check(p), "");
BoxedString* s = (BoxedString*)p;
......
......@@ -3609,6 +3609,39 @@ static Box* getsetDelete(Box* self, Box* obj) {
}
}
void Box::clearAttrs() {
if (cls->instancesHaveHCAttrs()) {
HCAttrs* attrs = getHCAttrsPtr();
HiddenClass* hcls = attrs->hcls;
if (unlikely(hcls->type == HiddenClass::DICT_BACKED)) {
Box* d = attrs->attr_list->attrs[0];
PyDict_Clear(d);
return;
}
assert(hcls->type == HiddenClass::NORMAL || hcls->type == HiddenClass::SINGLETON);
for (int i = 0; i < hcls->attributeArraySize(); i++) {
Py_DECREF(attrs->attr_list->attrs[i]);
}
new ((void*)attrs) HCAttrs(root_hcls);
return;
}
if (cls->instancesHaveDictAttrs()) {
BoxedDict* d = getDict();
PyDict_Clear(d);
return;
}
}
#ifndef Py_REF_DEBUG
#define PRINT_TOTAL_REFS()
#else /* Py_REF_DEBUG */
#define PRINT_TOTAL_REFS() fprintf(stderr, "[%" PY_FORMAT_SIZE_T "d refs]\n", _Py_GetRefTotal())
#endif
bool TRACK_ALLOCATIONS = false;
void setupRuntime() {
......@@ -3666,6 +3699,18 @@ void setupRuntime() {
none_cls->giveAttr("__base__", object_cls);
object_cls->giveAttr("__base__", None);
auto classes = {type_cls, object_cls, none_cls, str_cls, basestring_cls};
_Py_ReleaseInternedStrings();
for (auto b : classes)
b->clearAttrs();
for (auto b : {None})
Py_DECREF(b);
for (auto b : classes)
Py_DECREF(b);
// XXX
PRINT_TOTAL_REFS();
exit(0);
// Not sure why CPython defines sizeof(PyTupleObject) to include one element,
// but we copy that, which means we have to subtract that extra pointer to get the tp_basicsize:
......@@ -4188,12 +4233,6 @@ static void call_sys_exitfunc(void) {
PyErr_Clear();
}
#ifndef Py_REF_DEBUG
#define PRINT_TOTAL_REFS()
#else /* Py_REF_DEBUG */
#define PRINT_TOTAL_REFS() fprintf(stderr, "[%" PY_FORMAT_SIZE_T "d refs]\n", _Py_GetRefTotal())
#endif
extern "C" void Py_Finalize() noexcept {
// In the future this will have to wait for non-daemon
// threads to finish
......
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