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

Merge pull request #709 from toshok/mercurial-fixes

Mercurial fixes
parents 6fa67672 be56b96d
...@@ -479,17 +479,11 @@ static PyObject* file_write(BoxedFile* f, Box* arg) noexcept { ...@@ -479,17 +479,11 @@ static PyObject* file_write(BoxedFile* f, Box* arg) noexcept {
if (!f->writable) if (!f->writable)
return err_mode("writing"); return err_mode("writing");
if (f->f_binary) { if (f->f_binary) {
// In CPython, this branch calls PyArg_ParseTuple for all types, but we never created // NOTE: this call will create a new tuple every time we write to a binary file. if/when this becomes hot or
// the "args" tuple so we have to do some of the work that ParseTuple does. // creates too much GC pressure, we can fix it by adding a Pyston specific versino of PyArg_ParseTuple that
// Mostly it's easy since we've already unpacked the args, but there is some unicode-specific // (instead of taking a tuple) takes length + Box**. Then we'd call that directly here (passing "1, &arg").
// code in it that is better not to duplicate. if (!PyArg_ParseTuple(BoxedTuple::create({ arg }), "s*", &pbuf))
// So, if it's unicode, just make the tuple for now and send it through PyArg_ParseTuple.
if (PyUnicode_Check(arg)) {
if (!PyArg_ParseTuple(BoxedTuple::create({ arg }), "s*", &pbuf))
return NULL;
} else if (PyObject_GetBuffer(arg, &pbuf, 0))
return NULL; return NULL;
s = (const char*)pbuf.buf; s = (const char*)pbuf.buf;
n = pbuf.len; n = pbuf.len;
} else { } else {
......
...@@ -426,6 +426,12 @@ static Box* setIntersection(BoxedSet* self, BoxedTuple* args) { ...@@ -426,6 +426,12 @@ static Box* setIntersection(BoxedSet* self, BoxedTuple* args) {
return rtn; return rtn;
} }
static Box* setIntersectionUpdate(BoxedSet* self, BoxedTuple* args) {
Box* tmp = setIntersection(self, args);
std::swap(self->s, ((BoxedSet*)tmp)->s);
return None;
}
Box* setCopy(BoxedSet* self) { Box* setCopy(BoxedSet* self) {
RELEASE_ASSERT(PyAnySet_Check(self), ""); RELEASE_ASSERT(PyAnySet_Check(self), "");
...@@ -598,6 +604,9 @@ void setupSet() { ...@@ -598,6 +604,9 @@ void setupSet() {
set_cls->giveAttr("intersection", set_cls->giveAttr("intersection",
new BoxedFunction(boxRTFunction((void*)setIntersection, UNKNOWN, 1, 0, true, false))); new BoxedFunction(boxRTFunction((void*)setIntersection, UNKNOWN, 1, 0, true, false)));
frozenset_cls->giveAttr("intersection", set_cls->getattr(internStringMortal("intersection"))); frozenset_cls->giveAttr("intersection", set_cls->getattr(internStringMortal("intersection")));
set_cls->giveAttr("intersection_update",
new BoxedFunction(boxRTFunction((void*)setIntersectionUpdate, UNKNOWN, 1, 0, true, false)));
frozenset_cls->giveAttr("intersection_update", set_cls->getattr(internStringMortal("intersection_update")));
set_cls->giveAttr("difference", new BoxedFunction(boxRTFunction((void*)setDifference, UNKNOWN, 1, 0, true, false))); set_cls->giveAttr("difference", new BoxedFunction(boxRTFunction((void*)setDifference, UNKNOWN, 1, 0, true, false)));
frozenset_cls->giveAttr("difference", set_cls->getattr(internStringMortal("difference"))); frozenset_cls->giveAttr("difference", set_cls->getattr(internStringMortal("difference")));
set_cls->giveAttr("difference_update", set_cls->giveAttr("difference_update",
......
import os import os
import tempfile import tempfile
import array
fd, fn = tempfile.mkstemp() fd, fn = tempfile.mkstemp()
with open(fn, "wb") as f: with open(fn, "wb") as f:
f.write("hello world!\n") f.write("hello world!\n")
f.write(u"hello world2") f.write(u"hello world2")
f.write(array.array('c', 'hello world'))
with open(fn) as f: with open(fn) as f:
print repr(f.read()) print repr(f.read())
......
...@@ -133,3 +133,9 @@ for s1 in set(range(5)), frozenset(range(5)): ...@@ -133,3 +133,9 @@ for s1 in set(range(5)), frozenset(range(5)):
f = float('nan') f = float('nan')
s = set([f]) s = set([f])
print f in s, f == list(s)[0] print f in s, f == list(s)[0]
s1 = set([3, 5])
s2 = set([1, 5])
s1.intersection_update(s2)
print sorted(s1)
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