[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

darin darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 07:39:10 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 8aede131e4cc821fdafb526d20aebd8a986f58f5
Author: darin <darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Apr 29 18:26:29 2003 +0000

            Reviewed by John.
    
    	- fixed 2959353 -- eliminate globally initialized objects from JavaScriptCore
    
            * JavaScriptCore.pbproj/project.pbxproj: Added fpconst.cpp.
            * kjs/fpconst.cpp: Added. Defines KJS::NaN and KJS::Inf in a way that does not require a
            framework init routine.
    
            * kjs/identifier.h: Use a new KJS_IDENTIFIER_EACH_GLOBAL macro so we can do things to
            the entire set of identifiers easily. Also added an init function that sets up these globals
            in a way that does not require a framework init routine.
            * kjs/identifier.cpp: (Identifier::init): Initialize the property ane globals in a way that
            does not require a framework init routine.
    
            * kjs/internal.cpp: (InterpreterImp::initGlobalObject): Call Identifier::init.
    
            * kjs/ustring.h: Remove UChar::null and UString::null, and add UString::null(). We can't have
            a global object of a class that has a constructor if we want to avoid framework init routines,
            and luckily very little code relies on these.
            * kjs/ustring.cpp:
            (UCharReference::ref): Use our own global specific to this function rather than returning
            UChar::null when past the end of the string. This is dangerous because if the caller modifies
            it, that affects what all subsequent callers will see.
            (UString::Rep::create): Added assertions.
            (UString::UString): Got rid of code here that used to set up UString::null.
            (UString::null): Added. Returns a global null string, and can be used in some of the places
            where we used to use the UString::null global.
            (UString::operator[]): Fixed case where this used to return UChar::null to return '\0' instead.
    
            * kjs/regexp.cpp: (RegExp::match): Change uses of UString::null to UString::null().
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@4206 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 6064b0c..430d5fc 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,36 @@
+2003-04-28  Darin Adler  <darin at apple.com>
+
+        Reviewed by John.
+
+	- fixed 2959353 -- eliminate globally initialized objects from JavaScriptCore
+
+        * JavaScriptCore.pbproj/project.pbxproj: Added fpconst.cpp.
+        * kjs/fpconst.cpp: Added. Defines KJS::NaN and KJS::Inf in a way that does not require a
+        framework init routine.
+
+        * kjs/identifier.h: Use a new KJS_IDENTIFIER_EACH_GLOBAL macro so we can do things to
+        the entire set of identifiers easily. Also added an init function that sets up these globals
+        in a way that does not require a framework init routine.
+        * kjs/identifier.cpp: (Identifier::init): Initialize the property ane globals in a way that
+        does not require a framework init routine.
+
+        * kjs/internal.cpp: (InterpreterImp::initGlobalObject): Call Identifier::init.
+        
+        * kjs/ustring.h: Remove UChar::null and UString::null, and add UString::null(). We can't have
+        a global object of a class that has a constructor if we want to avoid framework init routines,
+        and luckily very little code relies on these.
+        * kjs/ustring.cpp:
+        (UCharReference::ref): Use our own global specific to this function rather than returning
+        UChar::null when past the end of the string. This is dangerous because if the caller modifies
+        it, that affects what all subsequent callers will see.
+        (UString::Rep::create): Added assertions.
+        (UString::UString): Got rid of code here that used to set up UString::null.
+        (UString::null): Added. Returns a global null string, and can be used in some of the places
+        where we used to use the UString::null global.
+        (UString::operator[]): Fixed case where this used to return UChar::null to return '\0' instead.
+
+        * kjs/regexp.cpp: (RegExp::match): Change uses of UString::null to UString::null().
+
 2003-04-25  Darin Adler  <darin at apple.com>
 
 	- fixed 3241344 -- REGRESSION: top of page missing on wired.com and cnn.com
diff --git a/JavaScriptCore/ChangeLog-2003-10-25 b/JavaScriptCore/ChangeLog-2003-10-25
index 6064b0c..430d5fc 100644
--- a/JavaScriptCore/ChangeLog-2003-10-25
+++ b/JavaScriptCore/ChangeLog-2003-10-25
@@ -1,3 +1,36 @@
+2003-04-28  Darin Adler  <darin at apple.com>
+
+        Reviewed by John.
+
+	- fixed 2959353 -- eliminate globally initialized objects from JavaScriptCore
+
+        * JavaScriptCore.pbproj/project.pbxproj: Added fpconst.cpp.
+        * kjs/fpconst.cpp: Added. Defines KJS::NaN and KJS::Inf in a way that does not require a
+        framework init routine.
+
+        * kjs/identifier.h: Use a new KJS_IDENTIFIER_EACH_GLOBAL macro so we can do things to
+        the entire set of identifiers easily. Also added an init function that sets up these globals
+        in a way that does not require a framework init routine.
+        * kjs/identifier.cpp: (Identifier::init): Initialize the property ane globals in a way that
+        does not require a framework init routine.
+
+        * kjs/internal.cpp: (InterpreterImp::initGlobalObject): Call Identifier::init.
+        
+        * kjs/ustring.h: Remove UChar::null and UString::null, and add UString::null(). We can't have
+        a global object of a class that has a constructor if we want to avoid framework init routines,
+        and luckily very little code relies on these.
+        * kjs/ustring.cpp:
+        (UCharReference::ref): Use our own global specific to this function rather than returning
+        UChar::null when past the end of the string. This is dangerous because if the caller modifies
+        it, that affects what all subsequent callers will see.
+        (UString::Rep::create): Added assertions.
+        (UString::UString): Got rid of code here that used to set up UString::null.
+        (UString::null): Added. Returns a global null string, and can be used in some of the places
+        where we used to use the UString::null global.
+        (UString::operator[]): Fixed case where this used to return UChar::null to return '\0' instead.
+
+        * kjs/regexp.cpp: (RegExp::match): Change uses of UString::null to UString::null().
+
 2003-04-25  Darin Adler  <darin at apple.com>
 
 	- fixed 3241344 -- REGRESSION: top of page missing on wired.com and cnn.com
diff --git a/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj b/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
index e2662ea..061c224 100644
--- a/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
+++ b/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
@@ -271,6 +271,7 @@
 				6541720B039E02E70058BFEB,
 				6541720C039E02E70058BFEB,
 				6541720D039E02E70058BFEB,
+				9364B274045B7D6C00A9CAC1,
 			);
 			isa = PBXSourcesBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
