-
Notifications
You must be signed in to change notification settings - Fork 11
Availability attribute support #51
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
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/src/syntax.jl b/src/syntax.jl
index d447fed..fd07371 100644
--- a/src/syntax.jl
+++ b/src/syntax.jl
@@ -290,7 +290,7 @@ macro objcwrapper(ex...)
# parse kwargs
comparison = nothing
immutable = nothing
- availability = nothing
+ availability = nothing
for kw in kwargs
if kw isa Expr && kw.head == :(=)
kw, value = kw.args
@@ -300,8 +300,8 @@ macro objcwrapper(ex...)
elseif kw == :immutable
value isa Bool || wrappererror("immutable keyword argument must be a literal boolean")
immutable = value
- elseif kw == :availability
- availability = get_avail_exprs(__module__, value)
+ elseif kw == :availability
+ availability = get_avail_exprs(__module__, value)
else
wrappererror("unrecognized keyword argument: $kw")
end
@@ -311,7 +311,7 @@ macro objcwrapper(ex...)
end
immutable = something(immutable, true)
comparison = something(comparison, !immutable)
- availability = something(availability, PlatformAvailability(:macos, v"0"))
+ availability = something(availability, PlatformAvailability(:macos, v"0"))
# parse class definition
if Meta.isexpr(def, :(<:))
@@ -352,9 +352,9 @@ macro objcwrapper(ex...)
# add a pseudo constructor to the abstract type that also checks for nil pointers.
function $name(ptr::id)
- @static if !Sys.isapple() || ObjectiveC.is_unavailable($availability)
- throw($UnavailableError(Symbol($name), $availability))
- end
+ @static if !Sys.isapple() || ObjectiveC.is_unavailable($availability)
+ throw($UnavailableError(Symbol($name), $availability))
+ end
ptr == nil && throw(UndefRefError())
$instance(ptr) |
0e5fb25
to
6badbb7
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #51 +/- ##
==========================================
+ Coverage 71.91% 77.71% +5.79%
==========================================
Files 10 13 +3
Lines 769 987 +218
==========================================
+ Hits 553 767 +214
- Misses 216 220 +4 ☔ View full report in Codecov by Sentry. |
What about making this more generic than only checking against the macOS version, taking an arbitrary bool instead? Is there precedent for, say, platform-dependent attributes? If so, what about: availability = is_macos(v"15")
availability = (Sys.ARCH == :aarch64) |
I don't think there is precedence for this, I tried to have it behave like the clang attribute, and the only platform that supports both it and Julia is macOS. I'm not opposed to it, but this would leave the need for code in the
|
Did not mean to close |
The TOML could always use a more specific
I wonder if we could symbolize the condition:
That said, I'm totally fine with mimicking Clang and providing something more specific. I'd then mimic it somewhat closer though, also including the platform and introduced/deprecated/obsolete. Just spitballing, but what about: # in ObjectiveC.jl:
struct macOS
# ...
macOS(introduced::VersionNumber, deprecated=nothing, obsolete=nothing) = ...
end
# in user code
@objcwrapper availability = macOS(v"14") Foo <: Object
@objcwrapper availability = [macOS(introduced=v"14", deprecated=v"15")] Bar <: Object
|
1cf918b
to
6c95198
Compare
I went with the second option with lowercase Open to any suggestions to simplify the code but it works and would be fairly easy to extend with a new platform if ever needed.
|
f24ca87
to
1044bbc
Compare
Now based on #52 for the nightly fixes. |
1044bbc
to
809e5e5
Compare
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.
Looking good! Some suggestions for simplifying/generalizing the implementation, I'd properly support multiple platforms already by supporting both macOS
and Darwin
availability selectors.
Also lays the groundwork for future platforms if they ever support Julia
db5a400
to
7fa3fc1
Compare
I think this is ready to merge! |
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.
Nice! Couple of minor suggestions.
I also don't particularly like the negative is_unavailable
, but I guess that's how it's done in Clang?
I've applied your suggestions.
If it's okay with you, since this is internal, I'll make the change to |
#50