Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r76055:6419bd45b4a3 Date: 2015-02-22 18:22 +0100 http://bitbucket.org/pypy/pypy/changeset/6419bd45b4a3/
Log: merge heads diff --git a/lib_pypy/gdbm.py b/lib_pypy/gdbm.py --- a/lib_pypy/gdbm.py +++ b/lib_pypy/gdbm.py @@ -20,9 +20,11 @@ } datum; datum gdbm_fetch(void*, datum); +datum pygdbm_fetch(void*, char*, int); int gdbm_delete(void*, datum); int gdbm_store(void*, datum, datum, int); int gdbm_exists(void*, datum); +int pygdbm_exists(void*, char*, int); int gdbm_reorganize(void*); @@ -37,19 +39,29 @@ ''') try: + verify_code = ''' + #include "gdbm.h" + + static datum pygdbm_fetch(GDBM_FILE gdbm_file, char *dptr, int dsize) { + datum key = {dptr, dsize}; + return gdbm_fetch(gdbm_file, key); + } + + static int pygdbm_exists(GDBM_FILE gdbm_file, char *dptr, int dsize) { + datum key = {dptr, dsize}; + return gdbm_exists(gdbm_file, key); + } + + ''' if sys.platform.startswith('freebsd'): import os.path _localbase = os.environ.get('LOCALBASE', '/usr/local') - lib = ffi.verify(''' - #include "gdbm.h" - ''', libraries=['gdbm'], + lib = ffi.verify(verify_code, libraries=['gdbm'], include_dirs=[os.path.join(_localbase, 'include')], library_dirs=[os.path.join(_localbase, 'lib')] ) else: - lib = ffi.verify(''' - #include "gdbm.h" - ''', libraries=['gdbm']) + lib = ffi.verify(verify_code, libraries=['gdbm']) except cffi.VerificationError as e: # distutils does not preserve the actual message, # but the verification is simple enough that the @@ -59,6 +71,13 @@ class error(Exception): pass +def _checkstr(key): + if isinstance(key, unicode): + key = key.encode("ascii") + if not isinstance(key, str): + raise TypeError("gdbm mappings have string indices only") + return key + def _fromstr(key): if isinstance(key, unicode): key = key.encode("ascii") @@ -107,12 +126,14 @@ def __contains__(self, key): self._check_closed() - return lib.gdbm_exists(self.ll_dbm, _fromstr(key)) + key = _checkstr(key) + return lib.pygdbm_exists(self.ll_dbm, key, len(key) has_key = __contains__ def __getitem__(self, key): self._check_closed() - drec = lib.gdbm_fetch(self.ll_dbm, _fromstr(key)) + key = _checkstr(key) + drec = lib.pygdbm_fetch(self.ll_dbm, key, len(key)) if not drec.dptr: raise KeyError(key) res = str(ffi.buffer(drec.dptr, drec.dsize)) diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -30,3 +30,7 @@ .. branch: alt_errno Add an alternative location to save LastError, errno around ctypes, cffi external calls so things like pdb will not overwrite it + +.. branch: nonquadratic-heapcache +Speed up the warmup times of the JIT by removing a quadratic algorithm in the +heapcache. diff --git a/rpython/jit/metainterp/test/test_recursive.py b/rpython/jit/metainterp/test/test_recursive.py --- a/rpython/jit/metainterp/test/test_recursive.py +++ b/rpython/jit/metainterp/test/test_recursive.py @@ -794,7 +794,7 @@ return frame.thing.val + s res = self.meta_interp(main, [0], inline=True) - self.check_resops(call=0, cond_call=0) # got removed by optimization + self.check_resops(call=0, cond_call=2) assert res == main(0) def test_directly_call_assembler_virtualizable_reset_token(self): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit