-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Build Foundation with DEPLOYMENT_RUNTIME_SWIFT disabled #1559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
*/ | ||
|
||
#include <CoreFoundation/CFRuntime.h> | ||
#include <CoreFoundation/CFInternal.h> | ||
#include <libxml/globals.h> | ||
#include <libxml/xmlerror.h> | ||
#include <libxml/parser.h> | ||
|
@@ -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. | ||
|
@@ -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,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; | ||
|
||
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't the calloc above already promise us zeroed memory? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, this line is not needed, I'll remove it. |
||
#endif //if DEPLOYMENT_RUNTIME_SWIFT | ||
return saxHandler; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain a bit more about what this is doing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add Lily to review this one. script is a string. items is a list containing strings and lists. On python 2.7 we can not append a list into a string, so we need to walk it, appending the strings on the array. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @millenomi There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC: This path is triggered by the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can also fix that command to add single items instead of a list. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, for context: this is the portion of build.py that is triggering that behavior: # This code is already in libdispatch so is only needed if libdispatch is
# NOT being used
if "LIBDISPATCH_SOURCE_DIR" not in Configuration.current.variables:
sources += (['closure/data.c', 'closure/runtime.c']) It'd be nice to fix this bit, but in general you want to set your There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Applying LIBDISPATCH_SOURCE_DIR did not work for me. I just auggested a more pythonic way of applying the product commands... hopefully that is better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, I'm compiling from within CoreFoundation, so the build.py I'm using is in CoreFoundation/build.py, that scripts do not have any references to LIBDISPATCH_SOURCE_DIR. |
||
|
||
script += """ | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we don't use CFInternal.h here at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't removed, it moved up & uses qualified path. Check line 15: <CoreFoundation/CFInternal.h>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks. Misread the diff.