@@ -337,6 +338,7 @@
 				F692A8580255597D01FF60F7,
 				F692A85B0255597D01FF60F7,
 				F692A85A0255597D01FF60F7,
+				9364B273045B7D6C00A9CAC1,
 				F692A85D0255597D01FF60F7,
 				F692A85C0255597D01FF60F7,
 				F692A85F0255597D01FF60F7,
@@ -668,6 +670,18 @@
 			settings = {
 			};
 		};
+		9364B273045B7D6C00A9CAC1 = {
+			fileEncoding = 4;
+			isa = PBXFileReference;
+			path = fpconst.cpp;
+			refType = 4;
+		};
+		9364B274045B7D6C00A9CAC1 = {
+			fileRef = 9364B273045B7D6C00A9CAC1;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
 		9373524E038DA8C2008635CE = {
 			fileEncoding = 4;
 			isa = PBXFileReference;
diff --git a/JavaScriptCore/kjs/fpconst.cpp b/JavaScriptCore/kjs/fpconst.cpp
new file mode 100644
index 0000000..ad5d29c
--- /dev/null
+++ b/JavaScriptCore/kjs/fpconst.cpp
@@ -0,0 +1,41 @@
+/*
+ *  Copyright (C) 2003 Apple Computer, Inc.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include <config.h>
+
+// This file exists because JavaScriptCore needs to define the NaN and Inf globals in a way
+// that does not use a static initializer so we don't have a framework initialization routine.
+
+// The trick is to define the NaN and Inf globals with a different type than the declaration.
+// This trick works because the mangled name of the globals does not include the type, although
+// I'm not sure that's guaranteed. There could be alignment issues with this, since arrays of
+// characters don't necessarily need the same alignment doubles do, but for now it seems to work.
+// It would be good to figure out a 100% clean way that still avoids code that runs at init time.
+
+namespace KJS {
+
+#ifdef WORDS_BIGENDIAN
+  extern const unsigned char NaN[sizeof(double)] = { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 };
+  extern const unsigned char Inf[sizeof(double)] = { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 };
+#else
+  extern const unsigned char NaN[sizeof(double)] = { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f };
+  extern const unsigned char Inf[sizeof(double)] = { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f };
+#endif
+
+};
diff --git a/JavaScriptCore/kjs/identifier.cpp b/JavaScriptCore/kjs/identifier.cpp
index ff09e5a..ea08f54 100644
--- a/JavaScriptCore/kjs/identifier.cpp
+++ b/JavaScriptCore/kjs/identifier.cpp
@@ -19,6 +19,20 @@
  *
  */
 
+// For JavaScriptCore we need to avoid having static constructors.
+// Our strategy is to declare the global objects with a different type (initialized to 0)
+// and then use placement new to initialize the global objects later. This is not completely
+// portable, and it would be good to figure out a 100% clean way that still avoids code that
+// runs at init time.
+
+#if APPLE_CHANGES
+#define AVOID_STATIC_CONSTRUCTORS 1
+#endif
+
+#if AVOID_STATIC_CONSTRUCTORS
+#define KJS_IDENTIFIER_HIDE_GLOBALS 1
+#endif
+
 #include "identifier.h"
 
 #define DUMP_STATISTICS 0
@@ -43,18 +57,6 @@ IdentifierStatisticsExitLogger::~IdentifierStatisticsExitLogger()
 
 #endif
 
-extern const Identifier argumentsPropertyName("arguments");
-extern const Identifier calleePropertyName("callee");
-extern const Identifier constructorPropertyName("constructor");
-extern const Identifier lengthPropertyName("length");
-extern const Identifier messagePropertyName("message");
-extern const Identifier namePropertyName("name");
-extern const Identifier prototypePropertyName("prototype");
-extern const Identifier specialPrototypePropertyName("__proto__");
-extern const Identifier toLocaleStringPropertyName("toLocaleString");
-extern const Identifier toStringPropertyName("toString");
-extern const Identifier valueOfPropertyName("valueOf");
-
 const int _minTableSize = 64;
 
 UString::Rep **Identifier::_table;
@@ -300,4 +302,35 @@ const Identifier &Identifier::null()
     return null;
 }
 
+// Global constants for property name strings.
+
+#if !AVOID_STATIC_CONSTRUCTORS
+    // Define an Identifier in the normal way.
+    #define DEFINE_GLOBAL(name, string) extern const Identifier name ## PropertyName(string);
+#else
+    // Define an Identifier-sized array of pointers to avoid static initialization.
+    // Use an array of pointers instead of an array of char in case there is some alignment issue.
+    #define DEFINE_GLOBAL(name, string) \
+        void * name ## PropertyName[(sizeof(Identifier) + sizeof(void *) - 1) / sizeof(void *)];
+#endif
+
+#define CALL_DEFINE_GLOBAL(name) DEFINE_GLOBAL(name, #name)
+KJS_IDENTIFIER_EACH_GLOBAL(CALL_DEFINE_GLOBAL)
+DEFINE_GLOBAL(specialPrototype, "__proto__")
+
+void Identifier::init()
+{
+#if AVOID_STATIC_CONSTRUCTORS
+    static bool initialized;
+    if (!initialized) {
+        // Use placement new to initialize the globals.
+        #define PLACEMENT_NEW_GLOBAL(name, string) new (&name ## PropertyName) Identifier(string);
+        #define CALL_PLACEMENT_NEW_GLOBAL(name) PLACEMENT_NEW_GLOBAL(name, #name)
+        KJS_IDENTIFIER_EACH_GLOBAL(CALL_PLACEMENT_NEW_GLOBAL)
+        PLACEMENT_NEW_GLOBAL(specialPrototype, "__proto__")
+        initialized = true;
+    }
+#endif
+}
+
 } // namespace KJS
