From 9b2a622b103413f7b7752f6a663761f6c8b744bf Mon Sep 17 00:00:00 2001 From: Mario Vera Date: Tue, 22 May 2018 14:57:09 -0700 Subject: [PATCH 1/4] Avoid runtime pitfalls by removing undefined behaviour. --- CoreFoundation/Base.subproj/CFPlatform.c | 1 + CoreFoundation/Base.subproj/CFUtilities.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CoreFoundation/Base.subproj/CFPlatform.c b/CoreFoundation/Base.subproj/CFPlatform.c index 97b7d1222e..246096df66 100644 --- a/CoreFoundation/Base.subproj/CFPlatform.c +++ b/CoreFoundation/Base.subproj/CFPlatform.c @@ -628,6 +628,7 @@ 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); diff --git a/CoreFoundation/Base.subproj/CFUtilities.c b/CoreFoundation/Base.subproj/CFUtilities.c index c7f90cc65d..4fb8d1a30e 100644 --- a/CoreFoundation/Base.subproj/CFUtilities.c +++ b/CoreFoundation/Base.subproj/CFUtilities.c @@ -658,7 +658,7 @@ static void _CFShowToFile(FILE *file, Boolean flush, const void *obj) { #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI fprintf_l(file, NULL, "\n"); #else - fprintf(file, NULL, "\n"); + fprintf(file, "\n"); #endif if (flush) fflush(file); } From 87c2287b8bbe93613b56f3c1834abbab3418d325 Mon Sep 17 00:00:00 2001 From: Mario Vera Date: Thu, 24 May 2018 13:00:17 -0700 Subject: [PATCH 2/4] Tony feedback: Call __CFTSDInitialize from __CFInitialize --- CoreFoundation/Base.subproj/CFPlatform.c | 1 - CoreFoundation/Base.subproj/CFRuntime.c | 4 ++-- CoreFoundation/Locale.subproj/CFCalendar.c | 1 + CoreFoundation/Locale.subproj/CFLocale.c | 1 + CoreFoundation/Parsing.subproj/CFXMLInterface.c | 13 ++++++++++++- CoreFoundation/build.py | 2 +- lib/script.py | 10 +++++++++- 7 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CoreFoundation/Base.subproj/CFPlatform.c b/CoreFoundation/Base.subproj/CFPlatform.c index 246096df66..97b7d1222e 100644 --- a/CoreFoundation/Base.subproj/CFPlatform.c +++ b/CoreFoundation/Base.subproj/CFPlatform.c @@ -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); diff --git a/CoreFoundation/Base.subproj/CFRuntime.c b/CoreFoundation/Base.subproj/CFRuntime.c index 386770b241..26fc202c21 100644 --- a/CoreFoundation/Base.subproj/CFRuntime.c +++ b/CoreFoundation/Base.subproj/CFRuntime.c @@ -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 @@ -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; diff --git a/CoreFoundation/Locale.subproj/CFCalendar.c b/CoreFoundation/Locale.subproj/CFCalendar.c index 5332e96dbc..d02cf4b7cb 100644 --- a/CoreFoundation/Locale.subproj/CFCalendar.c +++ b/CoreFoundation/Locale.subproj/CFCalendar.c @@ -10,6 +10,7 @@ #include +#include #include #include "CFInternal.h" #include "CFPriv.h" diff --git a/CoreFoundation/Locale.subproj/CFLocale.c b/CoreFoundation/Locale.subproj/CFLocale.c index 10013909c9..78b072a8df 100644 --- a/CoreFoundation/Locale.subproj/CFLocale.c +++ b/CoreFoundation/Locale.subproj/CFLocale.c @@ -10,6 +10,7 @@ // Note the header file is in the OpenSource set (stripped to almost nothing), but not the .c file +#include #include #include #include diff --git a/CoreFoundation/Parsing.subproj/CFXMLInterface.c b/CoreFoundation/Parsing.subproj/CFXMLInterface.c index f48c1e4c76..fcd4b0131f 100644 --- a/CoreFoundation/Parsing.subproj/CFXMLInterface.c +++ b/CoreFoundation/Parsing.subproj/CFXMLInterface.c @@ -12,6 +12,7 @@ */ #include +#include #include #include #include @@ -22,7 +23,7 @@ #include #include #include -#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. @@ -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) { @@ -119,8 +121,10 @@ 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(); @@ -128,21 +132,25 @@ void _CFSetupXMLInterface(void) { __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; @@ -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; } diff --git a/CoreFoundation/build.py b/CoreFoundation/build.py index 046babba09..c105fc0782 100755 --- a/CoreFoundation/build.py +++ b/CoreFoundation/build.py @@ -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) diff --git a/lib/script.py b/lib/script.py index 27948f321e..16a170095b 100644 --- a/lib/script.py +++ b/lib/script.py @@ -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 += """ From 5d0da08f356730316a26c88efe6d0ab371f54fb5 Mon Sep 17 00:00:00 2001 From: Mario Vera Date: Fri, 25 May 2018 16:17:44 -0700 Subject: [PATCH 3/4] Lily feedback: Undo changes not relevant to runtime behaviour. --- CoreFoundation/Locale.subproj/CFCalendar.c | 1 - CoreFoundation/Locale.subproj/CFLocale.c | 1 - CoreFoundation/Parsing.subproj/CFXMLInterface.c | 13 +------------ CoreFoundation/build.py | 2 +- 4 files changed, 2 insertions(+), 15 deletions(-) diff --git a/CoreFoundation/Locale.subproj/CFCalendar.c b/CoreFoundation/Locale.subproj/CFCalendar.c index d02cf4b7cb..5332e96dbc 100644 --- a/CoreFoundation/Locale.subproj/CFCalendar.c +++ b/CoreFoundation/Locale.subproj/CFCalendar.c @@ -10,7 +10,6 @@ #include -#include #include #include "CFInternal.h" #include "CFPriv.h" diff --git a/CoreFoundation/Locale.subproj/CFLocale.c b/CoreFoundation/Locale.subproj/CFLocale.c index 78b072a8df..10013909c9 100644 --- a/CoreFoundation/Locale.subproj/CFLocale.c +++ b/CoreFoundation/Locale.subproj/CFLocale.c @@ -10,7 +10,6 @@ // Note the header file is in the OpenSource set (stripped to almost nothing), but not the .c file -#include #include #include #include diff --git a/CoreFoundation/Parsing.subproj/CFXMLInterface.c b/CoreFoundation/Parsing.subproj/CFXMLInterface.c index fcd4b0131f..f48c1e4c76 100644 --- a/CoreFoundation/Parsing.subproj/CFXMLInterface.c +++ b/CoreFoundation/Parsing.subproj/CFXMLInterface.c @@ -12,7 +12,6 @@ */ #include -#include #include #include #include @@ -23,7 +22,7 @@ #include #include #include -#include "CFXMLInterface.h" +#include "CFInternal.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. @@ -111,7 +110,6 @@ typedef struct { xmlNotationPtr notation; } _cfxmlNotation; -#if DEPLOYMENT_RUNTIME_SWIFT static xmlExternalEntityLoader __originalLoader = NULL; static xmlParserInputPtr _xmlExternalEntityLoader(const char *urlStr, const char * ID, xmlParserCtxtPtr context) { @@ -121,10 +119,8 @@ 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(); @@ -132,25 +128,21 @@ void _CFSetupXMLInterface(void) { __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; @@ -176,9 +168,6 @@ _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; } diff --git a/CoreFoundation/build.py b/CoreFoundation/build.py index c105fc0782..046babba09 100755 --- a/CoreFoundation/build.py +++ b/CoreFoundation/build.py @@ -293,7 +293,7 @@ 'String.subproj/CFRegularExpression.c', 'String.subproj/CFAttributedString.c', 'String.subproj/CFRunArray.c', - 'Base.subproj/CFKnownLocations.c', + 'Base.subproj/CFKnownLocations.h', ] sources = CompileSources(sources_list) From 93453867acada8aec5c5b2b284e3837116364b0f Mon Sep 17 00:00:00 2001 From: Mario Vera Date: Fri, 25 May 2018 16:19:15 -0700 Subject: [PATCH 4/4] Lily feedback: Undo changes not relevant to runtime behaviour. --- lib/script.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/script.py b/lib/script.py index 16a170095b..27948f321e 100644 --- a/lib/script.py +++ b/lib/script.py @@ -226,15 +226,7 @@ def generate_products(self): script = flags + commands for product in self.products: - 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 += product.generate() script += """