Can't exportc predefined types from standard library with a stable name #1579

Open
gradha opened this Issue Oct 19, 2014 · 2 comments

Comments

Projects
None yet
3 participants
@gradha
Contributor

gradha commented Oct 19, 2014

The exportc pragma is fine for procs or types you have control over, but it can't be used to export to C types previously defined by the standard library. In my case I'm trying to export a proc to C which uses a PStringTable. I've tried several things, like creating aliases:

type
  LR_StringTable {.extern:"hahah".} = distinct PStringTable

  #LR_StringTable {.exportc.} = ref TStringTable

  TestStruct {.exportc:"thehu".} = object
    nil

proc testProc*(options: TestStruct, another: LR_StringTable) {.exportc.} =
  var a = another
  discard

However in all cases the generated header file contains a numbered symbol which doesn't sound like a good idea for source code compatibility, should this number change in the future:

...
typedef struct thehu thehu;
typedef struct tstringtable128812 tstringtable128812;
struct  thehu  {
char dummy;
};
N_NOCONV(void, signalHandler)(int sig);
N_NIMCALL(NI, getRefcount)(void* p);
N_NIMCALL(void, testProc)(thehu options, tstringtable128812* another);
...

@gradha gradha changed the title from Can't exportc predefined types from standard library to Can't exportc predefined types from standard library with a stable name Oct 19, 2014

@andreaferretti

This comment has been minimized.

Show comment
Hide comment
@andreaferretti

andreaferretti Jun 29, 2018

Collaborator

The identifier mangling logic is changed nowadays - it needed to be stable for compilation caching. So I get

typedef struct tyObject_StringTableObj_DKRIdH9c9cKI7YpQb9c0wKlEw 

Is this guaranteed to be stable?

Collaborator

andreaferretti commented Jun 29, 2018

The identifier mangling logic is changed nowadays - it needed to be stable for compilation caching. So I get

typedef struct tyObject_StringTableObj_DKRIdH9c9cKI7YpQb9c0wKlEw 

Is this guaranteed to be stable?

@Araq

This comment has been minimized.

Show comment
Hide comment
@Araq

Araq Jun 29, 2018

Member

Is this guaranteed to be stable?

No.

Member

Araq commented Jun 29, 2018

Is this guaranteed to be stable?

No.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment