Skip to content
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

[SR-9597] DispatchData.copyBytes allocates #627

Open
weissi opened this issue Jan 3, 2019 · 5 comments
Open

[SR-9597] DispatchData.copyBytes allocates #627

weissi opened this issue Jan 3, 2019 · 5 comments

Comments

@weissi
Copy link
Member

weissi commented Jan 3, 2019

Previous ID SR-9597
Radar rdar://problem/52529586
Original Reporter @weissi
Type Bug
Additional Detail from JIRA
Votes 0
Component/s libdispatch
Labels Bug
Assignee None
Priority Medium

md5: 63ced7a174d79c5fd0d6f317c1e088e1

Issue Description:

every method I can see to copy bytes out of a DispatchData into some other container of bytes allocates.

DispatchData.copyBytes looks really benign but internally calls (https://github.com/apple/swift-corelibs-libdispatch/blob/9c48a809693b78bd5ad89718c6f9712aaa1cfb1e/src/swift/Data.swift#L221) _copyBytesHelper which calls CDispatch.dispatch_data_apply which needs a closure. That closure has a non-nil context pointer and therefore allocates.

Possible solutions:

  • fix SR-904

  • make enough things inlinable/usableFromInline that we don't actually need to create a proper closure

CC @jckarter, phabouzit (JIRA User), @phausler, @parkera, phabouzit (JIRA User)

@jckarter
Copy link
Member

jckarter commented Jan 3, 2019

Sounds like a dup of SR-904. aschwaighofer@apple.com (JIRA User) are you still working on that?

@weissi
Copy link
Member Author

weissi commented Jan 3, 2019

@jckarter well, kind of a dup. It would certainly be possible to implement DispatchData.copyBytes without using any closures. But fixing SR-904 would obviously be the most awesome fix and it would fix so many other similarly surprising issues too.

@jckarter
Copy link
Member

jckarter commented Jan 3, 2019

If it doesn't overly uglify the implementation, sure.

@weissi
Copy link
Member Author

weissi commented Jan 3, 2019

@jckarter don't get me wrong, I would love for SR-904 to be fixed. I didn't file it as a dupe because I wan't sure if SR-904 will be fixed soon and I still think that DispatchData must be able to copy the bytes out of itself without allocating, regardless of Swift's ability to allocate non-escaping closures on the heap. But if fixing SR-904 is the fix to this bug I'll be very very happy 🙂

@weissi
Copy link
Member Author

weissi commented Jul 2, 2019

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants