-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Better namespace support for XML #1052
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
Conversation
@swift-ci please test |
8b810ba
to
1b57b3b
Compare
5f59dbd
to
3ba5d43
Compare
6c43bab
to
8014229
Compare
@@ -153,7 +153,7 @@ void _CFXMLNodeSetPrivateData(_CFXMLNodePtr node, void* data); | |||
void* _Nullable _CFXMLNodeGetPrivateData(_CFXMLNodePtr node); | |||
_CFXMLNodePtr _Nullable _CFXMLNodeProperties(_CFXMLNodePtr node); | |||
CFIndex _CFXMLNodeGetType(_CFXMLNodePtr node); | |||
const char* _Nullable _CFXMLNodeGetName(_CFXMLNodePtr node); | |||
CF_RETURNS_RETAINED CFStringRef _Nullable _CFXMLNodeGetName(_CFXMLNodePtr node); |
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.
For this and others - can we avoid the returns retained macro if we just follow the 'copy' convention, e.g.: _CFXMLNodeCopyName
�?
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.
Probably? I was mostly concerned with making extremely sure that Swift knew the correct retain count, because memory leaks are my personal crusade haha.
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
selectedDebuggerIdentifier = "" | ||
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn" |
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.
I think these two lines should be omitted from the PR
Foundation/NSXMLElement.swift
Outdated
public convenience init(xmlString string: String) throws { | ||
// If we prepend the XML line to the string | ||
let docString = """ | ||
<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\(string) |
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.
Mostly for my own education on the new triple-quote syntax: do we still need to backslash escape the quotes?
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.
Nope, sure don't, I'll fix that.
@swift-ci please test |
1 similar comment
@swift-ci please test |
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.
The only thing that absolutely needs to be changed is the returns retained on _CFXMLNamespaces
should be removed.
@@ -1179,6 +1236,131 @@ void _CFXMLDTDNodeSetPublicID(_CFXMLDTDNodePtr node, const unsigned char* public | |||
} | |||
} | |||
|
|||
// Namespaces | |||
_CFXMLNodePtr _Nonnull * _Nullable _CFXMLNamespaces(_CFXMLNodePtr node, CFIndex* count) { |
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.
we might wanna use a CFArrayRef here because this requires freeing the return value
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.
I actually tried that first, because it seemed like the right way to do it, but it crashed immediately on adding a _CFXMLNodePtr to the array. I wasn't able to figure out why, exactly, but I also didn't spend a long time trying.
void _CFXMLDTDNodeSetPublicID(_CFXMLDTDNodePtr node, const unsigned char* _Nullable publicID); | ||
|
||
// Namespaces | ||
CF_RETURNS_RETAINED _CFXMLNodePtr _Nonnull * _Nullable _CFXMLNamespaces(_CFXMLNodePtr node, CFIndex* count); |
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.
this is not retained, this is just returning allocated
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.
This is a relic of how I started off using CFArrayRef here. I would prefer to go back to that, I will see if the crash adding _CFXMLNodePtr still happens now.
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.
You would need to use custom retain and release methods on the structure pointer to use CFArrayRef but for managing the buffer it is probably safer I would say.
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.
eh, after thinking about it for a bit, perhaps the malloc'd buffer is better here because creating proper callbacks would mean that you would need to copy the backing pointers appropriately for the beyond the lifespan of the tree. tbh it might not be worth it if this is the only place that it is used.
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.
This is the only place it's used at the moment, and honestly anyone else should just call the Swift method that calls this one, so it should remain the only place.
Fix one place was still expecting C String XPath works with namespaces implement XMLElement(xmlString:) Add some tests, re-enable all tests Implement more namespaces support
Change names of CoreFoundation-level xml functions to better conform to CoreFoundation naming conventions, and eliminate thusly unnecessary CF_RETURNS_RETAINED macros.
@swift-ci test and merge |
So I wrote most of this to begin with, and when I went to actually try and use it for a little project (playing around with WebDAV), it crashed! Turns out I never went back and did namespace support. Well, here is more of (but still not all of) namespace support.
Fix one place was still expecting C String
XPath works with namespaces
implement XMLElement(xmlString:)
Add some tests, re-enable all tests
Implement more namespaces support