+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.
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
#include <kxmlcore/FastMalloc.h>
#endif
+
+#if !defined(WIN32) // can't get this to compile on Visual C++ yet
+#define AVOID_STATIC_CONSTRUCTORS 1
+#endif
*
*/
+#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.
DOM_EVENT_NAMES_FOR_EACH(INITIALIZE_GLOBAL)
initialized = true;
}
+#endif
}
} }
*
*/
-#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) \
\
// 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
* 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;
}
// 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
}
}
* 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:
*
*/
-#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");
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;
}
}
* 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) \
*
*/
-// 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;
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*>;
initialized = true;
}
+#endif
}
}
--- /dev/null
+/*
+ * 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