Commit 2c20ac1d authored by Kevin Modzelewski's avatar Kevin Modzelewski

Get unicode working

parent 24d82a06
......@@ -3192,9 +3192,14 @@ extern "C" PyUnicodeObject* _PyUnicode_New(Py_ssize_t length) noexcept {
// Pyston change: allocate ->str first, so that if this allocation
// causes a collection, we don't see a half-created unicode object:
size_t new_size = sizeof(Py_UNICODE) * ((size_t)length + 1);
Py_UNICODE* str = (Py_UNICODE*)PyObject_MALLOC(new_size);
if (!str)
unicode = PyObject_New(PyUnicodeObject, &PyUnicode_Type);
if (unicode == NULL)
return NULL;
unicode->str = (Py_UNICODE*)PyObject_MALLOC(new_size);
if (!unicode->str) {
Py_DECREF(unicode);
return (PyUnicodeObject*)PyErr_NoMemory();
}
#if STAT_ALLOCATIONS
{
......@@ -3203,22 +3208,6 @@ extern "C" PyUnicodeObject* _PyUnicode_New(Py_ssize_t length) noexcept {
}
#endif
// Do a bunch of inlining + constant folding of this line of CPython's:
// unicode = PyObject_New(PyUnicodeObject, &PyUnicode_Type);
assert(PyUnicode_Type.tp_basicsize == sizeof(PyUnicodeObject)); // use the compile-time constant
RELEASE_ASSERT(0, " track the ref, but keep the inlining?");
unicode = (PyUnicodeObject*)PyObject_MALLOC(sizeof(PyUnicodeObject));
if (unicode == NULL)
return (PyUnicodeObject*)PyErr_NoMemory();
// Inline PyObject_INIT:
assert(!PyType_SUPPORTS_WEAKREFS(&PyUnicode_Type));
assert(!PyUnicode_Type.instancesHaveHCAttrs());
assert(!PyUnicode_Type.instancesHaveDictAttrs());
unicode->ob_type = (struct _typeobject*)&PyUnicode_Type;
unicode->str = str;
/* Initialize the first element to guard against cases where
* the caller fails before initializing str -- unicode_resize()
* reads str[0], and the Keep-Alive optimization can keep memory
......@@ -3443,6 +3432,8 @@ void BoxedClass::dealloc(Box* b) noexcept {
std::vector<Box*> constants;
extern "C" void _PyUnicode_Fini(void);
bool TRACK_ALLOCATIONS = false;
void setupRuntime() {
root_hcls = HiddenClass::makeRoot();
......@@ -3794,6 +3785,7 @@ void setupRuntime() {
// XXX
PyType_ClearCache();
_Py_ReleaseInternedStrings();
_PyUnicode_Fini();
for (auto b : classes)
b->clearAttrs();
for (auto b : constants) {
......
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