[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kjs
From:       Maks Orlovich <maksim () kde ! org>
Date:       2010-05-22 17:41:22
Message-ID: 20100522174123.04498AC8BC () svn ! kde ! org
[Download RAW message or body]

SVN commit 1129509 by orlovich:

Fix a string internment bug that occurs when garbage collection must run to allocate 
the StringImp.


 M  +1 -0      CompileState.h  
 M  +12 -8     interpreter.cpp  


--- trunk/KDE/kdelibs/kjs/CompileState.h #1129508:1129509
@@ -337,6 +337,7 @@
 }
 
 inline OpValue OpValue::immValue(JSValue* in) {
+    assert(in);
     OpValue res;
     initImm(&res, OpType_value);
     res.value.wide.valueVal = in;
--- trunk/KDE/kdelibs/kjs/interpreter.cpp #1129508:1129509
@@ -948,16 +948,20 @@
 
 StringImp* Interpreter::internString(const UString& literal)
 {
-    std::pair<InternedStringsTable::iterator, bool> p = 
-        s_internedStrings->add(literal.rep(), std::make_pair((StringImp*)(0), 1));
+    InternedStringsTable::iterator i = s_internedStrings->find(literal.rep());
         
-    if (p.second) // actually added..
-        p.first.values()->first = static_cast<StringImp*>(jsOwnedString(literal));
-    else
-        ++p.first.values()->second; // just bump the ref count
-
-    return p.first.values()->first;
+    if (i == s_internedStrings->end()) {
+        // Need to add. Note: we can't use ->add() above to avoid a double-hash
+        // as creation of a StringImp may cause a GC, which in turn may
+        // rearrange the hashtable, invalidating the iterator.
+        StringImp* si = static_cast<StringImp*>(jsOwnedString(literal));
+        s_internedStrings->add(literal.rep(), std::make_pair(si, 1));
+        return si;
+    } else {
+        ++i.values()->second; // just bump the ref count
+        return i.values()->first;
 }
+}
 
 void Interpreter::releaseInternedString(const UString& literal)
 {
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic