2006-02-23 Eric Seidel <eseidel@apple.com>
authoreseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Feb 2006 01:11:00 +0000 (01:11 +0000)
committereseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Feb 2006 01:11:00 +0000 (01:11 +0000)
        Reviewed by darin.

        Fix linking of static constructed globals on win32.

        * WebCore.vcproj/WebCore/WebCore.vcproj:
        * config.h:
        * dom/EventNames.cpp:
        (WebCore::EventNames::init):
        * dom/EventNames.h:
        * dom/dom_qname.cpp:
        (WebCore::QualifiedName::init):
        * dom/dom_qname.h:
        * khtml/html/htmlnames.cpp:
        (WebCore::HTMLNames::init):
        * khtml/html/htmlnames.h:
        * platform/AtomicString.cpp:
        (WebCore::AtomicString::init):
        * platform/StaticConstructors.h: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@12951 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/WebCore.vcproj/WebCore/WebCore.vcproj
WebCore/config.h
WebCore/dom/EventNames.cpp
WebCore/dom/EventNames.h
WebCore/dom/dom_qname.cpp
WebCore/dom/dom_qname.h
WebCore/khtml/html/htmlnames.cpp
WebCore/khtml/html/htmlnames.h
WebCore/platform/AtomicString.cpp
WebCore/platform/StaticConstructors.h [new file with mode: 0644]

index 686cb09405ed091bcc1c79effd1ad252c01633fd..2bc63176adf2c25fb4b634124449e3b412950a23 100644 (file)
@@ -1,3 +1,24 @@
+2006-02-23  Eric Seidel  <eseidel@apple.com>
+
+        Reviewed by darin.
+
+        Fix linking of static constructed globals on win32.
+
+        * WebCore.vcproj/WebCore/WebCore.vcproj:
+        * config.h:
+        * dom/EventNames.cpp:
+        (WebCore::EventNames::init):
+        * dom/EventNames.h:
+        * dom/dom_qname.cpp:
+        (WebCore::QualifiedName::init):
+        * dom/dom_qname.h:
+        * khtml/html/htmlnames.cpp:
+        (WebCore::HTMLNames::init):
+        * khtml/html/htmlnames.h:
+        * platform/AtomicString.cpp:
+        (WebCore::AtomicString::init):
+        * platform/StaticConstructors.h: Added.
+
 2006-02-23  Vicki Murley <vicki@apple.com>
 
         Reviewed by Tim Omernick.
index 4a99a5f1c7cbc62a5596a7762722c2dad43e250c..1398268dd3a4bcb130e980f4823baac346559e4a 100644 (file)
                                RelativePath="..\..\platform\SharedTimer.h"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\..\platform\StaticConstructors.h"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath="..\..\platform\String.cpp"\r
                                >\r
                        <Filter\r
                                Name="js"\r
                                >\r
+                               <File\r
+                                       RelativePath="..\..\bindings\js\JSDOMCore.cpp"\r
+                                       >\r
+                               </File>\r
                                <File\r
                                        RelativePath="..\..\bindings\js\JSDOMEvents.cpp"\r
                                        >\r
index 466d447346ead4258607c743e3eabcd7ffa46fe6..88ae9413c3796a1693a99d7dbe9e0e465e4df747 100644 (file)
@@ -57,3 +57,7 @@ typedef unsigned uint;
 #include <kxmlcore/FastMalloc.h>
 
 #endif
+
+#if !defined(WIN32) // can't get this to compile on Visual C++ yet
+#define AVOID_STATIC_CONSTRUCTORS 1
+#endif
index 487329a87379a9c6576faacb4904f6f8b0721c52..273adc00b45e5bc44daf609ef6d5b3aea37c12a4 100644 (file)
  *
  */
 
+#include "config.h"
+
+#if AVOID_STATIC_CONSTRUCTORS
 #define DOM_EVENT_NAMES_HIDE_GLOBALS 1
+#endif
 
-#include "config.h"
 #include "EventNames.h"
+#include "StaticConstructors.h"
 
