Skip to content

Commit

Permalink
compiler/cgen, ccgthreadvars: export variables correctly
Browse files Browse the repository at this point in the history
For C/C++ variables, `extern` means that the variable is defined in an
another unit. Added a new N_LIB_EXPORT_VAR to correctly export
variables.
  • Loading branch information
alaviss committed Jan 22, 2020
1 parent 6a56ee2 commit 7c38d8c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion compiler/ccgthreadvars.nim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ proc declareThreadVar(m: BModule, s: PSym, isExtern: bool) =
m.g.nimtv.addf("$1 $2;$n", [getTypeDesc(m, s.loc.t), s.loc.r])
else:
if isExtern: m.s[cfsVars].add("extern ")
elif lfExportLib in s.loc.flags: m.s[cfsVars].add("N_LIB_EXPORT ")
elif lfExportLib in s.loc.flags: m.s[cfsVars].add("N_LIB_EXPORT_VAR ")
else: m.s[cfsVars].add("N_LIB_PRIVATE ")
if optThreads in m.config.globalOptions: m.s[cfsVars].add("NIM_THREADVAR ")
m.s[cfsVars].add(getTypeDesc(m, s.loc.t))
Expand Down
2 changes: 1 addition & 1 deletion compiler/cgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ proc assignGlobalVar(p: BProc, n: PNode; value: Rope) =
decl.addf "NIM_ALIGN($1) ", [rope(s.alignment)]
if p.hcrOn: decl.add("static ")
elif sfImportc in s.flags: decl.add("extern ")
elif lfExportLib in s.loc.flags: decl.add("N_LIB_EXPORT ")
elif lfExportLib in s.loc.flags: decl.add("N_LIB_EXPORT_VAR ")
else: decl.add("N_LIB_PRIVATE ")
if s.kind == skLet and value != nil: decl.add("NIM_CONST ")
decl.add(td)
Expand Down
2 changes: 2 additions & 0 deletions lib/nimbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ __AVR__
# else
# define N_LIB_EXPORT NIM_EXTERNC __declspec(dllexport)
# endif
# define N_LIB_EXPORT_VAR __declspec(dllexport)
# define N_LIB_IMPORT extern __declspec(dllimport)
#else
# define N_LIB_PRIVATE __attribute__((visibility("hidden")))
Expand Down Expand Up @@ -215,6 +216,7 @@ __AVR__
# define N_SAFECALL_PTR(rettype, name) rettype (*name)
# endif
# define N_LIB_EXPORT NIM_EXTERNC __attribute__((visibility("default")))
# define N_LIB_EXPORT_VAR __attribute__((visibility("default")))
# define N_LIB_IMPORT extern
#endif

Expand Down

0 comments on commit 7c38d8c

Please sign in to comment.