Commit 3a2c0407 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Hmm

parent fabde965
...@@ -123,6 +123,11 @@ PyAPI_FUNC(int) PyObject_DelHcAttrString(PyObject*, const char*) PYSTON_NOEXCEPT ...@@ -123,6 +123,11 @@ PyAPI_FUNC(int) PyObject_DelHcAttrString(PyObject*, const char*) PYSTON_NOEXCEPT
// Workaround: call this instead of setting tp_dict. // Workaround: call this instead of setting tp_dict.
PyAPI_FUNC(void) PyType_SetDict(PyTypeObject*, PyObject*) PYSTON_NOEXCEPT; PyAPI_FUNC(void) PyType_SetDict(PyTypeObject*, PyObject*) PYSTON_NOEXCEPT;
// Pyston addition: register an object as a "static constant". Current purpose is that this will
// get decref'd when the interpreter shuts down.
// PyType_Ready calls this automatically.
PyAPI_FUNC(void) PyGC_RegisterStaticConstant(PyObject*) PYSTON_NOEXCEPT;
#include "codecs.h" #include "codecs.h"
#include "pyerrors.h" #include "pyerrors.h"
......
...@@ -945,6 +945,7 @@ initthread(void) ...@@ -945,6 +945,7 @@ initthread(void)
str_dict = PyString_InternFromString("__dict__"); str_dict = PyString_InternFromString("__dict__");
if (str_dict == NULL) if (str_dict == NULL)
return; return;
PyGC_RegisterStaticConstant(str_dict);
/* Initialize the C thread library */ /* Initialize the C thread library */
//PyThread_init_thread(); // pyston change //PyThread_init_thread(); // pyston change
......
...@@ -206,7 +206,7 @@ void setupThread() { ...@@ -206,7 +206,7 @@ void setupThread() {
initthread(); initthread();
RELEASE_ASSERT(!PyErr_Occurred(), ""); RELEASE_ASSERT(!PyErr_Occurred(), "");
Box* thread_module = getSysModulesDict()->getOrNull(boxString("thread")); Box* thread_module = getSysModulesDict()->getOrNull(autoDecref(boxString("thread")));
assert(thread_module); assert(thread_module);
thread_module->giveAttr( thread_module->giveAttr(
...@@ -231,17 +231,17 @@ void setupThread() { ...@@ -231,17 +231,17 @@ void setupThread() {
thread_lock_cls->giveAttr("__module__", boxString("thread")); thread_lock_cls->giveAttr("__module__", boxString("thread"));
thread_lock_cls->giveAttr("acquire", new BoxedFunction(FunctionMetadata::create((void*)BoxedThreadLock::acquire, thread_lock_cls->giveAttr("acquire", new BoxedFunction(FunctionMetadata::create((void*)BoxedThreadLock::acquire,
BOXED_BOOL, 2, false, false), BOXED_BOOL, 2, false, false),
{ boxInt(1) })); { autoDecref(boxInt(1)) }));
thread_lock_cls->giveAttr("release", thread_lock_cls->giveAttr("release",
new BoxedFunction(FunctionMetadata::create((void*)BoxedThreadLock::release, NONE, 1))); new BoxedFunction(FunctionMetadata::create((void*)BoxedThreadLock::release, NONE, 1)));
thread_lock_cls->giveAttr("acquire_lock", thread_lock_cls->getattr(internStringMortal("acquire"))); thread_lock_cls->giveAttrBorrowed("acquire_lock", thread_lock_cls->getattr(getStaticString("acquire")));
thread_lock_cls->giveAttr("release_lock", thread_lock_cls->getattr(internStringMortal("release"))); thread_lock_cls->giveAttrBorrowed("release_lock", thread_lock_cls->getattr(getStaticString("release")));
thread_lock_cls->giveAttr("__enter__", thread_lock_cls->getattr(internStringMortal("acquire"))); thread_lock_cls->giveAttrBorrowed("__enter__", thread_lock_cls->getattr(getStaticString("acquire")));
thread_lock_cls->giveAttr("__exit__", thread_lock_cls->giveAttr("__exit__",
new BoxedFunction(FunctionMetadata::create((void*)BoxedThreadLock::exit, NONE, 4))); new BoxedFunction(FunctionMetadata::create((void*)BoxedThreadLock::exit, NONE, 4)));
thread_lock_cls->giveAttr( thread_lock_cls->giveAttr(
"locked", new BoxedFunction(FunctionMetadata::create((void*)BoxedThreadLock::locked, BOXED_BOOL, 1))); "locked", new BoxedFunction(FunctionMetadata::create((void*)BoxedThreadLock::locked, BOXED_BOOL, 1)));
thread_lock_cls->giveAttr("locked_lock", thread_lock_cls->getattr(internStringMortal("locked"))); thread_lock_cls->giveAttrBorrowed("locked_lock", thread_lock_cls->getattr(getStaticString("locked")));
thread_lock_cls->freeze(); thread_lock_cls->freeze();
ThreadError = BoxedClass::create(type_cls, Exception, Exception->attrs_offset, Exception->tp_weaklistoffset, ThreadError = BoxedClass::create(type_cls, Exception, Exception->attrs_offset, Exception->tp_weaklistoffset,
...@@ -249,6 +249,6 @@ void setupThread() { ...@@ -249,6 +249,6 @@ void setupThread() {
ThreadError->giveAttr("__module__", boxString("thread")); ThreadError->giveAttr("__module__", boxString("thread"));
ThreadError->freeze(); ThreadError->freeze();
thread_module->giveAttr("error", ThreadError); thread_module->giveAttrBorrowed("error", ThreadError);
} }
} }
...@@ -3431,6 +3431,9 @@ void BoxedClass::dealloc(Box* b) noexcept { ...@@ -3431,6 +3431,9 @@ void BoxedClass::dealloc(Box* b) noexcept {
#endif #endif
std::vector<Box*> constants; std::vector<Box*> constants;
extern "C" void PyGC_RegisterStaticConstant(Box* b) {
constants.push_back(b);
}
extern "C" void _PyUnicode_Fini(void); extern "C" void _PyUnicode_Fini(void);
...@@ -3922,7 +3925,7 @@ void setupRuntime() { ...@@ -3922,7 +3925,7 @@ void setupRuntime() {
attrwrapperiter_cls->tp_iternext = AttrWrapperIter::next_capi; attrwrapperiter_cls->tp_iternext = AttrWrapperIter::next_capi;
setupBuiltins(); setupBuiltins();
//_PyExc_Init(); _PyExc_Init();
//setupThread(); //setupThread();
//initgc(); //initgc();
//setupImport(); //setupImport();
......
...@@ -796,7 +796,7 @@ public: ...@@ -796,7 +796,7 @@ public:
DEFAULT_CLASS_SIMPLE(dict_cls, true); DEFAULT_CLASS_SIMPLE(dict_cls, true);
Box* getOrNull(Box* k) { BORROWED(Box*) getOrNull(Box* k) {
const auto& p = d.find(BoxAndHash(k)); const auto& p = d.find(BoxAndHash(k));
if (p != d.end()) if (p != d.end())
return p->second; return p->second;
......
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