Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r47026:5fb2ba368b6b Date: 2011-09-02 16:04 +0200 http://bitbucket.org/pypy/pypy/changeset/5fb2ba368b6b/
Log: merge heads diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py --- a/lib_pypy/_sqlite3.py +++ b/lib_pypy/_sqlite3.py @@ -705,6 +705,8 @@ from sqlite3.dump import _iterdump return _iterdump(self) +DML, DQL, DDL = range(3) + class Cursor(object): def __init__(self, con): if not isinstance(con, Connection): @@ -735,9 +737,9 @@ self.statement = self.connection.statement_cache.get(sql, self, self.row_factory) if self.connection._isolation_level is not None: - if self.statement.kind == "DDL": + if self.statement.kind == DDL: self.connection.commit() - elif self.statement.kind == "DML": + elif self.statement.kind == DML: self.connection._begin() self.statement.set_params(params) @@ -748,18 +750,18 @@ self.statement.reset() raise self.connection._get_exception(ret) - if self.statement.kind == "DQL"and ret == SQLITE_ROW: + if self.statement.kind == DQL and ret == SQLITE_ROW: self.statement._build_row_cast_map() self.statement._readahead() else: self.statement.item = None self.statement.exhausted = True - if self.statement.kind in ("DML", "DDL"): + if self.statement.kind == DML or self.statement.kind == DDL: self.statement.reset() self.rowcount = -1 - if self.statement.kind == "DML": + if self.statement.kind == DML: self.rowcount = sqlite.sqlite3_changes(self.connection.db) return self @@ -772,7 +774,7 @@ self._check_closed() self.statement = self.connection.statement_cache.get(sql, self, self.row_factory) - if self.statement.kind == "DML": + if self.statement.kind == DML: self.connection._begin() else: raise ProgrammingError, "executemany is only for DML statements" @@ -904,11 +906,11 @@ self.sql = sql # DEBUG ONLY first_word = self._statement_kind = sql.lstrip().split(" ")[0].upper() if first_word in ("INSERT", "UPDATE", "DELETE", "REPLACE"): - self.kind = "DML" + self.kind = DML elif first_word in ("SELECT", "PRAGMA"): - self.kind = "DQL" + self.kind = DQL else: - self.kind = "DDL" + self.kind = DDL self.exhausted = False self.in_use = False # @@ -923,7 +925,7 @@ if ret == SQLITE_OK and self.statement.value is None: # an empty statement, we work around that, as it's the least trouble ret = sqlite.sqlite3_prepare_v2(self.con.db, "select 42", -1, byref(self.statement), byref(next_char)) - self.kind = "DQL" + self.kind = DQL if ret != SQLITE_OK: raise self.con._get_exception(ret) @@ -1118,7 +1120,7 @@ self.statement = None def _get_description(self): - if self.kind == "DML": + if self.kind == DML: return None desc = [] for i in xrange(sqlite.sqlite3_column_count(self.statement)): diff --git a/pypy/module/pypyjit/test_pypy_c/test_globals.py b/pypy/module/pypyjit/test_pypy_c/test_globals.py --- a/pypy/module/pypyjit/test_pypy_c/test_globals.py +++ b/pypy/module/pypyjit/test_pypy_c/test_globals.py @@ -23,6 +23,4 @@ guard_not_invalidated(descr=...) p19 = getfield_gc(ConstPtr(p17), descr=<GcPtrFieldDescr .*W_DictMultiObject.inst_strategy .*>) guard_value(p19, ConstPtr(ptr20), descr=...) - p22 = getfield_gc(ConstPtr(ptr21), descr=<GcPtrFieldDescr .*ModuleCell.inst_w_value .*>) - guard_nonnull(p22, descr=...) - """) + """) \ No newline at end of file diff --git a/pypy/objspace/std/celldict.py b/pypy/objspace/std/celldict.py --- a/pypy/objspace/std/celldict.py +++ b/pypy/objspace/std/celldict.py @@ -65,6 +65,10 @@ if isinstance(cell, ModuleCell): cell.w_value = w_value return + # If the new value and the current value are the same, don't create a + # level of indirection, or mutate are version. + if self.space.is_w(w_value, cell): + return if cell is not None: w_value = ModuleCell(w_value) self.mutated() diff --git a/pypy/objspace/std/test/test_celldict.py b/pypy/objspace/std/test/test_celldict.py --- a/pypy/objspace/std/test/test_celldict.py +++ b/pypy/objspace/std/test/test_celldict.py @@ -39,6 +39,20 @@ assert d.getitem("a") is None assert d.strategy.getdictvalue_no_unwrapping(d, "a") is None + def test_same_key_set_twice(self): + strategy = ModuleDictStrategy(space) + storage = strategy.get_empty_storage() + d = W_DictMultiObject(space, strategy, storage) + + v1 = strategy.version + x = object() + d.setitem("a", x) + v2 = strategy.version + assert v1 is not v2 + d.setitem("a", x) + v3 = strategy.version + assert v2 is v3 + class AppTestModuleDict(object): def setup_class(cls): cls.space = gettestobjspace(**{"objspace.std.withcelldict": True}) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit