Skip to content

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

Merged
merged 3 commits into from
Jul 17, 2017
Merged

Better namespace support for XML #1052

merged 3 commits into from
Jul 17, 2017

Conversation

rothomp3
Copy link
Contributor

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

@alblue
Copy link
Contributor

alblue commented Jun 21, 2017

@swift-ci please test

@parkera parkera requested a review from Catfish-Man June 21, 2017 16:58
@rothomp3 rothomp3 force-pushed the master branch 3 times, most recently from 8b810ba to 1b57b3b Compare June 28, 2017 18:22
@rothomp3 rothomp3 force-pushed the master branch 2 times, most recently from 5f59dbd to 3ba5d43 Compare July 4, 2017 17:38
@rothomp3 rothomp3 force-pushed the master branch 2 times, most recently from 6c43bab to 8014229 Compare July 10, 2017 14:24
@@ -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);
Copy link
Contributor

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�?

Copy link
Contributor Author

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"
Copy link
Contributor

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

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@alblue
Copy link
Contributor

alblue commented Jul 12, 2017

@swift-ci please test

1 similar comment
@alblue
Copy link
Contributor

alblue commented Jul 13, 2017

@swift-ci please test

Copy link
Contributor

@phausler phausler left a 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) {
Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Robert Thompson added 2 commits July 17, 2017 12:57
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.
@parkera
Copy link
Contributor

parkera commented Jul 17, 2017

@swift-ci test and merge

@swift-ci swift-ci merged commit ddcbfec into swiftlang:master Jul 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants