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