-using DOM::AtomicString;
-using DOM::nullAtom;
-
-namespace DOM { namespace EventNames {
+using WebCore::AtomicString;
+using WebCore::nullAtom;
 
-// Initialize explicitly to avoid static initialization.
+namespace WebCore { namespace EventNames {
 
-#define DEFINE_GLOBAL(name) void *name##Event[(sizeof(AtomicString) + sizeof(void *) - 1) / sizeof(void *)];
-DOM_EVENT_NAMES_FOR_EACH(DEFINE_GLOBAL)
+#define DEFINE_EVENT_GLOBAL(name) \
+    DEFINE_GLOBAL(AtomicString, name##Event, #name)
+DOM_EVENT_NAMES_FOR_EACH(DEFINE_EVENT_GLOBAL)
 
 void init()
 {
+#if AVOID_STATIC_CONSTRUCTORS
     static bool initialized;
     if (!initialized) {
         // Use placement new to initialize the globals.
@@ -44,6 +48,7 @@ void init()
         DOM_EVENT_NAMES_FOR_EACH(INITIALIZE_GLOBAL)
         initialized = true;
     }
+#endif
 }
 
 } }
index 626967e0a3c3149be895376d5799bfed12ae3407..a9f434b737a9ae538711d96434ab1ed5aa8f80f7 100644 (file)
  *
  */
 
-#ifndef DOM_EVENT_NAMES_H
-#define DOM_EVENT_NAMES_H
+#ifndef EVENT_NAMES_H
+#define EVENT_NAMES_H
 
 #include "AtomicString.h"
 
-namespace DOM { namespace EventNames {
+namespace WebCore { namespace EventNames {
 
 #define DOM_EVENT_NAMES_FOR_EACH(macro) \
     \
@@ -94,7 +94,7 @@ namespace DOM { namespace EventNames {
 // end of DOM_EVENT_NAMES_FOR_EACH
 
 #if !DOM_EVENT_NAMES_HIDE_GLOBALS
-    #define DOM_EVENT_NAMES_DECLARE(name) extern AtomicString name##Event;
+    #define DOM_EVENT_NAMES_DECLARE(name) extern const AtomicString name##Event;
     DOM_EVENT_NAMES_FOR_EACH(DOM_EVENT_NAMES_DECLARE)
     #undef DOM_EVENT_NAMES_DECLARE
 #endif
index 07ca4fd4abca3612b414dbc3c5f39eee7ba88588..b1a734ef44f029767a1ad67b28d61ab34b3122b2 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
+#include "config.h"
+
+#if AVOID_STATIC_CONSTRUCTORS
 #define KHTML_QNAME_HIDE_GLOBALS 1
+#endif
 
-#include "config.h"
 #include "dom_qname.h"
+#include "StaticConstructors.h"
 #include <kxmlcore/HashSet.h>
 
-namespace DOM {
+namespace WebCore {
 
 struct QualifiedNameComponents {
     DOMStringImpl *m_prefix;
@@ -166,16 +170,18 @@ DOMString QualifiedName::toString() const
 }
 
 // Global init routines
-void* anyName[(sizeof(QualifiedName) + sizeof(void*) - 1) / sizeof(void*)];
+DEFINE_GLOBAL(QualifiedName, anyName, nullAtom, starAtom, starAtom);
 
 void QualifiedName::init()
 {
+#if AVOID_STATIC_CONSTRUCTORS
     static bool initialized;
     if (!initialized) {
         // Use placement new to initialize the globals.
         new (&anyName) QualifiedName(nullAtom, starAtom, starAtom);
         initialized = true;
     }
+#endif
 }
 
 }
index 163fd7b8aeb30b36276d540e363d01f12f817f39..a7a7503014da441c1b894b7878919b63c3d5f22c 100644 (file)
  * Boston, MA 02111-1307, USA.
  *
  */
-#ifndef _DOM_QNAME_h_
-#define _DOM_QNAME_h_
+#ifndef QualifiedName_h
+#define QualifiedName_h
 
 #include "AtomicString.h"
 
-namespace DOM {
+namespace WebCore {
 
 class QualifiedName {
 public:
index a0b9ddc99d559885b94710c8cb571d0850f1c078..8e68105478a28b9eb0fe8f7a9d5279b676715596 100644 (file)
  *
  */
 
-#define DOM_HTMLNAMES_HIDE_GLOBALS 1
-
 #include "config.h"
-#include "htmlnames.h"
 
-namespace DOM { namespace HTMLNames {
+#if AVOID_STATIC_CONSTRUCTORS
+#define DOM_HTMLNAMES_HIDE_GLOBALS 1
+#endif
 
-// Define a properly-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.
+#include "htmlnames.h"
+#include "StaticConstructors.h"
 
-#define DEFINE_UNINITIALIZED_GLOBAL(type, name) void *name[(sizeof(type) + sizeof(void *) - 1) / sizeof(void *)];
+namespace WebCore { namespace HTMLNames {
 
-DEFINE_UNINITIALIZED_GLOBAL(AtomicString, xhtmlNamespaceURI)
+DEFINE_GLOBAL(AtomicString, xhtmlNamespaceURI, "http://www.w3.org/1999/xhtml")
 
-#define DEFINE_TAG_GLOBAL(name) DEFINE_UNINITIALIZED_GLOBAL(QualifiedName, name##Tag)
+#define DEFINE_TAG_GLOBAL(name) \
+    DEFINE_GLOBAL(QualifiedName, name##Tag, nullAtom, #name, xhtmlNamespaceURI)
 DOM_HTMLNAMES_FOR_EACH_TAG(DEFINE_TAG_GLOBAL)
 
-#define DEFINE_ATTR_GLOBAL(name) DEFINE_UNINITIALIZED_GLOBAL(QualifiedName, name##Attr)
+#define DEFINE_ATTR_GLOBAL(name) \
+    DEFINE_GLOBAL(QualifiedName, name##Attr, nullAtom, #name, nullAtom)
 DOM_HTMLNAMES_FOR_EACH_ATTR(DEFINE_ATTR_GLOBAL)
 
 void init()
 {
     static bool initialized;
     if (!initialized) {
+#if AVOID_STATIC_CONSTRUCTORS
         // Use placement new to initialize the globals.
 
         AtomicString xhtmlNS("http://www.w3.org/1999/xhtml");
@@ -63,7 +65,10 @@ void init()
         http_equivAttrString = "http-equiv";
         #define INITIALIZE_ATTR_GLOBAL(name) new (&name##Attr) QualifiedName(nullAtom, name##AttrString, nullAtom);
         DOM_HTMLNAMES_FOR_EACH_ATTR(INITIALIZE_ATTR_GLOBAL)
-
+#else
+        const_cast<QualifiedName&>(accept_charsetAttr) = QualifiedName(nullAtom, "accept-charset", nullAtom);
+        const_cast<QualifiedName&>(http_equivAttr) = QualifiedName(nullAtom, "http-equiv", nullAtom);
+#endif
         initialized = true;
     }
 }
index 695ca0483f0d2de7ce2070829740e888bf2a1527..d225b4b678d0002ee475a27ecd13a91efc6aedea 100644 (file)
  * Boston, MA 02111-1307, USA.
  *
  */
-#ifndef DOM_HTMLNAMES_H
-#define DOM_HTMLNAMES_H
+#ifndef HTMLNAMES_H
+#define HTMLNAMES_H
 
 #include "dom_qname.h"
 
-namespace DOM { namespace HTMLNames {
+namespace WebCore { namespace HTMLNames {
 
 #define DOM_HTMLNAMES_FOR_EACH_TAG(macro) \
     macro(a) \
index 58bb1999c36ae0f21b55f2bf293a3cfb1a1a268c..c5c0de415d973c80ddbf0464c15b6be2b4f20db5 100644 (file)
  *
  */
 
-// For KHTML 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.
+#include "config.h"
 
+#if AVOID_STATIC_CONSTRUCTORS
 #define KHTML_ATOMICSTRING_HIDE_GLOBALS 1
+#endif
 
-#include "config.h"
 #include "AtomicString.h"
+#include "StaticConstructors.h"
 
 #include <kxmlcore/HashSet.h>
 
-namespace DOM {
+namespace WebCore {
    
 static HashSet<StringImpl*>* stringTable;
 
@@ -159,19 +157,19 @@ void AtomicString::remove(StringImpl* r)
     stringTable->remove(r);
 }
 
-// Define an AtomicString-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) \
-    void* name ## Atom[(sizeof(AtomicString) + sizeof(void*) - 1) / sizeof(void*)];
-
-DEFINE_GLOBAL(null)
-DEFINE_GLOBAL(empty)
-DEFINE_GLOBAL(text)
-DEFINE_GLOBAL(comment)
-DEFINE_GLOBAL(star)
+#if AVOID_STATIC_CONSTRUCTORS
+DEFINE_GLOBAL(AtomicString, nullAtom)
+#else
+const AtomicString nullAtom;
+#endif
+DEFINE_GLOBAL(AtomicString, emptyAtom, "")
+DEFINE_GLOBAL(AtomicString, textAtom, "#text")
+DEFINE_GLOBAL(AtomicString, commentAtom, "#comment")
+DEFINE_GLOBAL(AtomicString, starAtom, "*")
 
 void AtomicString::init()
 {
+#if AVOID_STATIC_CONSTRUCTORS
     static bool initialized;
     if (!initialized) {
         stringTable = new HashSet<StringImpl*>;
@@ -185,6 +183,7 @@ void AtomicString::init()
 
         initialized = true;
     }
+#endif
 }
 
 }
diff --git a/WebCore/platform/StaticConstructors.h b/WebCore/platform/StaticConstructors.h
new file mode 100644 (file)
index 0000000..0d2d8a6
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * This file is part of the DOM implementation for KDE.
+ *
+ * Copyright (C) 2006 Apple Computer, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+// For WebCore we need to avoid having static constructors.\r
+// Our strategy is to declare the global objects with a different type (initialized to 0)\r
+// and then use placement new to initialize the global objects later. This is not completely\r
+// portable, and it would be good to figure out a 100% clean way that still avoids code that\r
+// runs at init time.
+
+#if !AVOID_STATIC_CONSTRUCTORS
+    // Define an global in the normal way.
+#define DEFINE_GLOBAL(type, name, ...) \
+    const type name(__VA_ARGS__);
+#else
+// Define an correctly-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(type, name, ...) \
+    void * name[(sizeof(type) + sizeof(void *) - 1) / sizeof(void *)];
+#endif