[pypy-commit] pypy default: simplify sqlite cursor locking

2013-03-06 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r62123:92298f0e65e7
Date: 2013-03-06 02:35 -0500
http://bitbucket.org/pypy/pypy/changeset/92298f0e65e7/

Log:simplify sqlite cursor locking

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -739,20 +739,6 @@
 raise OperationalError("Error enabling load extension")
 
 
-class _CursorLock(object):
-def __init__(self, cursor):
-self.cursor = cursor
-
-def __enter__(self):
-self.cursor._check_closed()
-if self.cursor._locked:
-raise ProgrammingError("Recursive use of cursors not allowed.")
-self.cursor._locked = True
-
-def __exit__(self, *args):
-self.cursor._locked = False
-
-
 class Cursor(object):
 __initialized = False
 __connection = None
@@ -770,8 +756,8 @@
 
 self.arraysize = 1
 self.row_factory = None
-self._locked = False
 self._reset = False
+self.__locked = False
 self.__closed = False
 self.__description = None
 self.__rowcount = -1
@@ -798,6 +784,8 @@
 raise ProgrammingError("Base Cursor.__init__ not called.")
 if self.__closed:
 raise ProgrammingError("Cannot operate on a closed cursor.")
+if self.__locked:
+raise ProgrammingError("Recursive use of cursors not allowed.")
 self.__connection._check_thread()
 self.__connection._check_closed()
 
@@ -805,7 +793,9 @@
 if type(sql) is unicode:
 sql = sql.encode("utf-8")
 