diff --git a/JavaScriptCore/kjs/identifier.h b/JavaScriptCore/kjs/identifier.h
index 21695f6..634787c 100644
--- a/JavaScriptCore/kjs/identifier.h
+++ b/JavaScriptCore/kjs/identifier.h
@@ -29,6 +29,8 @@ namespace KJS {
     class Identifier {
         friend class PropertyMap;
     public:
+        static void init();
+
         Identifier() { }
         Identifier(const char *s) : _ustring(add(s)) { }
         Identifier(const UChar *s, int length) : _ustring(add(s, length)) { }
@@ -98,17 +100,27 @@ namespace KJS {
     inline bool operator==(const Identifier &a, const char *b)
         { return Identifier::equal(a, b); }
 
-    extern const Identifier argumentsPropertyName;
-    extern const Identifier calleePropertyName;
-    extern const Identifier constructorPropertyName;
-    extern const Identifier lengthPropertyName;
-    extern const Identifier messagePropertyName;
-    extern const Identifier namePropertyName;
-    extern const Identifier prototypePropertyName;
-    extern const Identifier specialPrototypePropertyName;
-    extern const Identifier toLocaleStringPropertyName;
-    extern const Identifier toStringPropertyName;
-    extern const Identifier valueOfPropertyName;
+    // List of property names, passed to a macro so we can do set them up various
+    // ways without repeating the list.
+    #define KJS_IDENTIFIER_EACH_GLOBAL(macro) \
+        macro(arguments) \
+        macro(callee) \
+        macro(constructor) \
+        macro(length) \
+        macro(message) \
+        macro(name) \
+        macro(prototype) \
+        macro(toLocaleString) \
+        macro(toString) \
+        macro(valueOf)
+
+    // Define external global variables for all property names above (and one more).
+#if !KJS_IDENTIFIER_HIDE_GLOBALS
+    #define KJS_IDENTIFIER_DECLARE_GLOBAL(name) extern const Identifier name ## PropertyName;
+    KJS_IDENTIFIER_EACH_GLOBAL(KJS_IDENTIFIER_DECLARE_GLOBAL)
+    KJS_IDENTIFIER_DECLARE_GLOBAL(specialPrototype)
+    #undef KJS_IDENTIFIER_DECLARE_GLOBAL
+#endif
 
 }
 
diff --git a/JavaScriptCore/kjs/internal.cpp b/JavaScriptCore/kjs/internal.cpp
index 21953d2..95834c6 100644
--- a/JavaScriptCore/kjs/internal.cpp
+++ b/JavaScriptCore/kjs/internal.cpp
@@ -54,6 +54,8 @@ extern int kjsyyparse();
 
 using namespace KJS;
 
+#if !APPLE_CHANGES
+
 namespace KJS {
 #ifdef WORDS_BIGENDIAN
   const unsigned char NaN_Bytes[] = { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 };
@@ -70,6 +72,8 @@ namespace KJS {
   const double Inf = *(const double*) Inf_Bytes;
 };
 
+#endif // APPLE_CHANGES
+
 static pthread_once_t interpreterLockOnce = PTHREAD_ONCE_INIT;
 static pthread_mutex_t interpreterLock;
 static int interpreterLockCount = 0;
@@ -547,6 +551,8 @@ void InterpreterImp::unlock()
 
 void InterpreterImp::initGlobalObject()
 {
+  Identifier::init();
+  
   // Contructor prototype objects (Object.prototype, Array.prototype etc)
 
   FunctionPrototypeImp *funcProto = new FunctionPrototypeImp(globExec);
diff --git a/JavaScriptCore/kjs/regexp.cpp b/JavaScriptCore/kjs/regexp.cpp
index 1ea880c..46572b3 100644
--- a/JavaScriptCore/kjs/regexp.cpp
+++ b/JavaScriptCore/kjs/regexp.cpp
@@ -100,7 +100,7 @@ UString RegExp::match(const UString &s, int i, int *pos, int **ovector)
     pos = &dummyPos;
   *pos = -1;
   if (i > s.size() || s.isNull())
-    return UString::null;
+    return UString::null();
 
 #ifdef HAVE_PCREPOSIX
   CString buffer(s.cstring());
@@ -109,10 +109,10 @@ UString RegExp::match(const UString &s, int i, int *pos, int **ovector)
 
   if (!pcregex || pcre_exec(pcregex, NULL, buffer.c_str(), buffer.size(), i,
 		  0, ovector ? *ovector : 0L, ovecsize) == PCRE_ERROR_NOMATCH)
-    return UString::null;
+    return UString::null();
 
   if (!ovector)
-    return UString::null; // don't rely on the return value if you pass ovector==0
+    return UString::null(); // don't rely on the return value if you pass ovector==0
 #else
   const uint maxMatch = 10;
   regmatch_t rmatch[maxMatch];
@@ -120,7 +120,7 @@ UString RegExp::match(const UString &s, int i, int *pos, int **ovector)
   char *str = strdup(s.ascii()); // TODO: why ???
   if (regexec(&preg, str + i, maxMatch, rmatch, 0)) {
     free(str);
-    return UString::null;
+    return UString::null();
   }
   free(str);
 
diff --git a/JavaScriptCore/kjs/ustring.cpp b/JavaScriptCore/kjs/ustring.cpp
index 1806d67..c0ffb36 100644
--- a/JavaScriptCore/kjs/ustring.cpp
+++ b/JavaScriptCore/kjs/ustring.cpp
@@ -116,10 +116,8 @@ bool KJS::operator==(const KJS::CString& c1, const KJS::CString& c2)
   return (strcmp(c1.c_str(), c2.c_str()) == 0);
 }
 
-UChar UChar::null((char)0);
 UString::Rep UString::Rep::null = { 0, 0, 0, 1, 1 };
 UString::Rep UString::Rep::empty = { 0, 0, 0, 1, 1 };
-UString UString::null;
 const int normalStatBufferSize = 4096;
 static char *statBuffer = 0;
 static int statBufferSize = 0;
@@ -154,8 +152,10 @@ UChar& UCharReference::ref() const
 {
   if (offset < str->rep->len)
     return *(str->rep->dat + offset);
-  else
-    return UChar::null;
+  else {
+    static UChar callerBetterNotModifyThis('\0');
+    return callerBetterNotModifyThis;
+  }
 }
 
 UString::Rep *UString::Rep::create(UChar *d, int l)
@@ -252,7 +252,6 @@ unsigned UString::Rep::computeHash(const char *s)
 
 UString::UString()
 {
-  null.rep = &Rep::null;
   attach(&Rep::null);
 }
 
@@ -321,6 +320,12 @@ UString::UString(const UString &a, const UString &b)
   rep = Rep::create(d, length);
 }
 
+const UString &UString::null()
+{
+    static UString n;
+    return n;
+}
+
 UString UString::from(int i)
 {
   return from((long)i);
@@ -550,9 +555,8 @@ bool UString::is8Bit() const
 UChar UString::operator[](int pos) const
 {
   if (pos >= size())
-    return UChar::null;
-
-  return ((UChar *)data())[pos];
+    return '\0';
+  return data()[pos];
 }
 
 UCharReference UString::operator[](int pos)
diff --git a/JavaScriptCore/kjs/ustring.h b/JavaScriptCore/kjs/ustring.h
index 8232913..c52d18d 100644
--- a/JavaScriptCore/kjs/ustring.h
+++ b/JavaScriptCore/kjs/ustring.h
@@ -97,10 +97,6 @@ namespace KJS {
      * @return The character converted to upper case.
      */
     UChar toUpper() const;
-    /**
-     * A static instance of UChar(0).
-     */
-    static UChar null;
 
     unsigned short uc;
   };
@@ -409,7 +405,7 @@ namespace KJS {
     /**
      * Static instance of a null string.
      */
-    static UString null;
+    static const UString &null();
 #ifdef KJS_DEBUG_MEM
     /**
      * Clear statically allocated resources.

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list