-
Notifications
You must be signed in to change notification settings - Fork 30
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Handle nil #4
Comments
I never considered that Swift allowed nil values 😅 |
@Brendonovich I am not quite sure what you mean. In my case, the swift function is defined kind of like this: @_cdecl("get_foo")
public func getFoo() -> Foo? {} So, the returned object itself is nullable. I tried this: #[link(name = "myfoolib")]
extern "C" {
fn get_foo() -> SRObject<Option<FooObjc>>;
} But this causes a segfault when I dereference the SRObject and nil was returned from swift |
I managed to get this working, but only once I created this type manually: #[repr(C)]
#[derive(Debug)]
enum NullablePtr<T> {
Null,
NonNull(T),
} Then I could define the linked function like this: #[link(name = "myfoolib")]
extern "C" {
fn get_foo() -> NullablePtr<SRObject<FooObjc>>;
} |
@0rvar The solution I outlined was to do with the internals of SRObject, in your case all that would be required is giving |
|
How do I handle nil returned from a swift function?
The
*const
pointer inSRObject
is private, so I can't checkresult.0.is_null()
. Any other option?EDIT: Opened a PR: #5
The text was updated successfully, but these errors were encountered: