Ignore:
Timestamp:
Apr 28, 2009, 11:57:58 AM (16 years ago)
Author:
[email protected]
Message:

Work around <rdar://problem/6833240> by relying on static initialization to zero the entire struct.
This removes the need for us to explicitly initialize all of the members, which have a tendency
to change in meaning and number between versions of libxml2.

Reviewed by Sam Weinig.

  • dom/XMLTokenizerLibxml2.cpp:

(WebCore::):
(WebCore::sharedXHTMLEntity):
(WebCore::getXHTMLEntity):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/dom/XMLTokenizerLibxml2.cpp

    r42738 r42945  
    10651065}
    10661066
    1067 // Using a global variable entity and marking it XML_INTERNAL_PREDEFINED_ENTITY is
     1067// Using a static entity and marking it XML_INTERNAL_PREDEFINED_ENTITY is
    10681068// a hack to avoid malloc/free. Using a global variable like this could cause trouble
    10691069// if libxml implementation details were to change
    1070 static xmlChar sharedXHTMLEntityResult[5] = {0,0,0,0,0};
    1071 static xmlEntity sharedXHTMLEntity = {
    1072     0, XML_ENTITY_DECL, 0, 0, 0, 0, 0, 0, 0,
    1073     sharedXHTMLEntityResult, sharedXHTMLEntityResult, 0,
    1074     XML_INTERNAL_PREDEFINED_ENTITY, 0, 0, 0, 0, 0,
    1075 #if LIBXML_VERSION >= 20627
    1076     // xmlEntity gained an extra member in 2.6.27.
    1077     1
    1078 #endif
    1079 };
     1070static xmlChar sharedXHTMLEntityResult[5] = {0, 0, 0, 0, 0};
     1071
     1072static xmlEntityPtr sharedXHTMLEntity()
     1073{
     1074    static xmlEntity entity;
     1075    if (!entity.type) {
     1076        entity.type = XML_ENTITY_DECL;
     1077        entity.orig = sharedXHTMLEntityResult;
     1078        entity.content = sharedXHTMLEntityResult;
     1079        entity.etype = XML_INTERNAL_PREDEFINED_ENTITY;
     1080    }
     1081    return &entity;
     1082}
    10801083
    10811084static xmlEntityPtr getXHTMLEntity(const xmlChar* name)
     
    10871090    CString value = String(&c, 1).utf8();
    10881091    ASSERT(value.length() < 5);
    1089     sharedXHTMLEntity.length = value.length();
    1090     sharedXHTMLEntity.name = name;
    1091     memcpy(sharedXHTMLEntityResult, value.data(), sharedXHTMLEntity.length + 1);
    1092 
    1093     return &sharedXHTMLEntity;
     1092    xmlEntityPtr entity = sharedXHTMLEntity();
     1093    entity->length = value.length();
     1094    entity->name = name;
     1095    memcpy(sharedXHTMLEntityResult, value.data(), entity->length + 1);
     1096
     1097    return entity;
    10941098}
    10951099
Note: See TracChangeset for help on using the changeset viewer.