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

Seemingly incorrect warning for Foundation enums #1817

Open
stuartmorgan opened this issue Dec 17, 2024 · 2 comments
Open

Seemingly incorrect warning for Foundation enums #1817

stuartmorgan opened this issue Dec 17, 2024 · 2 comments

Comments

@stuartmorgan
Copy link

stuartmorgan commented Dec 17, 2024

I tried converting path_provider_foundation (the simplest of our plugins) to FFI, and immediately hit:

[SEVERE] : The integer type used for enums is implementation-defined. FFIgen tries to mimic the integer sizes chosen by the most common compilers for the various OS and architecture combinations. To prevent any crashes, remove the enums from your API surface. To rely on the (unsafe!) mimicking, you can silence this warning by adding silence-enum-warning: true to the FFIgen config. Affected enums:
	NSDirectoryEnumerationOptions
	NSFileManagerItemReplacementOptions
	NSFileManagerUnmountOptions
	NSSearchPathDirectory
	NSSearchPathDomainMask
	NSURLRelationship
	NSVolumeEnumerationOptions

I need both NSSearchPathDirectory and NSSearchPathDomainMask, I don't control the APIs in question, and I don't want to ship something that is "unsafe!" to clients, so this would be a hard blocker on a pure-Dart implementation. However, the message doesn't seem to match the definitions:

typedef NS_ENUM(NSUInteger, NSSearchPathDirectory) {
  ...
};

typedef NS_OPTIONS(NSUInteger, NSSearchPathDomainMask) {
  ...
};

Isn't that a clearly defined integer type?

@liamappelbe
Copy link
Contributor

I think the issue is that this int can be 32 or 64 bit depending on the architecture. That message might be a bit overzealous though, since FFI has ABI specific integers. Presumably it would be pretty safe for ffigen to just use UnisgnedInt here.

@dcharkes @mannprerak2 I read the original PR, and it seems like the issue is mainly on Windows, where there's a disagreement about whether it's an int or a uint. Maybe we just disable this warning if the language is set to ObjC, since we know the target platform is Mac? Or is there some other reason this is unsafe?

@dcharkes
Copy link
Collaborator

I think the issue is that this int can be 32 or 64 bit depending on the architecture. That message might be a bit overzealous though, since FFI has ABI specific integers. Presumably it would be pretty safe for ffigen to just use UnisgnedInt here.

If I remember correctly, enums are always 32 bits.

@dcharkes @mannprerak2 I read the original PR, and it seems like the issue is mainly on Windows, where there's a disagreement about whether it's an int or a uint. Maybe we just disable this warning if the language is set to ObjC, since we know the target platform is Mac? Or is there some other reason this is unsafe?

Yeah, the issue is mostly for enums that have values defined outside their range if that upgrades the int to different size or sign than the declared int side. And yes, we only observed this on Windows. MacOS/iOS should be consistent with itself since it's always the Apple clang compiler. So skipping the warning for language ObjC sgtm. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

3 participants