Skip to content

Commit

Permalink
Tony feedback: Call __CFTSDInitialize from __CFInitialize
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-vera committed May 24, 2018
1 parent 9b2a622 commit 87c2287
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 6 deletions.
1 change: 0 additions & 1 deletion CoreFoundation/Base.subproj/CFPlatform.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,6 @@ static void *__CFTSDGetSpecific() {
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
return pthread_getspecific(__CFTSDIndexKey);
#elif DEPLOYMENT_TARGET_LINUX
__CFTSDInitialize();
return pthread_getspecific(__CFTSDIndexKey);
#elif DEPLOYMENT_TARGET_WINDOWS
return TlsGetValue(__CFTSDIndexKey);
Expand Down
4 changes: 2 additions & 2 deletions CoreFoundation/Base.subproj/CFRuntime.c
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ extern void __CFNumberInitialize(void);
extern void __CFCharacterSetInitialize(void);
extern void __CFPFactoryInitialize(void);
extern void __CFPlugInInitialize(void);
#if (DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_MACOSX) && DEPLOYMENT_RUNTIME_SWIFT
#if DEPLOYMENT_TARGET_LINUX || (DEPLOYMENT_TARGET_MACOSX && DEPLOYMENT_RUNTIME_SWIFT)
CF_PRIVATE void __CFTSDInitialize(void);
#endif
#if DEPLOYMENT_TARGET_WINDOWS
Expand Down Expand Up @@ -1076,7 +1076,7 @@ void __CFInitialize(void) {
#if DEPLOYMENT_TARGET_WINDOWS
// Must not call any CF functions
__CFTSDWindowsInitialize();
#elif (DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_MACOSX) && DEPLOYMENT_RUNTIME_SWIFT
#elif DEPLOYMENT_TARGET_LINUX || (DEPLOYMENT_TARGET_MACOSX && DEPLOYMENT_RUNTIME_SWIFT)
__CFTSDInitialize();
#endif
__CFProphylacticAutofsAccess = true;
Expand Down
1 change: 1 addition & 0 deletions CoreFoundation/Locale.subproj/CFCalendar.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


#include <CoreFoundation/CFCalendar.h>
#include <CoreFoundation/CFLocaleInternal.h>
#include <CoreFoundation/CFRuntime.h>
#include "CFInternal.h"
#include "CFPriv.h"
Expand Down
1 change: 1 addition & 0 deletions CoreFoundation/Locale.subproj/CFLocale.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// Note the header file is in the OpenSource set (stripped to almost nothing), but not the .c file

#include <CoreFoundation/CFInternal.h>
#include <CoreFoundation/CFLocale.h>
#include <CoreFoundation/CFLocale_Private.h>
#include <CoreFoundation/CFString.h>
Expand Down
13 changes: 12 additions & 1 deletion CoreFoundation/Parsing.subproj/CFXMLInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

#include <CoreFoundation/CFRuntime.h>
#include <CoreFoundation/CFInternal.h>
#include <libxml/globals.h>
#include <libxml/xmlerror.h>
#include <libxml/parser.h>
Expand All @@ -22,7 +23,7 @@
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include <libxml/dict.h>
#include "CFInternal.h"
#include "CFXMLInterface.h"

/*
libxml2 does not have nullability annotations and does not import well into swift when given potentially differing versions of the library that might be installed on the host operating system. This is a simple C wrapper to simplify some of that interface layer to libxml2.
Expand Down Expand Up @@ -110,6 +111,7 @@ typedef struct {
xmlNotationPtr notation;
} _cfxmlNotation;

#if DEPLOYMENT_RUNTIME_SWIFT
static xmlExternalEntityLoader __originalLoader = NULL;

static xmlParserInputPtr _xmlExternalEntityLoader(const char *urlStr, const char * ID, xmlParserCtxtPtr context) {
Expand All @@ -119,30 +121,36 @@ static xmlParserInputPtr _xmlExternalEntityLoader(const char *urlStr, const char
}
return __originalLoader(urlStr, ID, context);
}
#endif // DEPLOYMENT_RUNTIME_SWIFT

void _CFSetupXMLInterface(void) {
#if DEPLOYMENT_RUNTIME_SWIFT
static dispatch_once_t xmlInitGuard;
dispatch_once(&xmlInitGuard, ^{
xmlInitParser();
// set up the external entity loader
__originalLoader = xmlGetExternalEntityLoader();
xmlSetExternalEntityLoader(_xmlExternalEntityLoader);
});
#endif // DEPLOYMENT_RUNTIME_SWIFT
}

_CFXMLInterfaceParserInput _CFXMLInterfaceNoNetExternalEntityLoader(const char *URL, const char *ID, _CFXMLInterfaceParserContext ctxt) {
return xmlNoNetExternalEntityLoader(URL, ID, ctxt);
}

#if DEPLOYMENT_RUNTIME_SWIFT
static void _errorCallback(void *ctx, const char *msg, ...) {
xmlParserCtxtPtr context = __CFSwiftBridge.NSXMLParser.getContext((_CFXMLInterface)ctx);
xmlErrorPtr error = xmlCtxtGetLastError(context);
// TODO: reporting
// _reportError(error, (_CFXMLInterface)ctx);
}
#endif // DEPLOYMENT_RUNTIME_SWIFT

_CFXMLInterfaceSAXHandler _CFXMLInterfaceCreateSAXHandler() {
_CFXMLInterfaceSAXHandler saxHandler = (_CFXMLInterfaceSAXHandler)calloc(1, sizeof(struct _xmlSAXHandler));
#if DEPLOYMENT_RUNTIME_SWIFT
saxHandler->internalSubset = (internalSubsetSAXFunc)__CFSwiftBridge.NSXMLParser.internalSubset;
saxHandler->isStandalone = (isStandaloneSAXFunc)__CFSwiftBridge.NSXMLParser.isStandalone;

Expand All @@ -168,6 +176,9 @@ _CFXMLInterfaceSAXHandler _CFXMLInterfaceCreateSAXHandler() {
saxHandler->externalSubset = (externalSubsetSAXFunc)__CFSwiftBridge.NSXMLParser.externalSubset;

saxHandler->initialized = XML_SAX2_MAGIC; // make sure start/endElementNS are used
#else
memset(&saxHandler, 0, sizeof(saxHandler));
#endif //if DEPLOYMENT_RUNTIME_SWIFT
return saxHandler;
}

Expand Down
2 changes: 1 addition & 1 deletion CoreFoundation/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
'String.subproj/CFRegularExpression.c',
'String.subproj/CFAttributedString.c',
'String.subproj/CFRunArray.c',
'Base.subproj/CFKnownLocations.h',
'Base.subproj/CFKnownLocations.c',
]

sources = CompileSources(sources_list)
Expand Down
10 changes: 9 additions & 1 deletion lib/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,15 @@ def generate_products(self):
script = flags + commands

for product in self.products:
script += product.generate()
items = product.generate()
for item in items:
if isinstance(item, list):
for subitem in item:
#TODO: What to do with this elements?
#script += subitem
continue
else:
script += item

script += """
Expand Down

0 comments on commit 87c2287

Please sign in to comment.