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

[ffigen] Array globals are broken #1922

Open
dcharkes opened this issue Jan 22, 2025 · 1 comment
Open

[ffigen] Array globals are broken #1922

dcharkes opened this issue Jan 22, 2025 · 1 comment
Labels
contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) package:ffigen

Comments

@dcharkes
Copy link
Collaborator

It's a bug in ffigen and should be reported at https://github.com/dart-lang/native/issues/new (I can't transfer the issue because it is in the different org).

The bug is that this is not correct:

ate final ffi.Pointer<ffi.Pointer<ffi.Int>> _globals =
      _lookup<ffi.Pointer<ffi.Int>>('globals');

ffigen incorrectly added a level of indirection. Symbol globals will be pointing to the start of the array, not to the pointer which pointer to the array. It seems that ffigen incorrectly applies array-to-pointer decay here and treats extern int globals[] as it would treat extern int* globals.

Originally posted by @mraleph in #161987

cc @mannprerak2

@dcharkes dcharkes added contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) package:ffigen labels Jan 22, 2025
@mannprerak2
Copy link
Contributor

I think we missed testing specifically for

extern int globals[] (and till now I thought it is the same as extern int* globals)

So we add an extra pointer redirection like any other global var.

Looks like an easy fix though, I'm a little busy this week but I'll try making a PR for this as soon as I can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) package:ffigen
Projects
None yet
Development

No branches or pull requests

2 participants