-with _CursorLock(self):
+self._check_closed()
+self.__locked = True
+try:
 self.__description = None
 self._reset = False
 self.__statement = self.__connection._statement_cache.get(
@@ -842,6 +832,8 @@
 self.__rowcount = -1
 if self.__statement.kind == _DML:
 self.__rowcount = sqlite.sqlite3_changes(self.__connection._db)
+finally:
+self.__locked = False
 
 return self
 
@@ -849,7 +841,9 @@
 if type(sql) is unicode:
 sql = sql.encode("utf-8")
 
-with _CursorLock(self):
+self._check_closed()
+self.__locked = True
+try:
 self.__description = None
 self._reset = False
 self.__statement = self.__connection._statement_cache.get(
@@ -873,6 +867,8 @@
 raise self.__connection._get_exception(ret)
 self.__rowcount += 
sqlite.sqlite3_changes(self.__connection._db)
 self.__statement.reset()
+finally:
+self.__locked = False
 
 return self
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: mangle these implementation-specific function names

2013-03-06 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r62124:c02d9c36ffa2
Date: 2013-03-06 02:40 -0500
http://bitbucket.org/pypy/pypy/changeset/c02d9c36ffa2/

Log:mangle these implementation-specific function names

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -779,7 +779,7 @@
 self.__statement = None
 self.__closed = True
 
-def _check_closed(self):
+def __check_cursor(self):
 if not self.__initialized:
 raise ProgrammingError("Base Cursor.__init__ not called.")
 if self.__closed:
@@ -793,7 +793,7 @@
 if type(sql) is unicode:
 sql = sql.encode("utf-8")
 
-self._check_closed()
+self.__check_cursor()
 self.__locked = True
 try:
 self.__description = None
@@ -841,7 +841,7 @@
 if type(sql) is unicode:
 sql = sql.encode("utf-8")
 
-self._check_closed()
+self.__check_cursor()
 self.__locked = True
 try:
 self.__description = None
@@ -877,7 +877,7 @@
 self._reset = False
 if type(sql) is unicode:
 sql = sql.encode("utf-8")
-self._check_closed()
+self.__check_cursor()
 statement = c_void_p()
 c_sql = c_char_p(sql)
 
@@ -908,7 +908,7 @@
 break
 return self
 
-def _check_reset(self):
+def __check_reset(self):
 if self._reset:
 raise self.__connection.InterfaceError("Cursor needed to be reset 
because "
  "of commit/rollback and can "
@@ -916,8 +916,8 @@
 
 # do all statements
 def fetchone(self):
-self._check_closed()
-self._check_reset()
+self.__check_cursor()
+self.__check_reset()
 
 if self.__statement is None:
 return None
@@ -928,8 +928,8 @@
 return None
 
 def fetchmany(self, size=None):
-self._check_closed()
-self._check_reset()
+self.__check_cursor()
+self.__check_reset()
 if self.__statement is None:
 return []
 if size is None:
@@ -942,8 +942,8 @@
 return lst
 
 def fetchall(self):
-self._check_closed()
-self._check_reset()
+self.__check_cursor()
+self.__check_reset()
 if self.__statement is None:
 return []
 return list(self)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: additional small cleanups for sqlite

2013-03-06 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r62125:51cce4632d7c
Date: 2013-03-06 02:56 -0500
http://bitbucket.org/pypy/pypy/changeset/51cce4632d7c/

Log:additional small cleanups for sqlite

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -284,13 +284,16 @@
 return unicode(x, 'utf-8')
 
 
-class StatementCache(object):
+class _StatementCache(object):
 def __init__(self, connection, maxcount):
 self.connection = connection
 self.maxcount = maxcount
 self.cache = OrderedDict()
 
 def get(self, sql, row_factory):
+if isinstance(sql, unicode):
+sql = sql.encode('utf-8')
+
 try:
 stat = self.cache[sql]
 except KeyError:
@@ -298,7 +301,7 @@
 self.cache[sql] = stat
 if len(self.cache) > self.maxcount:
 self.cache.popitem(0)
-#
+
 if stat.in_use:
 stat = Statement(self.connection, sql)
 stat.set_row_factory(row_factory)
@@ -330,7 +333,7 @@
 self._cursors = []
 self.__statements = []
 self.__statement_counter = 0
-self._statement_cache = StatementCache(self, cached_statements)
+self._statement_cache = _StatementCache(self, cached_statements)
 
 self.__func_cache = {}
 self.__aggregates = {}
@@ -376,10 +379,10 @@
 
 def _check_closed_wrap(func):
 @wraps(func)
-def _check_closed_func(self, *args, **kwargs):
+def wrapper(self, *args, **kwargs):
 self._check_closed()
 return func(self, *args, **kwargs)
-return _check_closed_func
+return wrapper
 
 def _check_thread(self):
 try:
@@ -395,10 +398,10 @@
 
 def _check_thread_wrap(func):
 @wraps(func)
-def _check_thread_func(self, *args, **kwargs):
+def wrapper(self, *args, **kwargs):
 self._check_thread()
 return func(self, *args, **kwargs)
-return _check_thread_func
+return wrapper
 
 def _get_exception(self, error_code=None):
 if error_code is None:
@@ -441,8 +444,7 @@
 def __call__(self, sql):
 if not isinstance(sql, (str, unicode)):
 raise Warning("SQL is of wrong type. Must be string or unicode.")
-statement = self._statement_cache.get(sql, self.row_factory)
-return statement
+return self._statement_cache.get(sql, self.row_factory)
 
 def cursor(self, factory=None):
 self._check_thread()
@@ -790,9 +792,6 @@
 self.__connection._check_closed()
 
 def execute(self, sql, params=None):
-if type(sql) is unicode:
-sql = sql.encode("utf-8")
-
 self.__check_cursor()
 self.__locked = True
 try:
@@ -838,9 +837,6 @@
 return self
 
 def executemany(self, sql, many_params):
-if type(sql) is unicode:
-sql = sql.encode("utf-8")
-
 self.__check_cursor()
 self.__locked = True
 try:
@@ -910,9 +906,9 @@
 
 def __check_reset(self):
 if self._reset:
-raise self.__connection.InterfaceError("Cursor needed to be reset 
because "
- "of commit/rollback and can "
- "no longer be fetched from.")
+raise self.__connection.InterfaceError(
+"Cursor needed to be reset because of commit/rollback "
+"and can no longer be fetched from.")
 
 # do all statements
 def fetchone(self):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: merge default

2013-03-06 Thread bdkearns
Author: Brian Kearns 
Branch: py3k
Changeset: r62126:878a364bd84f
Date: 2013-03-06 03:45 -0500
http://bitbucket.org/pypy/pypy/changeset/878a364bd84f/

Log:merge default

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -291,7 +291,7 @@
 return str(x, 'utf-8')
 
 
-class StatementCache(object):
+class _StatementCache(object):
 def __init__(self, connection, maxcount):
 self.connection = connection
 self.maxcount = maxcount
@@ -305,7 +305,7 @@
 self.cache[sql] = stat
 if len(self.cache) > self.maxcount:
 self.cache.popitem(0)
-#
+
 if stat.in_use:
 stat = Statement(self.connection, sql)
 stat.set_row_factory(row_factory)
@@ -337,7 +337,7 @@
 self._cursors = []
 self.__statements = []
 self.__statement_counter = 0
-self._statement_cache = StatementCache(self, cached_statements)
+self._statement_cache = _StatementCache(self, cached_statements)
 
 self.__func_cache = {}
 self.__aggregates = {}
@@ -383,10 +383,10 @@
 
 def _check_closed_wrap(func):
 @wraps(func)
-def _check_closed_func(self, *args, **kwargs):
+def wrapper(self, *args, **kwargs):
 self._check_closed()
 return func(self, *args, **kwargs)
-return _check_closed_func
+return wrapper
 
 def _check_thread(self):
 try:
@@ -402,10 +402,10 @@
 
 def _check_thread_wrap(func):
 @wraps(func)
-def _check_thread_func(self, *args, **kwargs):
+def wrapper(self, *args, **kwargs):
 self._check_thread()
 return func(self, *args, **kwargs)
-return _check_thread_func
+return wrapper
 
 def _get_exception(self, error_code=None):
 if error_code is None:
@@ -449,8 +449,7 @@
 def __call__(self, sql):
 if not isinstance(sql, str):
 raise Warning("SQL is of wrong type. Must be string or unicode.")
-statement = self._statement_cache.get(sql, self.row_factory)
-return statement
+return self._statement_cache.get(sql, self.row_factory)
 
 def cursor(self, factory=None):
 self._check_thread()
@@ -749,20 +748,6 @@
 raise OperationalError("Error enabling load extension")
 
 
-class _CursorLock(object):
-def __init__(self, cursor):
-self.cursor = cursor
-
-def __enter__(self):
-self.cursor._check_closed()
-if self.cursor._locked:
-raise ProgrammingError("Recursive use of cursors not allowed.")
-self.cursor._locked = True
-
-def __exit__(self, *args):
-self.cursor._locked = False
-
-
 class Cursor(object):
 __initialized = False
 __connection = None
@@ -780,8 +765,8 @@
 
 self.arraysize = 1
 self.row_factory = None
-self._locked = False
 self._reset = False
+self.__locked = False
 self.__closed = False
 self.__description = None
 self.__rowcount = -1
@@ -803,16 +788,20 @@
 self.__statement = None
 self.__closed = True
 
-def _check_closed(self):
+def __check_cursor(self):
 if not self.__initialized:
 raise ProgrammingError("Base Cursor.__init__ not called.")
 if self.__closed:
 raise ProgrammingError("Cannot operate on a closed cursor.")
+if self.__locked:
+raise ProgrammingError("Recursive use of cursors not allowed.")
 self.__connection._check_thread()
 self.__connection._check_closed()
 
 def execute(self, sql, params=None):
-with _CursorLock(self):
+self.__check_cursor()
+self.__locked = True
+try:
 self.__description = None
 self._reset = False
 self.__statement = self.__connection._statement_cache.get(
@@ -849,11 +838,15 @@
 self.__rowcount = -1
 if self.__statement.kind == _DML:
 self.__rowcount = sqlite.sqlite3_changes(self.__connection._db)
+finally:
+self.__locked = False
 
 return self
 
 def executemany(self, sql, many_params):
-with _CursorLock(self):
+self.__check_cursor()
+self.__locked = True
+try:
 self.__description = None
 self._reset = False
 self.__statement = self.__connection._statement_cache.get(
@@ -877,6 +870,8 @@
 raise self.__connection._get_exception(ret)
 self.__rowcount += 
sqlite.sqlite3_changes(self.__connection._db)
 self.__statement.reset()
+finally:
+self.__locked = False
 
 return self
 
@@ -885,7 +880,7 @@
 self._reset = False
 if type(sql) is str:
 sql = sql.encode("utf-8")
-self._check_closed()
+self.__check_cursor()
 sta

[pypy-commit] pypy default: test and fix for sqlite check_cursor behavior

2013-03-06 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r62127:cdcf1ad3fcbe
Date: 2013-03-06 03:57 -0500
http://bitbucket.org/pypy/pypy/changeset/cdcf1ad3fcbe/

Log:test and fix for sqlite check_cursor behavior

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -791,8 +791,15 @@
 self.__connection._check_thread()
 self.__connection._check_closed()
 
+def __check_cursor_wrap(func):
+@wraps(func)
+def wrapper(self, *args, **kwargs):
+self.__check_cursor()
+return func(self, *args, **kwargs)
+return wrapper
+
+@__check_cursor_wrap
 def execute(self, sql, params=None):
-self.__check_cursor()
 self.__locked = True
 try:
 self.__description = None
@@ -836,8 +843,8 @@
 
 return self
 
+@__check_cursor_wrap
 def executemany(self, sql, many_params):
-self.__check_cursor()
 self.__locked = True
 try:
 self.__description = None
diff --git a/pypy/module/test_lib_pypy/test_sqlite3.py 
b/pypy/module/test_lib_pypy/test_sqlite3.py
--- a/pypy/module/test_lib_pypy/test_sqlite3.py
+++ b/pypy/module/test_lib_pypy/test_sqlite3.py
@@ -58,6 +58,9 @@
  cur.close()
  con.close()
  pytest.raises(_sqlite3.ProgrammingError, "cur.close()")
+ # raises ProgrammingError because should check closed before check args
+ pytest.raises(_sqlite3.ProgrammingError, "cur.execute(1,2,3,4,5)")
+ pytest.raises(_sqlite3.ProgrammingError, "cur.executemany(1,2,3,4,5)")
 
 @pytest.mark.skipif("not hasattr(sys, 'pypy_translation_info')")
 def test_cursor_del():
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k-memoryview: Temporarily rename array's itemsize to itemsize_ to work around an annotator bug.

2013-03-06 Thread Manuel Jacob
Author: Manuel Jacob
Branch: py3k-memoryview
Changeset: r62128:45b480dc2f6d
Date: 2013-03-06 10:49 +0100
http://bitbucket.org/pypy/pypy/changeset/45b480dc2f6d/

Log:Temporarily rename array's itemsize to itemsize_ to work around an
annotator bug.

diff --git a/pypy/module/array/interp_array.py 
b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -83,7 +83,7 @@
 
 
 def descr_itemsize(space, self):
-return space.wrap(self.itemsize)
+return space.wrap(self.itemsize_)
 
 
 def descr_typecode(space, self):
@@ -157,7 +157,7 @@
 def __init__(self, array):
 self.array = array
 self.format = array.typecode
-self.itemsize = array.itemsize
+self.itemsize = array.itemsize_
 
 def getlength(self):
 return self.array.len
@@ -203,7 +203,7 @@
 W_ArrayBase = globals()['W_ArrayBase']
 
 class W_Array(W_ArrayBase):
-itemsize = mytype.bytes
+itemsize_ = mytype.bytes
 typecode = mytype.typecode
 
 @staticmethod
@@ -321,7 +321,7 @@
 self.setlen(oldlen + i)
 
 def fromstring(self, s):
-if len(s) % self.itemsize != 0:
+if len(s) % self.itemsize_ != 0:
 msg = 'string length not a multiple of item size'
 raise OperationError(self.space.w_ValueError, 
self.space.wrap(msg))
 oldlen = self.len
@@ -598,14 +598,14 @@
 n = space.int_w(w_n)
 
 try:
-size = ovfcheck(self.itemsize * n)
+size = ovfcheck(self.itemsize_ * n)
 except OverflowError:
 raise MemoryError
 w_item = space.call_method(w_f, 'read', space.wrap(size))
 item = space.bytes_w(w_item)
 if len(item) < size:
-n = len(item) % self.itemsize
-elems = max(0, len(item) - (len(item) % self.itemsize))
+n = len(item) % self.itemsize_
+elems = max(0, len(item) - (len(item) % self.itemsize_))
 if n != 0:
 item = item[0:elems]
 w_item = space.wrapbytes(item)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k-memoryview: Python 3.2 supports tolist() only on byte memoryviews.

2013-03-06 Thread Manuel Jacob
Author: Manuel Jacob
Branch: py3k-memoryview
Changeset: r62129:b1c812a69e23
Date: 2013-03-06 11:54 +0100
http://bitbucket.org/pypy/pypy/changeset/b1c812a69e23/

Log:Python 3.2 supports tolist() only on byte memoryviews.

diff --git a/pypy/module/__builtin__/interp_memoryview.py 
b/pypy/module/__builtin__/interp_memoryview.py
--- a/pypy/module/__builtin__/interp_memoryview.py
+++ b/pypy/module/__builtin__/interp_memoryview.py
@@ -78,9 +78,12 @@
 def descr_tolist(self, space):
 self._check_released(space)
 buf = self.buf
+if buf.format != 'B':
+raise OperationError(space.w_NotImplementedError, space.wrap(
+"tolist() only supports byte views"))
 result = []
 for i in range(buf.getlength()):
-result.append(space.wrap(ord(buf.getitem(i
+result.append(space.wrap(ord(buf.getitem(i)[0])))
 return space.newlist(result)
 
 def descr_getitem(self, space, w_index):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k-memoryview: Mark 'format' and 'itemsize' as immutable fields.

2013-03-06 Thread Manuel Jacob
Author: Manuel Jacob
Branch: py3k-memoryview
Changeset: r62130:ac19e2710459
Date: 2013-03-06 11:57 +0100
http://bitbucket.org/pypy/pypy/changeset/ac19e2710459/

Log:Mark 'format' and 'itemsize' as immutable fields.

diff --git a/pypy/interpreter/buffer.py b/pypy/interpreter/buffer.py
--- a/pypy/interpreter/buffer.py
+++ b/pypy/interpreter/buffer.py
@@ -27,6 +27,7 @@
 """Abstract base class for memory views."""
 
 __slots__ = ('format', 'itemsize')
+_immutable_fields_ = ('format', 'itemsize')
 
 def getlength(self):
 raise NotImplementedError
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: fixes for frame_realloc

2013-03-06 Thread bivab
Author: David Schneider 
Branch: jitframe-on-heap
Changeset: r62131:aea384698a85
Date: 2013-03-06 15:09 +0100
http://bitbucket.org/pypy/pypy/changeset/aea384698a85/

Log:fixes for frame_realloc

diff --git a/rpython/jit/backend/arm/assembler.py 
b/rpython/jit/backend/arm/assembler.py
--- a/rpython/jit/backend/arm/assembler.py
+++ b/rpython/jit/backend/arm/assembler.py
@@ -742,14 +742,14 @@
 """
 descrs = self.cpu.gc_ll_descr.getframedescrs(self.cpu)
 ofs = self.cpu.unpack_fielddescr(descrs.arraydescr.lendescr)
-mc.LDR_ri(r.r12.value, r.fp.value, imm=ofs)
+mc.LDR_ri(r.ip.value, r.fp.value, imm=ofs)
 stack_check_cmp_ofs = mc.currpos()
 if expected_size == -1:
 mc.NOP()
 mc.NOP()
 else:
 mc.gen_load_int(r.lr.value, expected_size)
-mc.CMP_rr(r.lr.value, r.ip.value)
+mc.CMP_rr(r.ip.value, r.lr.value)
 
 jg_location = mc.currpos()
 mc.BKPT()
@@ -805,11 +805,12 @@
 #
 mc.BL(self.cpu.realloc_frame)
 
+# set fp to the new jitframe
+mc.MOV_rr(r.fp.value, r.r0.value)
+
 # restore a possibly present exception
 self._restore_exception(mc, None, r.fp)
 
-# set fp to the new jitframe
-mc.MOV_rr(r.fp.value, r.r0.value)
 
 gcrootmap = self.cpu.gc_ll_descr.gcrootmap
 if gcrootmap and gcrootmap.is_shadow_stack:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] extradoc extradoc: rework numpypy namespace changes (bdk)

2013-03-06 Thread mattip
Author: mattip 
Branch: extradoc
Changeset: r4952:b9c938b296b6
Date: 2013-03-06 18:36 +0200
http://bitbucket.org/pypy/extradoc/changeset/b9c938b296b6/

Log:rework numpypy namespace changes (bdk)

diff --git a/blog/draft/numpy-status-update-6.rst 
b/blog/draft/numpy-status-update-6.rst
--- a/blog/draft/numpy-status-update-6.rst
+++ b/blog/draft/numpy-status-update-6.rst
@@ -17,11 +17,13 @@
 
 * **pickling support for numarray** - hasn't started yet, but next on the list
 
-* There has been some work on exposing FFI routines in numpypy.
+* There has been some work on exposing **FFI routines** in numpypy.
 
-* Brian Kearns has made progress in mapping translated _numpypy submodules to 
-  the numpy core c-based submodules, furthering the goal of being able to 
install
-  numpy as a pure-python module with few modifications. 
+* Brian Kearns has made progress in improving the **numpypy namespace**.
+  The python numpypy submodules now more closely resemble their numpy 
+  counterparts. Also, translated _numpypy submodules are now more properly 
+  mapped to the numpy core c-based submodules, furthering the goal of being 
+  able to install numpy as a pure-python module with few modifications.
 
 And now the good news:
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: fix the test

2013-03-06 Thread fijal
Author: Maciej Fijalkowski 
Branch: jitframe-on-heap
Changeset: r62132:195a90abd218
Date: 2013-03-06 21:00 +0200
http://bitbucket.org/pypy/pypy/changeset/195a90abd218/

Log:fix the test

diff --git a/rpython/jit/backend/arm/test/test_runner.py 
b/rpython/jit/backend/arm/test/test_runner.py
--- a/rpython/jit/backend/arm/test/test_runner.py
+++ b/rpython/jit/backend/arm/test/test_runner.py
@@ -24,7 +24,9 @@
 # > ../../test/runner_test.py
 
 add_loop_instructions = ['ldr', 'mov', 'adds', 'cmp', 'beq', 'b']
-bridge_loop_instructions = ['movw', 'movt', 'bx']
+bridge_loop_instructions = ['ldr', 'mov', 'nop', 'cmp', 'bge',
+'push', 'mov', 'mov', 'push', 'mov', 'mov',
+'blx', 'mov', 'mov', 'bx']
 
 def get_cpu(self):
 cpu = CPU(rtyper=None, stats=FakeStats())
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk default: Switched from a context return based implementation to Exception Raising returns.

2013-03-06 Thread lwassermann
Author: Lars Wassermann 
Branch: 
Changeset: r121:079f6dd1e62f
Date: 2013-03-05 17:14 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/079f6dd1e62f/

Log:Switched from a context return based implementation to Exception
Raising returns. This way, contexts are not manipulated during
return, but on catching the exception.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -28,8 +28,8 @@
 _last_indent = ""
 jit_driver = jit.JitDriver(
 greens=['pc', 'self', 'method'],
-reds=['s_active_context'],
-#virtualizables=['s_active_context'],
+reds=['mark', 's_context'],
+#virtualizables=['s_context'],
 get_printable_location=get_printable_location
 )
 
@@ -60,25 +60,31 @@
 s_new_context = w_active_context.as_context_get_shadow(self.space)
 while True:
 try:
-s_new_context = self.c_loop(s_new_context)
+s_new_context = self.c_loop(s_new_context, mark=False)
 except StackOverflow, e:
 self.remaining_stack_depth = self.max_stack_depth
 s_new_context = e.s_context
+except Return, nlr:
+while s_new_context is not nlr.s_target_context:
+s_new_context, _ = s_new_context.s_sender(), 
s_new_context.mark_returned()
+s_new_context.push(nlr.value)
 
-def c_loop(self, s_context):
-s_active_context = s_context
+def c_loop(self, s_context, mark=True):
 while True:
-pc = s_active_context._pc
-method = s_active_context.s_method()
+pc = s_context._pc
+method = s_context.s_method()
 
 self.jit_driver.jit_merge_point(
 pc=pc, self=self, method=method,
-s_active_context=s_active_context)
-s_return_to_context = self.step(s_active_context)
-if (s_return_to_context is not None
-and s_return_to_context is not s_context):
-s_active_context.mark_returned()
-return s_return_to_context
+mark=mark, s_context=s_context)
+try:
+self.step(s_context)
+except Return, nlr:
+if nlr.s_target_context is not s_context:
+if mark: s_context.mark_returned()
+raise nlr
+else:
+s_context.push(nlr.value)
 
 def stack_frame(self, s_new_frame):
 if not self._loop:
@@ -88,8 +94,10 @@
 raise StackOverflow(s_new_frame)
 
 self.remaining_stack_depth -= 1
-retval = self.c_loop(s_new_frame)
-self.remaining_stack_depth += 1
+try:
+retval = self.c_loop(s_new_frame)
+finally:
+self.remaining_stack_depth += 1
 return retval
 
 def perform(self, w_receiver, selector, *arguments_w):
@@ -109,7 +117,11 @@
 s_frame.push(w_receiver)
 s_frame.push_all(list(arguments_w))
 try:
-s_new_frame = s_frame._sendSelfSelector(w_selector, 
len(arguments_w), self)
+try:
+s_new_frame = s_frame._sendSelfSelector(w_selector, 
len(arguments_w), self)
+except Return, nlr:
+s_new_frame = nlr.s_target_context
+nlr.s_target_context.push(nlr.value)
 if s_new_frame == None:
 # which means that we tried to call a primitive method
 return s_frame.pop()
@@ -125,6 +137,10 @@
 class StackOverflow(Exception):
 def __init__(self, s_top_context):
 self.s_context = s_top_context
+class Return(Exception):
+def __init__(self, object, s_context):
+self.value = object
+self.s_target_context = s_context
 
 def make_call_primitive_bytecode(primitive, selector, argcount):
 def callPrimitive(self, interp, current_bytecode):
@@ -281,11 +297,7 @@
 # unfortunately, the assert below is not true for some tests
 # assert self._stack_ptr == self.tempsize()
 
-# make this context a returned one
-self.mark_returned()
-
-s_return_to.push(return_value)
-return s_return_to
+raise Return(return_value, s_return_to)
 
 def returnReceiver(self, interp, current_bytecode):
 return self._return(self.w_receiver(), interp, 
self.s_home().s_sender())
@@ -695,7 +707,7 @@
 code.append("%sif %s:" % (prefix, cond, ))
 code.append("return context.%s(self, bytecode)" % (entry[-1], 
))
 prefix = "el"
-code.append("bytecode_step_translated._always_inline_ = True")
+# code.append("bytecode_step_translated._always_inline_ = True")
 source = py.code.Source("\n".join(code))
 #print source
 miniglob = {}
diff --git a/spyvm/test/test_interpreter.py b/spyvm/test/test_interpreter.py
--- a/spyvm/

[pypy-commit] lang-smalltalk default: (cfbolz, lwassermann): changed the version checker to test for 64bit images only on 64bit systems

2013-03-06 Thread lwassermann
Author: Lars Wassermann 
Branch: 
Changeset: r124:d6155cf750e0
Date: 2013-03-06 21:08 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/d6155cf750e0/

Log:(cfbolz, lwassermann): changed the version checker to test for 64bit
images only on 64bit systems

diff --git a/spyvm/squeakimage.py b/spyvm/squeakimage.py
--- a/spyvm/squeakimage.py
+++ b/spyvm/squeakimage.py
@@ -1,5 +1,6 @@
 import py
 import os
+import sys
 from spyvm import constants
 from spyvm import model
 from spyvm.tool.bitmanipulation import splitter
@@ -134,6 +135,10 @@
 0x1969: ImageVersion(6505,  True,  False, True,  True ),
 0x6919: ImageVersion(6505,  False, False, True,  True ),
 0x000109A0: ImageVersion(68000, True,  True,  False, False),
+}
+
+if sys.maxint == 2 ** 63 - 1:
+image_versions.update({
-0x5ff6ff00:
 # signed version of 0xA0090100: 
 ImageVersion(68000, False, True,  False, False),
@@ -145,7 +150,7 @@
-0x5cf6ff00:
 # signed version of 0xA3090100: 
ImageVersion(68003, False, True,  True,  True ),
-}
+})
 
 
 def version(magic):
diff --git a/spyvm/test/test_squeakimage.py b/spyvm/test/test_squeakimage.py
--- a/spyvm/test/test_squeakimage.py
+++ b/spyvm/test/test_squeakimage.py
@@ -184,6 +184,9 @@
 assert r.stream.pos == len(image_2)
 
 def test_simple_image64():
+import sys
+if not sys.maxint == 2 ** 63 - 1:
+  py.test.skip("on 32 bit platforms, we can't need to check for 64 bit 
images")
 word_size = 8
 header_size = 16 * word_size
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk default: removed the mark-variable by saving the needed information prior to calling c-loop

2013-03-06 Thread lwassermann
Author: Lars Wassermann 
Branch: 
Changeset: r122:ea61821e69dd
Date: 2013-03-06 21:03 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/ea61821e69dd/

Log:removed the mark-variable by saving the needed information prior to
calling c-loop

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -28,7 +28,7 @@
 _last_indent = ""
 jit_driver = jit.JitDriver(
 greens=['pc', 'self', 'method'],
-reds=['mark', 's_context'],
+reds=['s_context'],
 #virtualizables=['s_context'],
 get_printable_location=get_printable_location
 )
@@ -59,29 +59,31 @@
 self._loop = True
 s_new_context = w_active_context.as_context_get_shadow(self.space)
 while True:
+s_sender = s_new_context.s_sender()
 try:
-s_new_context = self.c_loop(s_new_context, mark=False)
+s_new_context = self.c_loop(s_new_context)
 except StackOverflow, e:
 self.remaining_stack_depth = self.max_stack_depth
 s_new_context = e.s_context
 except Return, nlr:
 while s_new_context is not nlr.s_target_context:
-s_new_context, _ = s_new_context.s_sender(), 
s_new_context.mark_returned()
+s_new_context.mark_returned()
+s_new_context = s_sender
 s_new_context.push(nlr.value)
 
-def c_loop(self, s_context, mark=True):
+def c_loop(self, s_context):
 while True:
 pc = s_context._pc
 method = s_context.s_method()
 
 self.jit_driver.jit_merge_point(
 pc=pc, self=self, method=method,
-mark=mark, s_context=s_context)
+s_context=s_context)
 try:
 self.step(s_context)
 except Return, nlr:
 if nlr.s_target_context is not s_context:
-if mark: s_context.mark_returned()
+s_context.mark_returned()
 raise nlr
 else:
 s_context.push(nlr.value)
@@ -707,7 +709,6 @@
 code.append("%sif %s:" % (prefix, cond, ))
 code.append("return context.%s(self, bytecode)" % (entry[-1], 
))
 prefix = "el"
-# code.append("bytecode_step_translated._always_inline_ = True")
 source = py.code.Source("\n".join(code))
 #print source
 miniglob = {}
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk default: (tfel, lwassermann): updated the targettinybenchsmalltalk to reflect the jit test changes needed because of interpreter restructuring

2013-03-06 Thread lwassermann
Author: Lars Wassermann 
Branch: 
Changeset: r125:2f7194263d4b
Date: 2013-03-06 21:10 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/2f7194263d4b/

Log:(tfel, lwassermann): updated the targettinybenchsmalltalk to reflect
the jit test changes needed because of interpreter restructuring

diff --git a/targettinybenchsmalltalk.py b/targettinybenchsmalltalk.py
--- a/targettinybenchsmalltalk.py
+++ b/targettinybenchsmalltalk.py
@@ -15,45 +15,27 @@
 # compile...
 sys.setrecursionlimit(10)
 
-
-def tinyBenchmarks():
+def setup():
 from spyvm import objspace
 space = objspace.ObjSpace()
 image = create_testimage(space)
-interp = interpreter.Interpreter(space)
+interp = interpreter.Interpreter(space, image)
+w_selector = interp.perform(space.wrap_string("loopTest"), "asSymbol")
+w_object = model.W_SmallInteger(0)
+s_class = w_object.shadow_of_my_class(space)
+s_method = s_class.lookup(w_selector)
+s_frame = s_method.create_frame(space, w_object, [])
+return interp, s_frame
 
-w_object = model.W_SmallInteger(0)
-
-s_class = w_object.shadow_of_my_class(space)
-w_method = s_class.lookup("loopTest")
-
-assert w_method
-w_frame = w_method.create_frame(space, w_object, [])
-interp.store_w_active_context(w_frame)
-
-counter = 0
-
-from spyvm.interpreter import BYTECODE_TABLE
-return interp
-
-
-interp = tinyBenchmarks()
-
+interp, s_frame = setup()
 
 def entry_point(argv):
-counter = 0
 try:
-while True:
-counter += 1
-interp.interpret()
-if counter == 10:
-counter = 0
-os.write(2, '#')
+interp.loop(s_frame.w_self())
 except interpreter.ReturnFromTopLevel, e:
 w_result = e.object
-
-assert isinstance(w_result, model.W_BytesObject)
-print w_result.as_string()
+assert isinstance(w_result, model.W_BytesObject)
+print w_result.as_string()
 return 0
 
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk default: (cfbolz, lwassermann): added attribute information to the model classes to prevent the typechecker from pulling variables up

2013-03-06 Thread lwassermann
Author: Lars Wassermann 
Branch: 
Changeset: r123:cb75ad6978de
Date: 2013-03-06 21:06 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/cb75ad6978de/

Log:(cfbolz, lwassermann): added attribute information to the model
classes to prevent the typechecker from pulling variables up In the
wake, added some assertions to pacify the typechecker

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -25,7 +25,8 @@
 
 class W_Object(object):
 """Root of Squeak model, abstract."""
-__slots__ = ()# no RPython-level instance variables allowed in W_Object
+_attrs_ = []# no RPython-level instance variables allowed in W_Object
+_settled_ = True
 
 def size(self):
 """Return bytesize that conforms to Blue Book.
@@ -112,6 +113,7 @@
 class W_SmallInteger(W_Object):
 """Boxed integer value"""
 # TODO can we tell pypy that its never larger then 31-bit?
+_attrs_ = ['value'] 
 __slots__ = ('value',) # the only allowed slot here
 _immutable_fields_ = ["value"]
 
@@ -152,6 +154,8 @@
 
 class W_Float(W_Object):
 """Boxed float value."""
+_attrs_ = ['value']
+
 def __init__(self, value):
 self.value = value
 
@@ -191,6 +195,8 @@
 class W_AbstractObjectWithIdentityHash(W_Object):
 """Object with explicit hash (ie all except small
 ints and floats)."""
+_attrs_ = ['hash']
+
 #XXX maybe this is too extreme, but it's very random
 hash_generator = rrandom.Random()
 UNASSIGNED_HASH = sys.maxint
@@ -215,6 +221,7 @@
 class W_AbstractObjectWithClassReference(W_AbstractObjectWithIdentityHash):
 """Objects with arbitrary class (ie not CompiledMethod, SmallInteger or
 Float)."""
+_attrs_ = ['w_class']
 
 def __init__(self, w_class):
 if w_class is not None: # it's None only for testing and space 
generation
@@ -251,6 +258,7 @@
 
 class W_PointersObject(W_AbstractObjectWithClassReference):
 """Common object."""
+_attrs_ = ['_shadow', '_vars']
 
 _shadow = None # Default value
 
@@ -371,6 +379,8 @@
 return w_result
 
 class W_BytesObject(W_AbstractObjectWithClassReference):
+_attrs_ = ['bytes']
+
 def __init__(self, w_class, size):
 W_AbstractObjectWithClassReference.__init__(self, w_class)
 assert isinstance(size, int)
@@ -421,6 +431,8 @@
 return w_result
 
 class W_WordsObject(W_AbstractObjectWithClassReference):
+_attrs_ = ['words']
+
 def __init__(self, w_class, size):
 W_AbstractObjectWithClassReference.__init__(self, w_class)
 self.words = [r_uint(0)] * size
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -298,12 +298,16 @@
 
 def attach_shadow(self):
 AbstractShadow.attach_shadow(self)
+w_self = self.w_self()
+assert isinstance(w_self, model.W_PointersObject)
 for i in range(self._w_self_size):
 self.copy_from_w_self(i)
-self.w_self()._vars = None
+w_self._vars = None
 
 def detach_shadow(self):
-self.w_self()._vars = [self.space.w_nil] * self._w_self_size
+w_self = self.w_self()
+assert isinstance(w_self, model.W_PointersObject)
+w_self._vars = [self.space.w_nil] * self._w_self_size
 for i in range(self._w_self_size):
 self.copy_to_w_self(i)
 
@@ -325,6 +329,7 @@
 def __init__(self, space, w_self):
 self._s_sender = None
 AbstractRedirectingShadow.__init__(self, space, w_self)
+self.instances_w = None
 
 @staticmethod
 def is_block_context(w_pointers, space):
diff --git a/spyvm/test/test_primitives.py b/spyvm/test/test_primitives.py
--- a/spyvm/test/test_primitives.py
+++ b/spyvm/test/test_primitives.py
@@ -492,24 +492,26 @@
 assert s_new_context.w_receiver() is space.w_nil
 
 def test_primitive_closure_value_value():
-s_initial_context, closure, s_new_context = 
build_up_closure_environment(["first arg", "second arg"])
+s_initial_context, closure, s_new_context = build_up_closure_environment([
+wrap("first arg"), wrap("second arg")])
 
 assert s_new_context.w_closure_or_nil is closure
 assert s_new_context.s_sender() is s_initial_context
 assert s_new_context.w_receiver() is space.w_nil
-assert s_new_context.gettemp(0) == "first arg"
-assert s_new_context.gettemp(1) == "second arg"
+assert s_new_context.gettemp(0).as_string() == "first arg"
+assert s_new_context.gettemp(1).as_string() == "second arg"
 
 def test_primitive_closure_value_value_with_temps():
-s_initial_context, closure, s_new_context = 
build_up_closure_environment(["first arg", "second arg"],
-copiedValues=['some value'])
+s_initial_context, closure, s_new_context = build_up_closure_environment(
+[wrap("first arg"), wrap("second arg")],
+copiedValues=[wrap('some value')])
 
 assert s_new_context.w_closure_or_nil 

[pypy-commit] lang-smalltalk default: removed the recursion increasing lines from the test-cases, because they cause segfaults

2013-03-06 Thread lwassermann
Author: Lars Wassermann 
Branch: 
Changeset: r126:c7a6275e8187
Date: 2013-03-06 21:11 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/c7a6275e8187/

Log:removed the recursion increasing lines from the test-cases, because
they cause segfaults

diff --git a/spyvm/test/jit.py b/spyvm/test/jit.py
--- a/spyvm/test/jit.py
+++ b/spyvm/test/jit.py
@@ -46,7 +46,7 @@
 # Tests
 #
 
-sys.setrecursionlimit(10)
+# sys.setrecursionlimit(10)
 
 class TestLLtype(LLJitMixin):
 
diff --git a/targettinybenchsmalltalk.py b/targettinybenchsmalltalk.py
--- a/targettinybenchsmalltalk.py
+++ b/targettinybenchsmalltalk.py
@@ -13,7 +13,7 @@
 # XXX this only compiles if sys.recursionlimit is high enough!
 # On non-Linux platforms I don't know if there is enough stack to
 # compile...
-sys.setrecursionlimit(10)
+#sys.setrecursionlimit(10)
 
 def setup():
 from spyvm import objspace
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk default: (cfbolz, lwassermann): Added type-checks in several places to pacify pypy. In most cases, the program will abort, if the wrong types are supplied.

2013-03-06 Thread lwassermann
Author: Lars Wassermann 
Branch: 
Changeset: r127:d0d2369575cf
Date: 2013-03-06 21:14 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/d0d2369575cf/

Log:(cfbolz, lwassermann): Added type-checks in several places to pacify
pypy. In most cases, the program will abort, if the wrong types are
supplied. The stack can now only contain model.W_Object-instances.
Generic shadows can now only exists for model.W_PointersObject.

diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -260,6 +260,10 @@
 elif isinstance(w_v, model.W_SmallInteger): return float(w_v.value)
 raise UnwrappingError()
 
+def unwrap_pointersobject(self, w_v):
+if not isinstance(w_v, model.W_PointersObject):
+raise UnwrappingError()
+return w_v
 def unwrap_array(self, w_array):
 # Check that our argument has pointers format and the class:
 if not w_array.getclass(self).is_same_object(self.w_Array):
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -93,6 +93,7 @@
 elif spec is float:
 args += (interp.space.unwrap_float(w_arg), )
 elif spec is object:
+assert isinstance(w_arg, model.W_Object)
 args += (w_arg, )
 elif spec is str:
 assert isinstance(w_arg, model.W_BytesObject)
@@ -963,7 +964,9 @@
 interp.space.w_Process):
 raise PrimitiveFailedError()
 s_frame.push(w_rcvr) # w_rcvr is the result in the old frame
-return wrapper.ProcessWrapper(interp.space, 
w_rcvr).resume(s_frame.w_self()).as_context_get_shadow(interp.space)
+w_frame = wrapper.ProcessWrapper(interp.space, 
w_rcvr).resume(s_frame.w_self())
+w_frame = interp.space.unwrap_pointersobject(w_frame)
+return w_frame.as_context_get_shadow(interp.space)
 
 @expose_primitive(SUSPEND, unwrap_spec=[object])
 def func(interp, s_frame, w_rcvr, result_is_new_frame=True):
@@ -972,7 +975,9 @@
 interp.space.w_Process):
 raise PrimitiveFailedError()
 s_frame.push(w_rcvr) # w_rcvr is the result in the old frame
-return wrapper.ProcessWrapper(interp.space, 
w_rcvr).suspend(s_frame.w_self()).as_context_get_shadow(interp.space)
+w_frame = wrapper.ProcessWrapper(interp.space, 
w_rcvr).suspend(s_frame.w_self())
+w_frame = interp.space.unwrap_pointersobject(w_frame)
+return w_frame.as_context_get_shadow(interp.space)
 
 @expose_primitive(FLUSH_CACHE, unwrap_spec=[object])
 def func(interp, s_frame, w_rcvr):
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -798,8 +798,10 @@
 def returnTopFromMethod(self, interp, current_bytecode):
 if self.is_closure_context():
 # this is a context for a blockClosure
-s_outerContext = self.w_closure_or_nil.fetch(self.space, 
-constants.BLKCLSR_OUTER_CONTEXT).get_shadow(self.space)
+w_outerContext = self.w_closure_or_nil.fetch(self.space, 
+constants.BLKCLSR_OUTER_CONTEXT)
+assert isinstance(w_outerContext, model.W_PointersObject)
+s_outerContext = w_outerContext.as_context_get_shadow(self.space)
 # XXX check whether we can actually return from that context
 if s_outerContext.pc() == -1:
 raise error.BlockCannotReturnError()
diff --git a/spyvm/wrapper.py b/spyvm/wrapper.py
--- a/spyvm/wrapper.py
+++ b/spyvm/wrapper.py
@@ -226,7 +226,10 @@
 
 def asContextWithSender(self, w_aContext, arguments):
 from spyvm import shadow
-s_outerContext = self.outerContext().get_shadow(self.space)
+w_outerContext = self.outerContext()
+if not isinstance(w_outerContext, model.W_PointersObject):
+raise PrimitiveFailedError
+s_outerContext = w_outerContext.as_context_get_shadow(self.space)
 s_method = 
s_outerContext.w_method().as_compiledmethod_get_shadow(self.space)
 w_receiver = s_outerContext.w_receiver()
 w_new_frame = shadow.MethodContextShadow.make_context(self.space, 
s_method, w_receiver,
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: cleanup _sqlite3.Statement

2013-03-06 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r62133:45bbcccf99e5
Date: 2013-03-06 15:25 -0500
http://bitbucket.org/pypy/pypy/changeset/45bbcccf99e5/

Log:cleanup _sqlite3.Statement

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -237,8 +237,6 @@
 sqlite.sqlite3_enable_load_extension.argtypes = [c_void_p, c_int]
 sqlite.sqlite3_enable_load_extension.restype = c_int
 
-_DML, _DQL, _DDL = range(3)
-
 ##
 # END Wrapped SQLite C API and constants
 ##
@@ -302,9 +300,9 @@
 if len(self.cache) > self.maxcount:
 self.cache.popitem(0)
 
-if stat.in_use:
+if stat._in_use:
 stat = Statement(self.connection, sql)
-stat.set_row_factory(row_factory)
+stat._row_factory = row_factory
 return stat
 
 
@@ -363,7 +361,7 @@
 for statement in self.__statements:
 obj = statement()
 if obj is not None:
-obj.finalize()
+obj._finalize()
 
 if self._db:
 ret = sqlite.sqlite3_close(self._db)
@@ -496,7 +494,7 @@
 for statement in self.__statements:
 obj = statement()
 if obj is not None:
-obj.reset()
+obj._reset()
 
 statement = c_void_p()
 next_char = c_char_p()
@@ -521,7 +519,7 @@
 for statement in self.__statements:
 obj = statement()
 if obj is not None:
-obj.reset()
+obj._reset()
 
 for cursor_ref in self._cursors:
 cursor = cursor_ref()
@@ -771,13 +769,13 @@
 except ValueError:
 pass
 if self.__statement:
-self.__statement.reset()
+self.__statement._reset()
 
 def close(self):
 self.__connection._check_thread()
 self.__connection._check_closed()
 if self.__statement:
-self.__statement.reset()
+self.__statement._reset()
 self.__statement = None
 self.__closed = True
 
@@ -808,35 +806,35 @@
 sql, self.row_factory)
 
 if self.__connection._isolation_level is not None:
-if self.__statement.kind == _DDL:
+if self.__statement._kind == Statement._DDL:
 if self.__connection._in_transaction:
 self.__connection.commit()
-elif self.__statement.kind == _DML:
+elif self.__statement._kind == Statement._DML:
 if not self.__connection._in_transaction:
 self.__connection._begin()
 
-self.__statement.set_params(params)
+self.__statement._set_params(params)
 
 # Actually execute the SQL statement
-ret = sqlite.sqlite3_step(self.__statement.statement)
+ret = sqlite.sqlite3_step(self.__statement._statement)
 if ret not in (SQLITE_DONE, SQLITE_ROW):
-self.__statement.reset()
+self.__statement._reset()
 self.__connection._in_transaction = \
 not 
sqlite.sqlite3_get_autocommit(self.__connection._db)
 raise self.__connection._get_exception(ret)
 
-if self.__statement.kind == _DML:
-self.__statement.reset()
+if self.__statement._kind == Statement._DML:
+self.__statement._reset()
 
-if self.__statement.kind == _DQL and ret == SQLITE_ROW:
+if self.__statement._kind == Statement._DQL and ret == SQLITE_ROW:
 self.__statement._build_row_cast_map()
 self.__statement._readahead(self)
 else:
-self.__statement.item = None
-self.__statement.exhausted = True
+self.__statement._item = None
+self.__statement._exhausted = True
 
 self.__rowcount = -1
-if self.__statement.kind == _DML:
+if self.__statement._kind == Statement._DML:
 self.__rowcount = sqlite.sqlite3_changes(self.__connection._db)
 finally:
 self.__locked = False
@@ -852,7 +850,7 @@
 self.__statement = self.__connection._statement_cache.get(
 sql, self.row_factory)
 
-if self.__statement.kind == _DML:
+if self.__statement._kind == Statement._DML:
 if self.__connection._isolation_level is not None:
 if not self.__connection._in_transaction:
 self.__connection._begin()
@@ -861,15 +859,15 @@
 
 self.__rowcount = 0
 for params in many_params:
-self.__statement.set_params(params)
-ret = sqlite.sqlite3_step(self.__statement.statement)
+sel

[pypy-commit] pypy py3k: merge default

2013-03-06 Thread bdkearns
Author: Brian Kearns 
Branch: py3k
Changeset: r62134:36a3c5c18e36
Date: 2013-03-06 15:35 -0500
http://bitbucket.org/pypy/pypy/changeset/36a3c5c18e36/

Log:merge default

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -244,8 +244,6 @@
 sqlite.sqlite3_enable_load_extension.argtypes = [c_void_p, c_int]
 sqlite.sqlite3_enable_load_extension.restype = c_int
 
-_DML, _DQL, _DDL = range(3)
-
 ##
 # END Wrapped SQLite C API and constants
 ##
@@ -306,9 +304,9 @@
 if len(self.cache) > self.maxcount:
 self.cache.popitem(0)
 
-if stat.in_use:
+if stat._in_use:
 stat = Statement(self.connection, sql)
-stat.set_row_factory(row_factory)
+stat._row_factory = row_factory
 return stat
 
 
@@ -367,7 +365,7 @@
 for statement in self.__statements:
 obj = statement()
 if obj is not None:
-obj.finalize()
+obj._finalize()
 
 if self._db:
 ret = sqlite.sqlite3_close(self._db)
@@ -501,7 +499,7 @@
 for statement in self.__statements:
 obj = statement()
 if obj is not None:
-obj.reset()
+obj._reset()
 
 statement = c_void_p()
 next_char = c_char_p()
@@ -526,7 +524,7 @@
 for statement in self.__statements:
 obj = statement()
 if obj is not None:
-obj.reset()
+obj._reset()
 
 for cursor_ref in self._cursors:
 cursor = cursor_ref()
@@ -778,13 +776,13 @@
 except ValueError:
 pass
 if self.__statement:
-self.__statement.reset()
+self.__statement._reset()
 
 def close(self):
 self.__connection._check_thread()
 self.__connection._check_closed()
 if self.__statement:
-self.__statement.reset()
+self.__statement._reset()
 self.__statement = None
 self.__closed = True
 
@@ -798,8 +796,15 @@
 self.__connection._check_thread()
 self.__connection._check_closed()
 
+def __check_cursor_wrap(func):
+@wraps(func)
+def wrapper(self, *args, **kwargs):
+self.__check_cursor()
+return func(self, *args, **kwargs)
+return wrapper
+
+@__check_cursor_wrap
 def execute(self, sql, params=None):
-self.__check_cursor()
 self.__locked = True
 try:
 self.__description = None
@@ -808,43 +813,43 @@
 sql, self.row_factory)
 
 if self.__connection._isolation_level is not None:
-if self.__statement.kind == _DDL:
+if self.__statement._kind == Statement._DDL:
 if self.__connection._in_transaction:
 self.__connection.commit()
-elif self.__statement.kind == _DML:
+elif self.__statement._kind == Statement._DML:
 if not self.__connection._in_transaction:
 self.__connection._begin()
 
-self.__statement.set_params(params)
+self.__statement._set_params(params)
 
 # Actually execute the SQL statement
-ret = sqlite.sqlite3_step(self.__statement.statement)
+ret = sqlite.sqlite3_step(self.__statement._statement)
 if ret not in (SQLITE_DONE, SQLITE_ROW):
-self.__statement.reset()
+self.__statement._reset()
 self.__connection._in_transaction = \
 not 
sqlite.sqlite3_get_autocommit(self.__connection._db)
 raise self.__connection._get_exception(ret)
 
-if self.__statement.kind == _DML:
-self.__statement.reset()
+if self.__statement._kind == Statement._DML:
+self.__statement._reset()
 
-if self.__statement.kind == _DQL and ret == SQLITE_ROW:
+if self.__statement._kind == Statement._DQL and ret == SQLITE_ROW:
 self.__statement._build_row_cast_map()
 self.__statement._readahead(self)
 else:
-self.__statement.item = None
-self.__statement.exhausted = True
+self.__statement._item = None
+self.__statement._exhausted = True
 
 self.__rowcount = -1
-if self.__statement.kind == _DML:
+if self.__statement._kind == Statement._DML:
 self.__rowcount = sqlite.sqlite3_changes(self.__connection._db)
 finally:
 self.__locked = False
 
 return self
 
+@__check_cursor_wrap
 def executemany(self, sql, many_params):
-self.__check_cursor()
 self.__locked = True
 tr

[pypy-commit] pypy default: redundant call to encode

2013-03-06 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r62135:5b25d91f1f35
Date: 2013-03-06 15:40 -0500
http://bitbucket.org/pypy/pypy/changeset/5b25d91f1f35/

Log:redundant call to encode

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -985,9 +985,7 @@
 def __init__(self, connection, sql):
 self.__con = connection
 
-if isinstance(sql, unicode):
-sql = sql.encode('utf-8')
-elif not isinstance(sql, str):
+if not isinstance(sql, str):
 raise ValueError("sql must be a string")
 first_word = self._statement_kind = sql.lstrip().split(" ")[0].upper()
 if first_word in ("INSERT", "UPDATE", "DELETE", "REPLACE"):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: fix

2013-03-06 Thread fijal
Author: Maciej Fijalkowski 
Branch: jitframe-on-heap
Changeset: r62136:1acd1abdb117
Date: 2013-03-06 22:53 +0200
http://bitbucket.org/pypy/pypy/changeset/1acd1abdb117/

Log:fix

diff --git a/rpython/jit/backend/arm/assembler.py 
b/rpython/jit/backend/arm/assembler.py
--- a/rpython/jit/backend/arm/assembler.py
+++ b/rpython/jit/backend/arm/assembler.py
@@ -805,12 +805,11 @@
 #
 mc.BL(self.cpu.realloc_frame)
 
-# set fp to the new jitframe
-mc.MOV_rr(r.fp.value, r.r0.value)
-
 # restore a possibly present exception
 self._restore_exception(mc, None, r.fp)
 
+# set fp to the new jitframe
+mc.MOV_rr(r.fp.value, r.r0.value)
 
 gcrootmap = self.cpu.gc_ll_descr.gcrootmap
 if gcrootmap and gcrootmap.is_shadow_stack:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk default: Added class attribute information to the ContextPartShadow class-chain.

2013-03-06 Thread lwassermann
Author: Lars Wassermann 
Branch: 
Changeset: r128:0e0ba48f9e2a
Date: 2013-03-06 21:54 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/0e0ba48f9e2a/

Log:Added class attribute information to the ContextPartShadow class-
chain. Renamed _w_method to __w_method to circumvent outside access
from an unknown place. Unfortunately, the maximum recursion depth
circumvents any attempts to see whether the system broke.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -29,7 +29,7 @@
 jit_driver = jit.JitDriver(
 greens=['pc', 'self', 'method'],
 reds=['s_context'],
-#virtualizables=['s_context'],
+virtualizables=['s_context'],
 get_printable_location=get_printable_location
 )
 
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -7,6 +7,8 @@
 """A shadow is an optional extra bit of information that
 can be attached at run-time to any Smalltalk object.
 """
+_attr_ = ['_w_self']
+
 def __init__(self, space, w_self):
 self.space = space
 self._w_self = w_self
@@ -25,6 +27,8 @@
 def sync_shadow(self): pass

 class AbstractCachingShadow(AbstractShadow):
+_attr_ = []
+
 def __init__(self, space, w_self):
 AbstractShadow.__init__(self, space, w_self)
 
@@ -282,6 +286,8 @@
 
 
 class AbstractRedirectingShadow(AbstractShadow):
+_attr_ = ['_w_self_size']
+
 def __init__(self, space, w_self):
 AbstractShadow.__init__(self, space, w_self)
 if w_self is not None:
@@ -319,12 +325,14 @@
 class ContextPartShadow(AbstractRedirectingShadow):
 
 __metaclass__ = extendabletype
+_attr_ = ['_s_sender', '_pc', '_temps_and_stack', 
+'_stack_ptr', 'instances_w']
 
-# _virtualizable2_ = [
-# "_s_sender", "_pc",
-# "_temps_and_stack[*]", "_stack_ptr",
-# "_w_self", "_w_self_size"
-# ]
+_virtualizable2_ = [
+"_s_sender", "_pc",
+"_temps_and_stack[*]", "_stack_ptr",
+"_w_self", "_w_self_size"
+]
 
 def __init__(self, space, w_self):
 self._s_sender = None
@@ -464,7 +472,9 @@
 # Method that contains the bytecode for this method/block context
 
 def w_method(self):
-return self.s_home().w_method()
+retval = self.s_home().w_method()
+assert isinstance(retval, model.W_CompiledMethod)
+return retval
 
 def s_method(self):
 w_method = jit.promote(self.w_method())
@@ -585,6 +595,7 @@
 
 
 class BlockContextShadow(ContextPartShadow):
+_attr_ = ['_w_home', '_initialip', '_eargc']
 
 @staticmethod
 def make_context(space, w_home, s_sender, argcnt, initialip):
@@ -679,11 +690,12 @@
 return 0
 
 class MethodContextShadow(ContextPartShadow):
-
+_attr_ = ['w_closure_or_nil', '_w_receiver', '__w_method']
 
 def __init__(self, space, w_self):
 self.w_closure_or_nil = space.w_nil
-self._w_receiver = None
+self._w_receiver = space.w_nil
+self.__w_method = None
 ContextPartShadow.__init__(self, space, w_self)
 
 @staticmethod
@@ -761,11 +773,13 @@
 self.w_closure_or_nil).tempsize()
 
 def w_method(self):
-return self._w_method
+retval = self.__w_method
+assert isinstance(retval, model.W_CompiledMethod)
+return retval
 
 def store_w_method(self, w_method):
 assert isinstance(w_method, model.W_CompiledMethod)
-self._w_method = w_method
+self.__w_method = w_method
 
 def w_receiver(self):
 return self._w_receiver
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: disable the debug

2013-03-06 Thread fijal
Author: Maciej Fijalkowski 
Branch: jitframe-on-heap
Changeset: r62137:523baa10ad2f
Date: 2013-03-06 22:55 +0200
http://bitbucket.org/pypy/pypy/changeset/523baa10ad2f/

Log:disable the debug

diff --git a/rpython/jit/backend/x86/assembler.py 
b/rpython/jit/backend/x86/assembler.py
--- a/rpython/jit/backend/x86/assembler.py
+++ b/rpython/jit/backend/x86/assembler.py
@@ -51,7 +51,7 @@
 _output_loop_log = None
 _second_tmp_reg = ecx
 
-DEBUG_FRAME_DEPTH = True
+DEBUG_FRAME_DEPTH = False
 
 def __init__(self, cpu, translate_support_code=False):
 BaseAssembler.__init__(self, cpu, translate_support_code)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: this guy can go away (a better version is in llsupport)

2013-03-06 Thread fijal
Author: Maciej Fijalkowski 
Branch: jitframe-on-heap
Changeset: r62138:46ce7f2e3cb9
Date: 2013-03-06 23:00 +0200
http://bitbucket.org/pypy/pypy/changeset/46ce7f2e3cb9/

Log:this guy can go away (a better version is in llsupport)

diff --git a/rpython/jit/backend/arm/test/test_gc_integration.py 
b/rpython/jit/backend/arm/test/test_gc_integration.py
deleted file mode 100644
--- a/rpython/jit/backend/arm/test/test_gc_integration.py
+++ /dev/null
@@ -1,207 +0,0 @@
-
-""" Tests for register allocation for common constructs
-"""
-
-from rpython.jit.metainterp.history import TargetToken
-from rpython.jit.backend.llsupport.gc import GcLLDescription, GcLLDescr_boehm
-from rpython.jit.backend.detect_cpu import getcpuclass
-from rpython.jit.backend.arm.arch import WORD
-from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
-
-from rpython.jit.backend.arm.test.test_regalloc import BaseTestRegalloc
-
-CPU = getcpuclass()
-
-
-class MockGcRootMap(object):
-is_shadow_stack = False
-
-def get_basic_shape(self, is_64_bit):
-return ['shape']
-
-def add_frame_offset(self, shape, offset):
-shape.append(offset)
-
-def add_callee_save_reg(self, shape, reg_index):
-index_to_name = {1: 'ebx', 2: 'esi', 3: 'edi'}
-shape.append(index_to_name[reg_index])
-
-def compress_callshape(self, shape, datablockwrapper):
-assert datablockwrapper == 'fakedatablockwrapper'
-assert shape[0] == 'shape'
-return ['compressed'] + shape[1:]
-
-
-class MockGcDescr(GcLLDescr_boehm):
-gcrootmap = MockGcRootMap()
-
-
-class TestRegallocGcIntegration(BaseTestRegalloc):
-
-cpu = CPU(None, None)
-cpu.gc_ll_descr = MockGcDescr(None, None, None)
-cpu.setup_once()
-
-S = lltype.GcForwardReference()
-S.become(lltype.GcStruct('S', ('field', lltype.Ptr(S)),
- ('int', lltype.Signed)))
-
-fielddescr = cpu.fielddescrof(S, 'field')
-
-struct_ptr = lltype.malloc(S)
-struct_ref = lltype.cast_opaque_ptr(llmemory.GCREF, struct_ptr)
-child_ptr = lltype.nullptr(S)
-struct_ptr.field = child_ptr
-
-
-descr0 = cpu.fielddescrof(S, 'int')
-ptr0 = struct_ref
-targettoken = TargetToken()
-
-namespace = locals().copy()
-
-def test_basic(self):
-ops = '''
-[p0]
-p1 = getfield_gc(p0, descr=fielddescr)
-finish(p1)
-'''
-self.interpret(ops, [self.struct_ptr])
-assert not self.getptr(0, lltype.Ptr(self.S))
-
-def test_rewrite_constptr(self):
-ops = '''
-[]
-p1 = getfield_gc(ConstPtr(struct_ref), descr=fielddescr)
-finish(p1)
-'''
-self.interpret(ops, [])
-assert not self.getptr(0, lltype.Ptr(self.S))
-
-def test_bug_0(self):
-ops = '''
-[i0, i1, i2, i3, i4, i5, i6, i7, i8]
-label(i0, i1, i2, i3, i4, i5, i6, i7, i8, descr=targettoken)
-guard_value(i2, 1) [i2, i3, i4, i5, i6, i7, i0, i1, i8]
-guard_class(i4, 138998336) [i4, i5, i6, i7, i0, i1, i8]
-i11 = getfield_gc(i4, descr=descr0)
-guard_nonnull(i11) [i4, i5, i6, i7, i0, i1, i11, i8]
-i13 = getfield_gc(i11, descr=descr0)
-guard_isnull(i13) [i4, i5, i6, i7, i0, i1, i11, i8]
-i15 = getfield_gc(i4, descr=descr0)
-i17 = int_lt(i15, 0)
-guard_false(i17) [i4, i5, i6, i7, i0, i1, i11, i15, i8]
-i18 = getfield_gc(i11, descr=descr0)
-i19 = int_ge(i15, i18)
-guard_false(i19) [i4, i5, i6, i7, i0, i1, i11, i15, i8]
-i20 = int_lt(i15, 0)
-guard_false(i20) [i4, i5, i6, i7, i0, i1, i11, i15, i8]
-i21 = getfield_gc(i11, descr=descr0)
-i22 = getfield_gc(i11, descr=descr0)
-i23 = int_mul(i15, i22)
-i24 = int_add(i21, i23)
-i25 = getfield_gc(i4, descr=descr0)
-i27 = int_add(i25, 1)
-setfield_gc(i4, i27, descr=descr0)
-i29 = getfield_raw(144839744, descr=descr0)
-i31 = int_and(i29, -2141192192)
-i32 = int_is_true(i31)
-guard_false(i32) [i4, i6, i7, i0, i1, i24]
-i33 = getfield_gc(i0, descr=descr0)
-guard_value(i33, ConstPtr(ptr0)) [i4, i6, i7, i0, i1, i33, i24]
-jump(i0, i1, 1, 17, i4, ConstPtr(ptr0), i6, i7, i24, descr=targettoken)
-'''
-self.interpret(ops, [0, 0, 0, 0, 0, 0, 0, 0, 0], run=False)
-
-NOT_INITIALIZED = chr(0xdd)
-
-class GCDescrFastpathMalloc(GcLLDescription):
-gcrootmap = None
-write_barrier_descr = None
-
-def __init__(self):
-GcLLDescription.__init__(self, None)
-# create a nursery
-NTP = rffi.CArray(lltype.Char)
-self.nursery = lltype.malloc(NTP, 64, flavor='raw')
-for i in range(64):
-self.nursery[i] = NOT_INITIALIZED
-self.addrs = lltype.malloc(rffi.CArray(lltype.Signed), 2,
-   flavor='raw')
-self.addrs[0] = rffi.cast(lltype.Signed, self.nursery)
-self

[pypy-commit] pypy jitframe-on-heap: fix imporrt

2013-03-06 Thread fijal
Author: Maciej Fijalkowski 
Branch: jitframe-on-heap
Changeset: r62139:b6e3c93df3fd
Date: 2013-03-06 23:06 +0200
http://bitbucket.org/pypy/pypy/changeset/b6e3c93df3fd/

Log:fix imporrt

diff --git a/rpython/jit/backend/arm/test/test_trace_operations.py 
b/rpython/jit/backend/arm/test/test_trace_operations.py
--- a/rpython/jit/backend/arm/test/test_trace_operations.py
+++ b/rpython/jit/backend/arm/test/test_trace_operations.py
@@ -1,4 +1,4 @@
-from rpython.jit.backend.x86.test.test_regalloc import BaseTestRegalloc
+from rpython.jit.backend.llsupport.test.test_regalloc_integration import 
BaseTestRegalloc
 from rpython.jit.backend.detect_cpu import getcpuclass
 from rpython.rtyper.lltypesystem import lltype, llmemory
 CPU = getcpuclass()
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: another fix

2013-03-06 Thread fijal
Author: Maciej Fijalkowski 
Branch: jitframe-on-heap
Changeset: r62140:20c676368ee9
Date: 2013-03-06 23:12 +0200
http://bitbucket.org/pypy/pypy/changeset/20c676368ee9/

Log:another fix

diff --git a/rpython/jit/backend/arm/test/test_assembler.py 
b/rpython/jit/backend/arm/test/test_assembler.py
--- a/rpython/jit/backend/arm/test/test_assembler.py
+++ b/rpython/jit/backend/arm/test/test_assembler.py
@@ -24,7 +24,7 @@
 clt = CompiledLoopToken(cpu, 0)
 clt.allgcrefs = []
 token.compiled_loop_token = clt
-self.a.setup(token, [])
+self.a.setup(token)
 
 def test_make_operation_list(self):
 i = rop.INT_ADD
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy missing-os-functions: Use platform.configure() to detect the presence of most posix functions.

2013-03-06 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: missing-os-functions
Changeset: r62141:873c7be6cbfe
Date: 2013-03-06 22:28 +0100
http://bitbucket.org/pypy/pypy/changeset/873c7be6cbfe/

Log:Use platform.configure() to detect the presence of most posix
functions.

The posix module now relies on these HAVE_XXX instead of the host
Python running the translation.

diff --git a/pypy/module/posix/__init__.py b/pypy/module/posix/__init__.py
--- a/pypy/module/posix/__init__.py
+++ b/pypy/module/posix/__init__.py
@@ -73,6 +73,7 @@
 'access': 'interp_posix.access',
 'times' : 'interp_posix.times',
 'system': 'interp_posix.system',
+'getpid': 'interp_posix.getpid',
 'unlink': 'interp_posix.unlink',
 'remove': 'interp_posix.remove',
 'getcwd': 'interp_posix.getcwd',
@@ -84,7 +85,6 @@
 'listdir'   : 'interp_posix.listdir',
 'strerror'  : 'interp_posix.strerror',
 'pipe'  : 'interp_posix.pipe',
-'chmod' : 'interp_posix.chmod',
 'rename': 'interp_posix.rename',
 'umask' : 'interp_posix.umask',
 '_exit' : 'interp_posix._exit',
@@ -95,25 +95,33 @@
 'urandom'   : 'interp_posix.urandom',
 }
 
+# XXX Missing functions: chflags lchmod lchflags ctermid fork1
+#plock setgroups initgroups tcgetpgrp
+#tcsetpgrp confstr pathconf
+
 for name in '''
-wait wait3 wait4 chown lchown ftruncate
-fsync fdatasync fchdir putenv unsetenv killpg getpid
-link symlink readlink
-fork openpty forkpty waitpid execv execve uname sysconf fpathconf
-ttyname getloadavg makedev major minor mkfifo mknod nice getlogin
+ttyname chmod fchmod chown lchown fchown chroot link symlink 
readlink
+ftruncate getloadavg nice uname execv execve fork spawnv spawnve
+putenv unsetenv fchdir fsync fdatasync mknod
+openpty forkpty mkfifo getlogin sysconf fpathconf
 getsid getuid geteuid getgid getegid getpgrp getpgid
 setsid setuid seteuid setgid setegid setpgrp setpgid
-getppid getgroups setreuid setregid chroot
-_getfullpathname
+getppid getgroups setreuid setregid
+wait wait3 wait4 killpg waitpid
 '''.split():
-if hasattr(posix, name):
+symbol = 'HAVE_' + name.upper()
+if getattr(rposix, symbol):
 interpleveldefs[name] = 'interp_posix.%s' % (name,)
 
-for name in '''fchmod fchown
-'''.split():
-symbol = 'HAS_' + name.upper()
-if getattr(rposix, symbol):
-interpleveldefs[name] = 'interp_posix.%s' % (name,)
+if rposix.HAVE_DEVICE_MACROS:
+interpleveldefs['major']   = 'interp_posix.major'
+interpleveldefs['minor']   = 'interp_posix.minor'
+interpleveldefs['makedev'] = 'interp_posix.makedev'
+
+if os.name == 'nt':
+interpleveldefs['_getfullpathname'] = 'interp_posix._getfullpathname'
+# On Windows, _cwait() can be used to emulate waitpid
+interpleveldefs['waitpid'] = 'interp_posix.waitpid'
 
 for constant in '''
 F_OK R_OK W_OK X_OK NGROUPS_MAX TMP_MAX
@@ -138,6 +146,7 @@
 interpleveldefs['pathconf_names'] = 'space.wrap(os.pathconf_names)'
 
 # Macros for process exit statuses: WIFEXITED &co
+# XXX HAVE_SYS_WAIT_H
 for name in RegisterOs.w_star:
 if hasattr(posix, name):
 interpleveldefs[name] = 'interp_posix.' + name
diff --git a/pypy/module/posix/test/test_posix2.py 
b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -63,25 +63,26 @@
 except UnicodeDecodeError:
 # filesystem encoding is not good enough
 cls.w_unicode_dir = space.w_None
-if hasattr(os, 'getuid'):
+if rposix.HAVE_GETUID:
 cls.w_getuid = space.wrap(os.getuid())
+if rposix.HAVE_GETEUID:
 cls.w_geteuid = space.wrap(os.geteuid())
-if hasattr(os, 'getgid'):
+if rposix.HAVE_GETGID:
 cls.w_getgid = space.wrap(os.getgid())
-if hasattr(os, 'getgroups'):
+if rposix.HAVE_GETGROUPS:
 cls.w_getgroups = space.newlist([space.wrap(e) for e in 
os.getgroups()])
-if hasattr(os, 'getpgid'):
+if rposix.HAVE_GETPGID:
 cls.w_getpgid = space.wrap(os.getpgid(os.getpid()))
-if hasattr(os, 'getsid'):
+if rposix.HAVE_GETSID:
 cls.w_getsid0 = space.wrap(os.getsid(0))
-if hasattr(os, 'sysconf'):
+if rposix.HAVE_SYSCONF:
 sysconf_name = os.sysconf_names.keys()[0]
 cls.w_sysconf_name = space.wrap(sysconf_name)
 cls.w_sysconf_value = space.wrap(os.sysconf_names[sysconf_name])
  

[pypy-commit] pypy default: cleanup _sqlite3.Statement.set_params

2013-03-06 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r62142:42054fe35ff6
Date: 2013-03-06 16:29 -0500
http://bitbucket.org/pypy/pypy/changeset/42054fe35ff6/

Log:cleanup _sqlite3.Statement.set_params

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -797,7 +797,7 @@
 return wrapper
 
 @__check_cursor_wrap
-def execute(self, sql, params=None):
+def execute(self, sql, params=[]):
 self.__locked = True
 try:
 self.__description = None
@@ -1102,34 +1102,30 @@
 raise self.__con._get_exception(ret)
 self._in_use = True
 
-if params is None:
-if sqlite.sqlite3_bind_parameter_count(self._statement) != 0:
-raise ProgrammingError("wrong number of arguments")
-return
-
-params_type = None
-if isinstance(params, dict):
-params_type = dict
+num_params_needed = 
sqlite.sqlite3_bind_parameter_count(self._statement)
+if not isinstance(params, dict):
+num_params = len(params)
+if num_params != num_params_needed:
+raise ProgrammingError("Incorrect number of bindings supplied. 
"
+   "The current statement uses %d, and "
+   "there are %d supplied." %
+   (num_params_needed, num_params))
+for i in range(num_params):
+self.__set_param(i + 1, params[i])
 else:
-params_type = list
-
-if params_type == list:
-if len(params) != 
sqlite.sqlite3_bind_parameter_count(self._statement):
-raise ProgrammingError("wrong number of arguments")
-
-for i in range(len(params)):
-self.__set_param(i+1, params[i])
-else:
-for idx in range(1, 
sqlite.sqlite3_bind_parameter_count(self._statement) + 1):
-param_name = 
sqlite.sqlite3_bind_parameter_name(self._statement, idx)
+for i in range(1, num_params_needed + 1):
+param_name = 
sqlite.sqlite3_bind_parameter_name(self._statement, i)
 if param_name is None:
-raise ProgrammingError("need named parameters")
+raise ProgrammingError("Binding %d has no name, but you "
+   "supplied a dictionary (which has "
+   "only names)." % i)
 param_name = param_name[1:]
 try:
 param = params[param_name]
 except KeyError:
-raise ProgrammingError("missing parameter '%s'" % param)
-self.__set_param(idx, param)
+raise ProgrammingError("You did not supply a value for "
+   "binding %d." % i)
+self.__set_param(i, param)
 
 def _next(self, cursor):
 self.__con._check_closed()
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: merge default

2013-03-06 Thread bdkearns
Author: Brian Kearns 
Branch: py3k
Changeset: r62143:f4c340c0fdad
Date: 2013-03-06 16:31 -0500
http://bitbucket.org/pypy/pypy/changeset/f4c340c0fdad/

Log:merge default

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -804,7 +804,7 @@
 return wrapper
 
 @__check_cursor_wrap
-def execute(self, sql, params=None):
+def execute(self, sql, params=[]):
 self.__locked = True
 try:
 self.__description = None
@@ -1099,34 +1099,30 @@
 raise self.__con._get_exception(ret)
 self._in_use = True
 
-if params is None:
-if sqlite.sqlite3_bind_parameter_count(self._statement) != 0:
-raise ProgrammingError("wrong number of arguments")
-return
-
-params_type = None
-if isinstance(params, dict):
-params_type = dict
+num_params_needed = 
sqlite.sqlite3_bind_parameter_count(self._statement)
+if not isinstance(params, dict):
+num_params = len(params)
+if num_params != num_params_needed:
+raise ProgrammingError("Incorrect number of bindings supplied. 
"
+   "The current statement uses %d, and "
+   "there are %d supplied." %
+   (num_params_needed, num_params))
+for i in range(num_params):
+self.__set_param(i + 1, params[i])
 else:
-params_type = list
-
-if params_type == list:
-if len(params) != 
sqlite.sqlite3_bind_parameter_count(self._statement):
-raise ProgrammingError("wrong number of arguments")
-
-for i in range(len(params)):
-self.__set_param(i+1, params[i])
-else:
-for idx in range(1, 
sqlite.sqlite3_bind_parameter_count(self._statement) + 1):
-param_name = 
sqlite.sqlite3_bind_parameter_name(self._statement, idx)
+for i in range(1, num_params_needed + 1):
+param_name = 
sqlite.sqlite3_bind_parameter_name(self._statement, i)
 if param_name is None:
-raise ProgrammingError("need named parameters")
+raise ProgrammingError("Binding %d has no name, but you "
+   "supplied a dictionary (which has "
+   "only names)." % i)
 param_name = param_name[1:].decode('utf-8')
 try:
 param = params[param_name]
 except KeyError:
-raise ProgrammingError("missing parameter %r" % param_name)
-self.__set_param(idx, param)
+raise ProgrammingError("You did not supply a value for "
+   "binding %d." % i)
+self.__set_param(i, param)
 
 def _next(self, cursor):
 self.__con._check_closed()
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: more small cleanups for sqlite

2013-03-06 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r62144:a511e6de3ae1
Date: 2013-03-06 16:45 -0500
http://bitbucket.org/pypy/pypy/changeset/a511e6de3ae1/

Log:more small cleanups for sqlite

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -741,7 +741,6 @@
 
 class Cursor(object):
 __initialized = False
-__connection = None
 __statement = None
 
 def __init__(self, con):
@@ -763,11 +762,10 @@
 self.__rowcount = -1
 
 def __del__(self):
-if self.__connection:
-try:
-self.__connection._cursors.remove(weakref.ref(self))
-except ValueError:
-pass
+try:
+self.__connection._cursors.remove(weakref.ref(self))
+except (AttributeError, ValueError):
+pass
 if self.__statement:
 self.__statement._reset()
 
@@ -866,8 +864,8 @@
 self.__connection._in_transaction = \
 not 
sqlite.sqlite3_get_autocommit(self.__connection._db)
 raise self.__connection._get_exception(ret)
+self.__statement._reset()
 self.__rowcount += 
sqlite.sqlite3_changes(self.__connection._db)
-self.__statement._reset()
 finally:
 self.__locked = False
 
@@ -1097,9 +1095,6 @@
  str(type(param)))
 
 def _set_params(self, params):
-ret = sqlite.sqlite3_reset(self._statement)
-if ret != SQLITE_OK:
-raise self.__con._get_exception(ret)
 self._in_use = True
 
 num_params_needed = 
sqlite.sqlite3_bind_parameter_count(self._statement)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: try to write a better test

2013-03-06 Thread fijal
Author: Maciej Fijalkowski 
Branch: jitframe-on-heap
Changeset: r62145:11b4e036be3e
Date: 2013-03-06 23:52 +0200
http://bitbucket.org/pypy/pypy/changeset/11b4e036be3e/

Log:try to write a better test

diff --git a/rpython/jit/backend/arm/runner.py 
b/rpython/jit/backend/arm/runner.py
--- a/rpython/jit/backend/arm/runner.py
+++ b/rpython/jit/backend/arm/runner.py
@@ -107,7 +107,7 @@
 
 class CPU_ARM(AbstractARMCPU):
 """ARM v7 uses softfp ABI, requires vfp"""
-pass
+backend_name = "arm"
 ArmCPU = CPU_ARM
 
 class CPU_ARMHF(AbstractARMCPU):
diff --git a/rpython/jit/backend/llsupport/test/test_gc_integration.py 
b/rpython/jit/backend/llsupport/test/test_gc_integration.py
--- a/rpython/jit/backend/llsupport/test/test_gc_integration.py
+++ b/rpython/jit/backend/llsupport/test/test_gc_integration.py
@@ -2,6 +2,7 @@
 """ Tests for register allocation for common constructs
 """
 
+import re
 from rpython.jit.metainterp.history import TargetToken, BasicFinalDescr,\
  JitCellToken, BasicFailDescr, AbstractDescr
 from rpython.jit.backend.llsupport.gc import GcLLDescription, GcLLDescr_boehm,\
@@ -18,6 +19,12 @@
 
 CPU = getcpuclass()
 
+def getmap(frame):
+r = ''
+for elem in frame.jf_gcmap:
+r += bin(elem)[2:]
+return r[r.find('1'):]
+
 class TestRegallocGcIntegration(BaseTestRegalloc):
 
 cpu = CPU(None, None)
@@ -66,17 +73,21 @@
 frame = lltype.cast_opaque_ptr(jitframe.JITFRAMEPTR, self.deadframe)
 # p0 and p3 should be in registers, p1 not so much
 assert self.getptr(0, lltype.Ptr(self.S)) == s1
-# this is a fairly CPU specific check
-assert len(frame.jf_gcmap) == 1
 # the gcmap should contain three things, p0, p1 and p3
 # p3 stays in a register
 # while p0 and p1 are on the frame
-if self.cpu.IS_64_BIT:
-nos = [11, 12, 31]
+b = getmap(frame)
+nos = [len(b) - 1 - i.start() for i in re.finditer('1', b)]
+nos.reverse()
+if self.cpu.backend_name.startswith('x86'):
+if self.cpu.IS_64_BIT:
+assert nos == [11, 12, 31]
+else:
+assert nos ==  [4, 5, 25]
+elif self.cpu.backend_name.startswith('arm'):
+assert nos == []
 else:
-nos = [4, 5, 25]
-assert frame.jf_gcmap[0] == ((1 << nos[0]) | (1 << nos[1]) |
- (1 << nos[2]))
+raise Exception("write the data here")
 assert frame.jf_frame[nos[0]]
 assert frame.jf_frame[nos[1]]
 assert frame.jf_frame[nos[2]]
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: fix the test

2013-03-06 Thread fijal
Author: Maciej Fijalkowski 
Branch: jitframe-on-heap
Changeset: r62146:aef7ed124ee1
Date: 2013-03-07 00:01 +0200
http://bitbucket.org/pypy/pypy/changeset/aef7ed124ee1/

Log:fix the test

diff --git a/rpython/jit/backend/llsupport/test/test_gc_integration.py 
b/rpython/jit/backend/llsupport/test/test_gc_integration.py
--- a/rpython/jit/backend/llsupport/test/test_gc_integration.py
+++ b/rpython/jit/backend/llsupport/test/test_gc_integration.py
@@ -85,7 +85,7 @@
 else:
 assert nos ==  [4, 5, 25]
 elif self.cpu.backend_name.startswith('arm'):
-assert nos == []
+assert nos == [15, 25, 26]
 else:
 raise Exception("write the data here")
 assert frame.jf_frame[nos[0]]
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: only call sqlite3_{finalize, reset} if not already called

2013-03-06 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r62147:60a6a2e99263
Date: 2013-03-06 17:04 -0500
http://bitbucket.org/pypy/pypy/changeset/60a6a2e99263/

Log:only call sqlite3_{finalize,reset} if not already called

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -1018,15 +1018,16 @@
 sqlite.sqlite3_finalize(self._statement)
 
 def _finalize(self):
-sqlite.sqlite3_finalize(self._statement)
-self._statement = None
+if self._statement:
+sqlite.sqlite3_finalize(self._statement)
+self._statement = None
 self._in_use = False
 
 def _reset(self):
-ret = sqlite.sqlite3_reset(self._statement)
-self._in_use = False
+if self._in_use and self._statement:
+ret = sqlite.sqlite3_reset(self._statement)
+self._in_use = False
 self._exhausted = False
-return ret
 
 def _build_row_cast_map(self):
 self.__row_cast_map = []
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: store the loop for debugging

2013-03-06 Thread fijal
Author: Maciej Fijalkowski 
Branch: jitframe-on-heap
Changeset: r62148:ea68db3f9825
Date: 2013-03-07 00:04 +0200
http://bitbucket.org/pypy/pypy/changeset/ea68db3f9825/

Log:store the loop for debugging

diff --git a/rpython/jit/backend/llsupport/test/test_regalloc_integration.py 
b/rpython/jit/backend/llsupport/test/test_regalloc_integration.py
--- a/rpython/jit/backend/llsupport/test/test_regalloc_integration.py
+++ b/rpython/jit/backend/llsupport/test/test_regalloc_integration.py
@@ -95,6 +95,7 @@
 
 def interpret(self, ops, args, run=True):
 loop = self.parse(ops)
+self.loop = loop
 looptoken = JitCellToken()
 self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken)
 arguments = []
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: oops

2013-03-06 Thread fijal
Author: Maciej Fijalkowski 
Branch: jitframe-on-heap
Changeset: r62149:f30e3aaca824
Date: 2013-03-07 00:33 +0200
http://bitbucket.org/pypy/pypy/changeset/f30e3aaca824/

Log:oops

diff --git a/rpython/jit/backend/llsupport/test/test_gc_integration.py 
b/rpython/jit/backend/llsupport/test/test_gc_integration.py
--- a/rpython/jit/backend/llsupport/test/test_gc_integration.py
+++ b/rpython/jit/backend/llsupport/test/test_gc_integration.py
@@ -22,7 +22,7 @@
 def getmap(frame):
 r = ''
 for elem in frame.jf_gcmap:
-r += bin(elem)[2:]
+r = bin(elem)[2:] + r
 return r[r.find('1'):]
 
 class TestRegallocGcIntegration(BaseTestRegalloc):
@@ -85,7 +85,7 @@
 else:
 assert nos ==  [4, 5, 25]
 elif self.cpu.backend_name.startswith('arm'):
-assert nos == [15, 25, 26]
+assert nos == [9, 10, 47]
 else:
 raise Exception("write the data here")
 assert frame.jf_frame[nos[0]]
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitframe-on-heap: one more

2013-03-06 Thread fijal
Author: Maciej Fijalkowski 
Branch: jitframe-on-heap
Changeset: r62150:f635eff12548
Date: 2013-03-07 00:36 +0200
http://bitbucket.org/pypy/pypy/changeset/f635eff12548/

Log:one more

diff --git a/rpython/jit/backend/llsupport/test/test_gc_integration.py 
b/rpython/jit/backend/llsupport/test/test_gc_integration.py
--- a/rpython/jit/backend/llsupport/test/test_gc_integration.py
+++ b/rpython/jit/backend/llsupport/test/test_gc_integration.py
@@ -22,7 +22,9 @@
 def getmap(frame):
 r = ''
 for elem in frame.jf_gcmap:
-r = bin(elem)[2:] + r
+elem = bin(elem)[2:]
+elem = '0' * (WORD * 8 - len(elem)) + elem
+r = elem + r
 return r[r.find('1'):]
 
 class TestRegallocGcIntegration(BaseTestRegalloc):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: Remove py3k attribute from base object space. It's not necessary anymore because the flow object space is independent from the interpreter now.

2013-03-06 Thread Manuel Jacob
Author: Manuel Jacob
Branch: py3k
Changeset: r62152:8b8e895b4fcb
Date: 2013-03-07 00:53 +0100
http://bitbucket.org/pypy/pypy/changeset/8b8e895b4fcb/

Log:Remove py3k attribute from base object space. It's not necessary
anymore because the flow object space is independent from the
interpreter now.

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -295,8 +295,6 @@
 """Base class for the interpreter-level implementations of object spaces.
 http://pypy.readthedocs.org/en/latest/objspace.html""";
 
-py3k = True # are we interpreting py3k bytecode?
-
 def __init__(self, config=None):
 "NOT_RPYTHON: Basic initialization of objects."
 self.fromcache = InternalSpaceCache(self).getorbuild
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -534,7 +534,6 @@
 self.setdictscope(w_locals)
 
 def POP_EXCEPT(self, oparg, next_instr):
-assert self.space.py3k
 block = self.pop_block()
 block.cleanup(self)
 return
@@ -1327,14 +1326,12 @@
 # the stack setup is slightly different than in CPython:
 # instead of the traceback, we store the unroller object,
 # wrapped.
-if frame.space.py3k:
-# this is popped by POP_EXCEPT, which is present only in py3k
-w_last_exception = W_OperationError(frame.last_exception)
-w_last_exception = frame.space.wrap(w_last_exception)
-frame.pushvalue(w_last_exception)
-block = ExceptHandlerBlock(self.valuestackdepth,
-   0, frame.lastblock)
-frame.lastblock = block
+# this is popped by POP_EXCEPT, which is present only in py3k
+w_last_exception = W_OperationError(frame.last_exception)
+w_last_exception = frame.space.wrap(w_last_exception)
+frame.pushvalue(w_last_exception)
+block = ExceptHandlerBlock(self.valuestackdepth, 0, frame.lastblock)
+frame.lastblock = block
 frame.pushvalue(frame.space.wrap(unroller))
 frame.pushvalue(operationerr.get_w_value(frame.space))
 frame.pushvalue(operationerr.w_type)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k-memoryview: Only check for TypeError here.

2013-03-06 Thread Manuel Jacob
Author: Manuel Jacob
Branch: py3k-memoryview
Changeset: r62151:e444775753c6
Date: 2013-03-06 12:51 +0100
http://bitbucket.org/pypy/pypy/changeset/e444775753c6/

Log:Only check for TypeError here.

diff --git a/pypy/module/__builtin__/test/test_buffer.py 
b/pypy/module/__builtin__/test/test_buffer.py
--- a/pypy/module/__builtin__/test/test_buffer.py
+++ b/pypy/module/__builtin__/test/test_buffer.py
@@ -67,7 +67,7 @@
 assert data == bytearray(eval("b'zbcefg'"))
 v[1:4] = b'123'
 assert data == bytearray(eval("b'z123fg'"))
-raises((ValueError, TypeError), "v[2] = 'spam'")
+raises(TypeError, "v[2] = 'spam'")
 
 def test_memoryview_attrs(self):
 v = memoryview(b"a"*100)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: these are redundant

2013-03-06 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r62153:47b22d98ea8d
Date: 2013-03-06 19:11 -0500
http://bitbucket.org/pypy/pypy/changeset/47b22d98ea8d/

Log:these are redundant

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -1070,7 +1070,7 @@
 def __set_param(self, idx, param):
 cvt = converters.get(type(param))
 if cvt is not None:
-cvt = param = cvt(param)
+param = cvt(param)
 
 param = adapt(param)
 
@@ -1124,8 +1124,6 @@
 self.__set_param(i, param)
 
 def _next(self, cursor):
-self.__con._check_closed()
-self.__con._check_thread()
 if self._exhausted:
 raise StopIteration
 item = self._item
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: check return value of sqlite3_bind_xxx

2013-03-06 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r62154:e14333f7fb32
Date: 2013-03-06 19:22 -0500
http://bitbucket.org/pypy/pypy/changeset/e14333f7fb32/

Log:check return value of sqlite3_bind_xxx

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -1075,25 +1075,25 @@
 param = adapt(param)
 
 if param is None:
-sqlite.sqlite3_bind_null(self._statement, idx)
+rc = sqlite.sqlite3_bind_null(self._statement, idx)
 elif type(param) in (bool, int, long):
 if -2147483648 <= param <= 2147483647:
-sqlite.sqlite3_bind_int(self._statement, idx, param)
+rc = sqlite.sqlite3_bind_int(self._statement, idx, param)
 else:
-sqlite.sqlite3_bind_int64(self._statement, idx, param)
+rc = sqlite.sqlite3_bind_int64(self._statement, idx, param)
 elif type(param) is float:
-sqlite.sqlite3_bind_double(self._statement, idx, param)
+rc = sqlite.sqlite3_bind_double(self._statement, idx, param)
 elif isinstance(param, str):
 self.__check_decodable(param)
-sqlite.sqlite3_bind_text(self._statement, idx, param, len(param), 
SQLITE_TRANSIENT)
+rc = sqlite.sqlite3_bind_text(self._statement, idx, param, 
len(param), SQLITE_TRANSIENT)
 elif isinstance(param, unicode):
 param = param.encode("utf-8")
-sqlite.sqlite3_bind_text(self._statement, idx, param, len(param), 
SQLITE_TRANSIENT)
+rc = sqlite.sqlite3_bind_text(self._statement, idx, param, 
len(param), SQLITE_TRANSIENT)
 elif type(param) is buffer:
-sqlite.sqlite3_bind_blob(self._statement, idx, str(param), 
len(param), SQLITE_TRANSIENT)
+rc = sqlite.sqlite3_bind_blob(self._statement, idx, str(param), 
len(param), SQLITE_TRANSIENT)
 else:
-raise InterfaceError("parameter type %s is not supported" %
- str(type(param)))
+rc = -1
+return rc
 
 def _set_params(self, params):
 self._in_use = True
@@ -1107,7 +1107,10 @@
"there are %d supplied." %
(num_params_needed, num_params))
 for i in range(num_params):
-self.__set_param(i + 1, params[i])
+rc = self.__set_param(i + 1, params[i])
+if rc != SQLITE_OK:
+raise InterfaceError("Error binding parameter %d - "
+ "probably unsupported type." % i)
 else:
 for i in range(1, num_params_needed + 1):
 param_name = 
sqlite.sqlite3_bind_parameter_name(self._statement, i)
@@ -1121,7 +1124,11 @@
 except KeyError:
 raise ProgrammingError("You did not supply a value for "
"binding %d." % i)
-self.__set_param(i, param)
+rc = self.__set_param(i, param)
+if rc != SQLITE_OK:
+raise InterfaceError("Error binding parameter :%s - "
+ "probably unsupported type." %
+ param_name)
 
 def _next(self, cursor):
 if self._exhausted:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: improve sqlite parameter type checking, test

2013-03-06 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r62155:f22a27ebaeed
Date: 2013-03-06 19:52 -0500
http://bitbucket.org/pypy/pypy/changeset/f22a27ebaeed/

Log:improve sqlite parameter type checking, test

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -1099,7 +1099,9 @@
 self._in_use = True
 
 num_params_needed = 
sqlite.sqlite3_bind_parameter_count(self._statement)
-if not isinstance(params, dict):
+if isinstance(params, (tuple, list)) or \
+not isinstance(params, dict) and \
+hasattr(params, '__len__') and hasattr(params, '__getitem__'):
 num_params = len(params)
 if num_params != num_params_needed:
 raise ProgrammingError("Incorrect number of bindings supplied. 
"
@@ -,7 +1113,7 @@
 if rc != SQLITE_OK:
 raise InterfaceError("Error binding parameter %d - "
  "probably unsupported type." % i)
-else:
+elif isinstance(params, dict):
 for i in range(1, num_params_needed + 1):
 param_name = 
sqlite.sqlite3_bind_parameter_name(self._statement, i)
 if param_name is None:
@@ -1129,6 +1131,8 @@
 raise InterfaceError("Error binding parameter :%s - "
  "probably unsupported type." %
  param_name)
+else:
+raise ValueError("parameters are of unsupported type")
 
 def _next(self, cursor):
 if self._exhausted:
diff --git a/pypy/module/test_lib_pypy/test_sqlite3.py 
b/pypy/module/test_lib_pypy/test_sqlite3.py
--- a/pypy/module/test_lib_pypy/test_sqlite3.py
+++ b/pypy/module/test_lib_pypy/test_sqlite3.py
@@ -126,3 +126,20 @@
 con.commit()
 except _sqlite3.OperationalError:
 pytest.fail("_sqlite3 knew nothing about the implicit ROLLBACK")
+
+def test_statement_param_checking():
+con = _sqlite3.connect(':memory:')
+con.execute('create table foo(x)')
+con.execute('insert into foo(x) values (?)', [2])
+con.execute('insert into foo(x) values (?)', (2,))
+class seq(object):
+def __len__(self):
+return 1
+def __getitem__(self, key):
+return 2
+con.execute('insert into foo(x) values (?)', seq())
+with pytest.raises(_sqlite3.ProgrammingError):
+con.execute('insert into foo(x) values (?)', {2:2})
+with pytest.raises(ValueError) as e:
+con.execute('insert into foo(x) values (?)', 2)
+assert str(e.value) == 'parameters are of unsupported type'
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Fix struct definition in ll_termios.

2013-03-06 Thread Manuel Jacob
Author: Manuel Jacob
Branch: 
Changeset: r62157:71045d55f113
Date: 2013-03-07 07:28 +0100
http://bitbucket.org/pypy/pypy/changeset/71045d55f113/

Log:Fix struct definition in ll_termios.

diff --git a/rpython/rtyper/module/ll_termios.py 
b/rpython/rtyper/module/ll_termios.py
--- a/rpython/rtyper/module/ll_termios.py
+++ b/rpython/rtyper/module/ll_termios.py
@@ -24,17 +24,28 @@
 class CConfig:
 _compilation_info_ = eci
 NCCS = rffi_platform.DefinedConstantInteger('NCCS')
+_HAVE_STRUCT_TERMIOS_C_ISPEED = rffi_platform.Defined(
+'_HAVE_STRUCT_TERMIOS_C_ISPEED')
+_HAVE_STRUCT_TERMIOS_C_OSPEED = rffi_platform.Defined(
+'_HAVE_STRUCT_TERMIOS_C_OSPEED')
 
-NCCS = rffi_platform.configure(CConfig)['NCCS']
+c_config = rffi_platform.configure(CConfig)
+NCCS = c_config['NCCS']
 
 TCFLAG_T = rffi.UINT
 CC_T = rffi.UCHAR
 SPEED_T = rffi.UINT
 INT = rffi.INT
 
+_add = []
+if c_config['_HAVE_STRUCT_TERMIOS_C_ISPEED']:
+_add.append(('c_ispeed', SPEED_T))
+if c_config['_HAVE_STRUCT_TERMIOS_C_OSPEED']:
+_add.append(('c_ospeed', SPEED_T))
 TERMIOSP = rffi.CStructPtr('termios', ('c_iflag', TCFLAG_T), ('c_oflag', 
TCFLAG_T),
('c_cflag', TCFLAG_T), ('c_lflag', TCFLAG_T),
-   ('c_cc', lltype.FixedSizeArray(CC_T, NCCS)))
+   ('c_line', CC_T),
+   ('c_cc', lltype.FixedSizeArray(CC_T, NCCS)), *_add)
 
 def c_external(name, args, result):
 return rffi.llexternal(name, args, result, compilation_info=eci)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Random cleanups.

2013-03-06 Thread Manuel Jacob
Author: Manuel Jacob
Branch: 
Changeset: r62156:9cec3981c9a2
Date: 2013-03-07 07:15 +0100
http://bitbucket.org/pypy/pypy/changeset/9cec3981c9a2/

Log:Random cleanups.

diff --git a/rpython/memory/gctransform/framework.py 
b/rpython/memory/gctransform/framework.py
--- a/rpython/memory/gctransform/framework.py
+++ b/rpython/memory/gctransform/framework.py
@@ -7,8 +7,7 @@
 from rpython.memory.gctransform.log import log
 from rpython.memory.gctransform.support import get_rtti, ll_call_destructor
 from rpython.memory.gctransform.transform import GCTransformer
-from rpython.memory.gctypelayout import ll_weakref_deref, WEAKREF, \
- WEAKREFPTR
+from rpython.memory.gctypelayout import ll_weakref_deref, WEAKREF, WEAKREFPTR
 from rpython.tool.sourcetools import func_with_new_name
 from rpython.translator.backendopt import graphanalyze
 from rpython.translator.backendopt.finalizer import FinalizerAnalyzer
@@ -317,7 +316,8 @@
 malloc_fast = func_with_new_name(
 malloc_fast_meth,
 "malloc_fast")
-s_False = annmodel.SomeBool(); s_False.const = False
+s_False = annmodel.SomeBool()
+s_False.const = False
 self.malloc_fast_ptr = getfn(
 malloc_fast,
 [s_gc, s_typeid16,
@@ -335,7 +335,8 @@
 malloc_varsize_clear_fast = func_with_new_name(
 GCClass.malloc_varsize_clear.im_func,
 "malloc_varsize_clear_fast")
-s_False = annmodel.SomeBool(); s_False.const = False
+s_False = annmodel.SomeBool()
+s_False.const = False
 self.malloc_varsize_clear_fast_ptr = getfn(
 malloc_varsize_clear_fast,
 [s_gc, s_typeid16,
@@ -614,7 +615,7 @@
 if self.collect_analyzer.analyze_direct_call(graph):
 raise Exception("'no_collect' function can trigger collection:"
 " %s" % func)
-
+
 if self.write_barrier_ptr:
 self.clean_sets = (
 find_initializing_stores(self.collect_analyzer, graph))
@@ -1180,7 +1181,7 @@
 if self.gcdata.gc.moving_gc and not keep_current_args:
 # moving GCs don't borrow, so the caller does not need to keep
 # the arguments alive
-livevars = [var for var in hop.livevars_after_op()]
+livevars = hop.livevars_after_op()
 else:
 livevars = hop.livevars_after_op() + hop.current_op_keeps_alive()
 return livevars
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: simplify

2013-03-06 Thread pjenvey
Author: Philip Jenvey 
Branch: py3k
Changeset: r62158:e569a7d9ad90
Date: 2013-03-06 23:42 -0800
http://bitbucket.org/pypy/pypy/changeset/e569a7d9ad90/

Log:simplify

diff --git a/pypy/module/imp/test/support.py b/pypy/module/imp/test/support.py
--- a/pypy/module/imp/test/support.py
+++ b/pypy/module/imp/test/support.py
@@ -10,12 +10,8 @@
 if sys.platform == 'nt':
 testfn_unencodable = testfn + u"-\u5171\u0141\u2661\u0363\uDC80"
 elif sys.platform != 'darwin':
-fsenc = sys.getfilesystemencoding()
 try:
-'\xff'.decode(fsenc)
+'\xff'.decode(sys.getfilesystemencoding())
 except UnicodeDecodeError:
-w_unenc = space.call_method(space.wrapbytes('-\xff'), 'decode',
-space.wrap(fsenc),
-space.wrap('surrogateescape'))
-testfn_unencodable = testfn + space.unicode_w(w_unenc)
+testfn_unencodable = testfn + u'-\udcff'
 cls.w_testfn_unencodable = space.wrap(testfn_unencodable)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit