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

Minor NSArray improvements #26

Merged
merged 3 commits into from
Feb 14, 2024
Merged

Minor NSArray improvements #26

merged 3 commits into from
Feb 14, 2024

Conversation

maleadt
Copy link
Member

@maleadt maleadt commented Feb 14, 2024

Fixes #25

This prevents constructing invalid NSArray objects (and likely segfaulting) by both constraining the type signature, and by not using the questionable Ptr{id{Object}} type signature (id is already a pointer, and relying on Julia's Ptr leads to surprising automatic conversion from otherwise incompatible array values).

Copy link

codecov bot commented Feb 14, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (78659ba) 69.48% compared to head (8ffbf57) 69.68%.

Files Patch % Lines
src/syntax.jl 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #26      +/-   ##
==========================================
+ Coverage   69.48%   69.68%   +0.19%     
==========================================
  Files           9        9              
  Lines         626      630       +4     
==========================================
+ Hits          435      439       +4     
  Misses        191      191              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@maleadt
Copy link
Member Author

maleadt commented Feb 14, 2024

Test failures unrelated; looks like the dispatch tests are a little fragile.

@maleadt maleadt merged commit 44a5aae into master Feb 14, 2024
6 of 7 checks passed
@maleadt maleadt deleted the tb/nsarray branch February 14, 2024 21:20
Comment on lines +298 to +301
# XXX: it's too bad `cconvert` cannot do the `[pointer(obj) for obj in objs]` for us
# (because we can only derive unsafe references in `unsafe_convert`)
Base.unsafe_convert(T::Type{<:id}, ptrs::Vector{<:id}) =
reinterpret(T, pointer(ptrs))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, this is what Base.RefArray is for doing, as it will recursively derive a pointer for you after cconverting recursively

Copy link
Member Author

@maleadt maleadt Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, interesting, I figured something like that would exist already.
I think I'll have to copy the pattern though, as AFAIU RefArray only works to ultimately convert to a Ptr, while we're using a custom id pointer here.

EDIT: #27

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.

NSArray can be constructed with non-NSObjects, leading to segfaults
2 participants