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

Needs a way to do lookup in cstubs using dlsym/eglGetProcAddress #280

Open
whitequark opened this issue Mar 6, 2015 · 4 comments
Open

Comments

@whitequark
Copy link
Contributor

See dbuenzli/tgls#14 for details. I was going to implement this but the C representation used by cstubs is horrendously opaque and I am not motivated enough to figure it out.

@dbuenzli
Copy link
Contributor

dbuenzli commented Mar 7, 2015

@whitequark if you have a clear idea of what should be done API-wise maybe you should expand a bit on that/explain the problem and try to make a more precise proposal (personally I'm completly ignorant of stub generation and don't have much time to work on that at the moment). For reference this is what Jeremy wrote about the problem at a certain point in time.

@whitequark
Copy link
Contributor Author

The idea is very simple. Currently the stubs look like this:

value stub(value foo) {
  long c_foo = Long_val(foo);
  c_call(c_foo);
  return Val_unit;
}

With this proposal, they would look like:

value stub(value foo) {
  static void(*c_call)(long);
  if(!c_call) {
    c_call = [GetProcAddress];
    if(!c_call) caml_raise(*caml_named_value("Cstubs.Dynamic_stub_not_found"), caml_alloc_string("c_call"));
  }
  c_call(c_foo);
  return Val_unit;
}

The [GetProcAddress] part could be:

This would add just one argument to Cstubs.FOREIGN.foreign, like ?reference:[ direct |dlsym | `custom of string ].

This would be trivial if not for the many layers of abstraction between cstubs' interface and the generated C code.

@whitequark
Copy link
Contributor Author

@yallop Any opinion on this?

@yallop
Copy link
Owner

yallop commented Mar 29, 2016

I'd like to support this kind of thing, but ideally via a general mechanism of customising the generated code (#211). In the short/medium term one possibility is to generate code that makes calls via a macro CALL, like this

value stub(value foo) {
  long c_foo = Long_val(foo);
  CALL(c_call, c_foo);
  return Val_unit;
}

and allow you to redefine CALL to insert the GetProcAddress code.

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