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

ffi pattern matching for pointers in args is broken #651

Open
KaruroChori opened this issue Sep 20, 2024 · 9 comments
Open

ffi pattern matching for pointers in args is broken #651

KaruroChori opened this issue Sep 20, 2024 · 9 comments

Comments

@KaruroChori
Copy link
Contributor

KaruroChori commented Sep 20, 2024

For example, right now this signature:

int Fl_Window_x(Fl_Window *);

will generate as AST of its argument:

            {
                "kind": "vardef",
                "type": {
                    "kind": "type",
                    "typeModifiers": [],
                    "name": "Fl_Window",
                    "ptr": 0
                },
                "name": "*"
            }

in place of

            {
                "kind": "vardef",
                "type": {
                    "kind": "type",
                    "typeModifiers": [],
                    "name": "Fl_Window",
                    "ptr": 1
                },
                "name": ""
            }
@saghul
Copy link
Owner

saghul commented Sep 20, 2024

Ping @lal12 :-)

@lal12
Copy link
Contributor

lal12 commented Sep 20, 2024

It indeed doesn't like function prototypes without name. This isn't totally trivially fixable. I've thought for a while about using a PEG grammar based parser instead.

@saghul
Copy link
Owner

saghul commented Sep 20, 2024

So int Fl_Window_x(Fl_Window *w); should work, right?

@lal12
Copy link
Contributor

lal12 commented Sep 20, 2024

So int Fl_Window_x(Fl_Window *w); should work, right?

Yes.

@KaruroChori
Copy link
Contributor Author

KaruroChori commented Sep 20, 2024

Yes it does, but it cannot count as a workaround if I have to do that hundreds of times :D.
This is the library I am using for reference: https://github.com/MoAlyousef/cfltk

I just got it to work and (almost) automatically translate all bindings for Bun ffi using https://github.com/Morglod/bun-ffi-gen (and a lot of patchwork on its code).
I was just hoping to do the same in txiki but failed for that and few more problems, like preprocessor macros not being expanded.

@lal12
Copy link
Contributor

lal12 commented Sep 20, 2024

How about adding a bun ffi compatible wrapper?

@saghul
Copy link
Owner

saghul commented Sep 20, 2024

How about adding a bun ffi compatible wrapper?

That sounds like a good idea!

@KaruroChori
Copy link
Contributor Author

As long as the dynamic library is open as RTLD_LAZY and not RTLD_NOW like Bun does :D.
Loading thousands of function signatures and enforcing them all to exist is really not ideal for fast loading time :/
Internally in txiki we are using uv_load, and if I recall correctly for unix systems it wraps dlopen with RTLD_LAZY. So if we keep this behaviour in place it should be fine.

@saghul
Copy link
Owner

saghul commented Sep 21, 2024

Sounds good!

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

No branches or pull requests

3 participants