Commit fdf7fcca authored by Marius Wachtler's avatar Marius Wachtler

fix deepcopy of dictwrapper objects + enable test_urllib2 + test_array

add list self assignment and list.index with non int args
add thread._count
copy over test_urllib2 from the correct python version
parent 3f259086
...@@ -257,6 +257,14 @@ def _deepcopy_dict(x, memo): ...@@ -257,6 +257,14 @@ def _deepcopy_dict(x, memo):
y[deepcopy(key, memo)] = deepcopy(value, memo) y[deepcopy(key, memo)] = deepcopy(value, memo)
return y return y
d[dict] = _deepcopy_dict d[dict] = _deepcopy_dict
# Pyston change: teach copy how to handle attrwrappers
def get_attrwrapper_type():
class C(object):
pass
return type(C().__dict__)
d[get_attrwrapper_type()] = _deepcopy_dict
if PyStringMap is not None: if PyStringMap is not None:
d[PyStringMap] = _deepcopy_dict d[PyStringMap] = _deepcopy_dict
......
# expected: fail
"""Test the arraymodule. """Test the arraymodule.
Roger E. Masse Roger E. Masse
""" """
...@@ -766,6 +765,8 @@ class BaseTest(unittest.TestCase): ...@@ -766,6 +765,8 @@ class BaseTest(unittest.TestCase):
b = buffer(a) b = buffer(a)
self.assertEqual(b[0], a.tostring()[0]) self.assertEqual(b[0], a.tostring()[0])
# Pyston change: disable this test because of our GC
@unittest.skip("Pyston" in sys.version)
def test_weakref(self): def test_weakref(self):
s = array.array(self.typecode, self.example) s = array.array(self.typecode, self.example)
p = proxy(s) p = proxy(s)
......
# expected: fail
import unittest import unittest
from test import test_support from test import test_support
...@@ -9,11 +8,6 @@ import StringIO ...@@ -9,11 +8,6 @@ import StringIO
import urllib2 import urllib2
from urllib2 import Request, OpenerDirector from urllib2 import Request, OpenerDirector
try:
import ssl
except ImportError:
ssl = None
# XXX # XXX
# Request # Request
# CacheFTPHandler (hard to write) # CacheFTPHandler (hard to write)
...@@ -26,7 +20,7 @@ class TrivialTests(unittest.TestCase): ...@@ -26,7 +20,7 @@ class TrivialTests(unittest.TestCase):
self.assertRaises(ValueError, urllib2.urlopen, 'bogus url') self.assertRaises(ValueError, urllib2.urlopen, 'bogus url')
# XXX Name hacking to get this to work on Windows. # XXX Name hacking to get this to work on Windows.
fname = os.path.abspath(urllib2.__file__).replace(os.sep, '/') fname = os.path.abspath(urllib2.__file__).replace('\\', '/')
# And more hacking to get it to work on MacOS. This assumes # And more hacking to get it to work on MacOS. This assumes
# urllib.pathname2url works, unfortunately... # urllib.pathname2url works, unfortunately...
...@@ -53,14 +47,6 @@ class TrivialTests(unittest.TestCase): ...@@ -53,14 +47,6 @@ class TrivialTests(unittest.TestCase):
for string, list in tests: for string, list in tests:
self.assertEqual(urllib2.parse_http_list(string), list) self.assertEqual(urllib2.parse_http_list(string), list)
@unittest.skipUnless(ssl, "ssl module required")
def test_cafile_and_context(self):
context = ssl.create_default_context()
with self.assertRaises(ValueError):
urllib2.urlopen(
"https://localhost", cafile="/nonexistent/path", context=context
)
def test_request_headers_dict(): def test_request_headers_dict():
""" """
......
# expected: fail
import urlparse import urlparse
import urllib2 import urllib2
import BaseHTTPServer import BaseHTTPServer
......
...@@ -28,6 +28,7 @@ using namespace pyston::threading; ...@@ -28,6 +28,7 @@ using namespace pyston::threading;
extern "C" void initthread(); extern "C" void initthread();
std::atomic_long nb_threads;
static int initialized; static int initialized;
static void PyThread__init_thread(void); /* Forward */ static void PyThread__init_thread(void); /* Forward */
...@@ -69,6 +70,8 @@ static void* thread_start(Box* target, Box* varargs, Box* kwargs) { ...@@ -69,6 +70,8 @@ static void* thread_start(Box* target, Box* varargs, Box* kwargs) {
timer.pushTopLevel(getCPUTicks()); timer.pushTopLevel(getCPUTicks());
#endif #endif
++nb_threads;
try { try {
runtimeCall(target, ArgPassSpec(0, 0, true, kwargs != NULL), varargs, kwargs, NULL, NULL, NULL); runtimeCall(target, ArgPassSpec(0, 0, true, kwargs != NULL), varargs, kwargs, NULL, NULL, NULL);
} catch (ExcInfo e) { } catch (ExcInfo e) {
...@@ -79,6 +82,8 @@ static void* thread_start(Box* target, Box* varargs, Box* kwargs) { ...@@ -79,6 +82,8 @@ static void* thread_start(Box* target, Box* varargs, Box* kwargs) {
timer.popTopLevel(getCPUTicks()); timer.popTopLevel(getCPUTicks());
#endif #endif
--nb_threads;
return NULL; return NULL;
} }
...@@ -190,6 +195,10 @@ Box* stackSize() { ...@@ -190,6 +195,10 @@ Box* stackSize() {
Py_FatalError("unimplemented"); Py_FatalError("unimplemented");
} }
Box* threadCount() {
return boxInt(nb_threads);
}
void setupThread() { void setupThread() {
// Hacky: we want to use some of CPython's implementation of the thread module (the threading local stuff), // Hacky: we want to use some of CPython's implementation of the thread module (the threading local stuff),
// and some of ours (thread handling). Start off by calling a cut-down version of initthread, and then // and some of ours (thread handling). Start off by calling a cut-down version of initthread, and then
...@@ -209,6 +218,8 @@ void setupThread() { ...@@ -209,6 +218,8 @@ void setupThread() {
"get_ident", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)getIdent, BOXED_INT, 0), "get_ident")); "get_ident", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)getIdent, BOXED_INT, 0), "get_ident"));
thread_module->giveAttr( thread_module->giveAttr(
"stack_size", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)stackSize, BOXED_INT, 0), "stack_size")); "stack_size", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)stackSize, BOXED_INT, 0), "stack_size"));
thread_module->giveAttr(
"_count", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)threadCount, BOXED_INT, 0), "_count"));
thread_lock_cls = BoxedClass::create(type_cls, object_cls, NULL, 0, 0, sizeof(BoxedThreadLock), false, "lock"); thread_lock_cls = BoxedClass::create(type_cls, object_cls, NULL, 0, 0, sizeof(BoxedThreadLock), false, "lock");
thread_lock_cls->tp_dealloc = BoxedThreadLock::threadLockDestructor; thread_lock_cls->tp_dealloc = BoxedThreadLock::threadLockDestructor;
......
...@@ -462,9 +462,7 @@ int list_ass_ext_slice(BoxedList* self, PyObject* item, PyObject* value) { ...@@ -462,9 +462,7 @@ int list_ass_ext_slice(BoxedList* self, PyObject* item, PyObject* value) {
/* protect against a[::-1] = a */ /* protect against a[::-1] = a */
if (self == value) { if (self == value) {
abort(); seq = list_slice(value, 0, PyList_GET_SIZE(value));
// seq = list_slice((PyListObject*)value, 0,
// PyList_GET_SIZE(value));
} else { } else {
seq = PySequence_Fast(value, "must assign iterable " seq = PySequence_Fast(value, "must assign iterable "
"to extended slice"); "to extended slice");
...@@ -1021,13 +1019,16 @@ Box* listCount(BoxedList* self, Box* elt) { ...@@ -1021,13 +1019,16 @@ Box* listCount(BoxedList* self, Box* elt) {
return boxInt(count); return boxInt(count);
} }
Box* listIndex(BoxedList* self, Box* elt, BoxedInt* _start, Box** args) { Box* listIndex(BoxedList* self, Box* elt, Box* _start, Box** args) {
BoxedInt* _stop = (BoxedInt*)args[0]; Box* _stop = (BoxedInt*)args[0];
RELEASE_ASSERT(!_start || _start->cls == int_cls, "");
RELEASE_ASSERT(!_stop || _stop->cls == int_cls, "");
int64_t start = _start ? _start->n : 0; int64_t start = 0;
int64_t stop = _stop ? _stop->n : self->size; int64_t stop = self->size;
if (!_PyEval_SliceIndex(_start, &start))
throwCAPIException();
if (!_PyEval_SliceIndex(_stop, &stop))
throwCAPIException();
if (start < 0) { if (start < 0) {
start += self->size; start += self->size;
......
...@@ -23,7 +23,6 @@ test_aifc Unsupported subclassing from file? ...@@ -23,7 +23,6 @@ test_aifc Unsupported subclassing from file?
test_al No module named al test_al No module named al
test_applesingle Not really a failure, but it tries to skip itself and we don't support that test_applesingle Not really a failure, but it tries to skip itself and we don't support that
test_argparse [unknown] test_argparse [unknown]
test_array [unknown]
test_ascii_formattd [unknown] test_ascii_formattd [unknown]
test_ast [unknown] test_ast [unknown]
test_asynchat [unknown] test_asynchat [unknown]
...@@ -248,9 +247,7 @@ test_unicode_file exit code 139, no error message ...@@ -248,9 +247,7 @@ test_unicode_file exit code 139, no error message
test_unittest serialize_ast assert test_unittest serialize_ast assert
test_univnewlines2k [unknown] test_univnewlines2k [unknown]
test_univnewlines [unknown] test_univnewlines [unknown]
test_urllib2_localnet [unknown]
test_urllib2net [unknown] test_urllib2net [unknown]
test_urllib2 segfault due to attrwrapper corruption
test_urllibnet [unknown] test_urllibnet [unknown]
test_userdict segfault: repr of recursive dict? test_userdict segfault: repr of recursive dict?
test_userlist slice(1L, 1L) test_userlist slice(1L, 1L)
......
...@@ -7,6 +7,7 @@ c.a = 1 ...@@ -7,6 +7,7 @@ c.a = 1
c.b = (["str", 1], 2L) c.b = (["str", 1], 2L)
print sorted(c.__dict__.items()) print sorted(c.__dict__.items())
cc = copy.deepcopy(c) cc = copy.deepcopy(c)
copy_dict = copy.deepcopy(c.__dict__)
del c.a del c.a
print sorted(cc.__dict__.items()) print sorted(cc.__dict__.items())
print sorted(copy_dict.items())
...@@ -61,7 +61,7 @@ list_index = [1, 2, 3, 4, 5] ...@@ -61,7 +61,7 @@ list_index = [1, 2, 3, 4, 5]
for i in xrange(1, 6): for i in xrange(1, 6):
assert list_index.index(i) == i-1 assert list_index.index(i) == i-1
try: try:
print list_index.index(i, 3, 4) print list_index.index(i, 3L, 4L)
except ValueError as e: except ValueError as e:
print e print e
try: try:
...@@ -167,6 +167,8 @@ l = range(5) ...@@ -167,6 +167,8 @@ l = range(5)
l[2:4] = tuple(range(2)) l[2:4] = tuple(range(2))
print l print l
l[::-1] = l
print l
l = [None]*4 l = [None]*4
try: try:
......
from thread import start_new_thread, allocate_lock from thread import start_new_thread, allocate_lock, _count
import time import time
print type(allocate_lock()) print type(allocate_lock())
...@@ -9,11 +9,13 @@ done = 0 ...@@ -9,11 +9,13 @@ done = 0
def run(arg): def run(arg):
global done global done
with print_lock: with print_lock:
print "num threads:", _count()
print "in other thread!", arg print "in other thread!", arg
done = 1 done = 1
print "starting!" print "starting!"
print "num threads:", _count()
with print_lock: with print_lock:
t = start_new_thread(run, (5,)) t = start_new_thread(run, (5,))
print type(t) print type(t)
...@@ -22,6 +24,7 @@ while not done: ...@@ -22,6 +24,7 @@ while not done:
time.sleep(0) time.sleep(0)
print "done!" print "done!"
print "num threads:", _count()
done = False done = False
with print_lock: with print_lock:
...@@ -46,6 +49,7 @@ def run2(): ...@@ -46,6 +49,7 @@ def run2():
global state global state
print lock.acquire(0) print lock.acquire(0)
print "num threads:", _count()
state = 1 state = 1
print lock.acquire() print lock.acquire()
lock.release() lock.release()
......
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