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

Objects marked with {.exportc.} should be fully defined in generated header #4723

Closed
nigredo-tori opened this issue Sep 6, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@nigredo-tori
Copy link
Contributor

commented Sep 6, 2016

In header, generated with --header compiler option, visibility rules for exported structs are non-trivial. As far as I can tell, there are three cases:

  1. The struct is not passed into some proc (directly, via pointer, or via some other directly passed struct), no declaration is generated at all;
  2. The struct is passed only via pointer, we get only a declaration;
  3. The struct is passed directly, we get the full definition.

Here's an example for clarity:

#1. By default we have no declaration at all.
type MyObj {.exportc.} = object
  val: uint

#2. With this we only get `typedef struct MyObj MyObj` declaration.
proc foo(o: ptr MyObj) {.exportc.} = discard

#3. With this we have full definition with all the fields.
proc bar(o: MyObj) {.exportc.} = discard

This means that, if I need to provide an API that only accepts pointers to object type, I have to provide a constructor proc for the object (ugh), or a stub that accepts the object and does nothing (less work, but even uglier)!

A more logical behavior would be to fully define all exported object types in generated header.

@Araq Araq closed this in 279df83 May 22, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.