Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions from_cpython/Modules/_io/bufferedio.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,9 @@ _PyIO_trap_eintr(void)
if (eintr_int == NULL) {
eintr_int = PyLong_FromLong(EINTR);
assert(eintr_int != NULL);

// Pyston change:
PyGC_RegisterStaticConstant(eintr_int);
}
if (!PyErr_ExceptionMatches(PyExc_EnvironmentError))
return 0;
Expand Down
13 changes: 11 additions & 2 deletions src/codegen/ast_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1574,8 +1574,13 @@ Value ASTInterpreter::visit_dict(AST_Dict* node) {
BoxedDict* dict = new BoxedDict();
for (size_t i = 0; i < node->keys.size(); ++i) {
Value v = visit_expr(node->values[i]);
AUTO_DECREF(v.o);
Value k = visit_expr(node->keys[i]);
dict->d[k.o] = v.o;
AUTO_DECREF(k.o);

int ret = PyDict_SetItem(dict, k.o, v.o);
if (ret == -1)
throwCAPIException();

values.push_back(v);
keys.push_back(k);
Expand All @@ -1590,7 +1595,11 @@ Value ASTInterpreter::visit_set(AST_Set* node) {
BoxedSet::Set set;
for (AST_expr* e : node->elts) {
Value v = visit_expr(e);
set.insert(v.o);
auto&& p = set.insert(v.o);
if (!p.second /* already exists */) {
Py_DECREF(p.first->value);
*p.first = v.o;
}
items.push_back(v);
}

Expand Down
13 changes: 10 additions & 3 deletions src/codegen/baseline_jit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,9 @@ Box* JitFragmentWriter::callattrHelper(Box* obj, BoxedString* attr, CallattrFlag
Box* JitFragmentWriter::createDictHelper(uint64_t num, Box** keys, Box** values) {
BoxedDict* dict = (BoxedDict*)createDict();
for (uint64_t i = 0; i < num; ++i) {
dict->d[keys[i]] = values[i];
int ret = PyDict_SetItem(dict, autoDecref(keys[i]), autoDecref(values[i]));
if (ret == -1)
throwCAPIException();
}
return dict;
}
Expand All @@ -870,8 +872,13 @@ Box* JitFragmentWriter::createListHelper(uint64_t num, Box** data) {

Box* JitFragmentWriter::createSetHelper(uint64_t num, Box** data) {
BoxedSet* set = (BoxedSet*)createSet();
for (int i = 0; i < num; ++i)
set->s.insert(data[i]);
for (int i = 0; i < num; ++i) {
auto&& p = set->s.insert(data[i]);
if (!p.second /* already exists */) {
Py_DECREF(p.first->value);
*p.first = data[i];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should use the original value and decref the duplicate one: set([1, 1L]) is 1 for CPython and 1L for us.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches the behavior for dict keys, but is different from dict values -- {1:1, 1L:1L} is {1: 1L}.

}
}
return set;
}

Expand Down
4 changes: 3 additions & 1 deletion src/jit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ static int main(int argc, char** argv) noexcept {
}
} else if (module != NULL) {
// TODO: CPython uses the same main module for all code paths
main_module = createModule(boxString("__main__"), "<string>");
main_module = createModule(autoDecref(boxString("__main__")), "<string>");
rtncode = (RunModule(module, 1) != 0);
} else {
main_module = createModule(autoDecref(boxString("__main__")), fn ? fn : "<stdin>");
Expand Down Expand Up @@ -526,6 +526,8 @@ static int main(int argc, char** argv) noexcept {
PyObject* v = PyImport_ImportModule("readline");
if (!v)
PyErr_Clear();
else
Py_CLEAR(v);

printf("Pyston v%d.%d.%d (rev " STRINGIFY(GITREV) ")", PYSTON_VERSION_MAJOR, PYSTON_VERSION_MINOR,
PYSTON_VERSION_MICRO);
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,6 @@ extern "C" int PyRun_InteractiveOneFlags(FILE* fp, const char* filename, PyCompi
// Pyston change:
// d = PyModule_GetDict(m);
// v = run_mod(mod, filename, d, d, flags, arena);
v = None;
Py_INCREF(v);
assert(PyModule_Check(m));
bool failed = false;
try {
Expand All @@ -1005,7 +1003,9 @@ extern "C" int PyRun_InteractiveOneFlags(FILE* fp, const char* filename, PyCompi
PyErr_Print();
return -1;
}
Py_DECREF(v);
// Pyston change: we dont't have v
// Py_DECREF(v);

if (Py_FlushLine())
PyErr_Clear();
return 0;
Expand Down
1 change: 1 addition & 0 deletions src/runtime/objmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3120,6 +3120,7 @@ extern "C" void setattr(Box* obj, BoxedString* attr, STOLEN(Box*) attr_val) {
STAT_TIMER(t1, "us_timer_slowpath_tpsetattr", 10);

assert(attr->data()[attr->size()] == '\0');
AUTO_DECREF(attr_val);
int rtn = obj->cls->tp_setattr(obj, const_cast<char*>(attr->data()), attr_val);
if (rtn)
throwCAPIException();
Expand Down
2 changes: 1 addition & 1 deletion test/tests/dict.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
d = {2:2}
d = {2:"should get overwritten", 2:2}
d[1] = 1
print d
print d[1], d[1L], d[1.0], d[True]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/set.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
s1 = {1}
s1 = {1, 1}

def sorted(s):
l = list(s)
Expand Down