From 0852c2e99f20c49ad5abff8d0bfa90a8ef420d01 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 30 Oct 2013 15:58:15 +0000 Subject: [PATCH] Put extern "C" guard around stub table definition. See also same change in Itcl: [http://core.tcl.tk/itcl/info/ddf387cd88] --- generic/tdbc.h | 18 ++++++++++++++++++ generic/tdbcDecls.h | 33 +++++++-------------------------- generic/tdbcStubLib.c | 2 ++ tools/genStubs.tcl | 37 ++++++++++++++++++------------------- 4 files changed, 45 insertions(+), 45 deletions(-) diff --git a/generic/tdbc.h b/generic/tdbc.h index 7361def..4e8e518 100644 --- a/generic/tdbc.h +++ b/generic/tdbc.h @@ -28,6 +28,10 @@ # endif #endif +#ifdef __cplusplus +extern "C" { +#endif + #if defined(BUILD_tdbc) DLLEXPORT int Tdbc_Init(Tcl_Interp *interp); #elif defined(STATIC_BUILD) @@ -36,6 +40,20 @@ extern int Tdbc_Init(Tcl_Interp* interp); DLLIMPORT int Tdbc_Init(Tcl_Interp* interp); #endif +#define Tdbc_InitStubs(interp) TdbcInitializeStubs(interp, \ + TDBC_VERSION, TDBC_STUBS_EPOCH, TDBC_STUBS_REVISION) +#if defined(USE_TDBC_STUBS) + TDBCAPI const char* TdbcInitializeStubs( + Tcl_Interp* interp, const char* version, int epoch, int revision); +#else +# define TdbcInitializeStubs(interp, version, epoch, revision) \ + (Tcl_PkgRequire(interp, "tdbc", version)) +#endif + +#ifdef __cplusplus +} +#endif + /* * TDBC_VERSION and TDBC_PATCHLEVEL here must match the ones that * appear near the top of configure.in. diff --git a/generic/tdbcDecls.h b/generic/tdbcDecls.h index 708039a..24e4548 100644 --- a/generic/tdbcDecls.h +++ b/generic/tdbcDecls.h @@ -14,23 +14,14 @@ * */ -#if defined(USE_TDBC_STUBS) - TDBCAPI const char* TdbcInitializeStubs( - Tcl_Interp* interp, const char* version, int epoch, int revision); -# define Tdbc_InitStubs(interp) \ - (TdbcInitializeStubs(interp, TDBC_VERSION, TDBC_STUBS_EPOCH, \ - TDBC_STUBS_REVISION)) -#else -# define Tdbc_InitStubs(interp) \ - (Tcl_PkgRequire(interp, "tdbc", TDBC_VERSION)) -#endif - /* !BEGIN!: Do not edit below this line. */ #define TDBC_STUBS_EPOCH 0 #define TDBC_STUBS_REVISION 3 -#if !defined(USE_TDBC_STUBS) +#ifdef __cplusplus +extern "C" { +#endif /* * Exported function declarations: @@ -39,28 +30,24 @@ /* 0 */ TDBCAPI int Tdbc_Init_ (Tcl_Interp* interp); /* 1 */ -TDBCAPI Tcl_Obj* Tdbc_TokenizeSql (Tcl_Interp* interp, +TDBCAPI Tcl_Obj* Tdbc_TokenizeSql (Tcl_Interp* interp, const char* statement); /* 2 */ TDBCAPI const char* Tdbc_MapSqlState (const char* sqlstate); -#endif /* !defined(USE_TDBC_STUBS) */ - typedef struct TdbcStubs { int magic; int epoch; int revision; - const struct TdbcStubHooks *hooks; + void *hooks; int (*tdbc_Init_) (Tcl_Interp* interp); /* 0 */ Tcl_Obj* (*tdbc_TokenizeSql) (Tcl_Interp* interp, const char* statement); /* 1 */ const char* (*tdbc_MapSqlState) (const char* sqlstate); /* 2 */ } TdbcStubs; -#ifdef __cplusplus -extern "C" { -#endif -TDBCAPI const TdbcStubs *tdbcStubsPtr; +extern const TdbcStubs *tdbcStubsPtr; + #ifdef __cplusplus } #endif @@ -71,18 +58,12 @@ TDBCAPI const TdbcStubs *tdbcStubsPtr; * Inline function declarations: */ -#ifndef Tdbc_Init_ #define Tdbc_Init_ \ (tdbcStubsPtr->tdbc_Init_) /* 0 */ -#endif -#ifndef Tdbc_TokenizeSql #define Tdbc_TokenizeSql \ (tdbcStubsPtr->tdbc_TokenizeSql) /* 1 */ -#endif -#ifndef Tdbc_MapSqlState #define Tdbc_MapSqlState \ (tdbcStubsPtr->tdbc_MapSqlState) /* 2 */ -#endif #endif /* defined(USE_TDBC_STUBS) */ diff --git a/generic/tdbcStubLib.c b/generic/tdbcStubLib.c index b9d9ff2..18fcecc 100644 --- a/generic/tdbcStubLib.c +++ b/generic/tdbcStubLib.c @@ -19,6 +19,8 @@ #define USE_TDBC_STUBS 1 #include "tdbc.h" +MODULE_SCOPE const TdbcStubs *tdbcStubsPtr; + const TdbcStubs *tdbcStubsPtr = NULL; /* diff --git a/tools/genStubs.tcl b/tools/genStubs.tcl index dd878cb..77d0b51 100644 --- a/tools/genStubs.tcl +++ b/tools/genStubs.tcl @@ -299,6 +299,7 @@ proc genStubs::addPlatformGuard {plat text} { proc genStubs::emitSlots {name textVar} { upvar $textVar text + forAllStubs $name makeSlot noGuard text {" void (*reserved$i)(void);\n"} return } @@ -398,7 +399,6 @@ proc genStubs::parseArg {arg} { proc genStubs::makeDecl {name decl index} { variable scspec - lassign $decl rtype fname args append text "/* $index */\n" @@ -430,7 +430,7 @@ proc genStubs::makeDecl {name decl index} { [lindex $arg 2] if {[string length $line] + [string length $next] \ + $pad > 76} { - append text $line \n + append text [string trimright $line] \n set line "\t\t\t\t" set pad 28 } @@ -464,7 +464,7 @@ proc genStubs::makeMacro {name decl index} { set lfname [string tolower [string index $fname 0]] append lfname [string range $fname 1 end] - set text "#ifndef $fname\n#define $fname" + set text "#define $fname" set arg1 [lindex $args 0] set argList "" switch -exact $arg1 { @@ -483,7 +483,7 @@ proc genStubs::makeMacro {name decl index} { } } append text " \\\n\t(${name}StubsPtr->$lfname)" - append text " /* $index */\n#endif\n" + append text " /* $index */\n" return $text } @@ -527,7 +527,7 @@ proc genStubs::makeSlot {name decl index} { append text ")" } } - + append text "; /* $index */\n" return $text } @@ -626,15 +626,10 @@ proc genStubs::ifdeffed {macro text} { # None. proc genStubs::emitDeclarations {name textVar} { - variable libraryName upvar $textVar text - set upName [string toupper $libraryName] - append text "\n#if !defined(USE_${upName}_STUBS)\n" append text "\n/*\n * Exported function declarations:\n */\n\n" forAllStubs $name makeDecl noGuard text - append text "\n#endif /* !defined(USE_${upName}_STUBS) */\n" - return } @@ -656,7 +651,7 @@ proc genStubs::emitMacros {name textVar} { set upName [string toupper $libraryName] append text "\n#if defined(USE_${upName}_STUBS)\n" append text "\n/*\n * Inline function declarations:\n */\n\n" - + forAllStubs $name makeMacro addGuard text append text "\n#endif /* defined(USE_${upName}_STUBS) */\n" @@ -679,7 +674,6 @@ proc genStubs::emitHeader {name} { variable hooks variable epoch variable revision - variable scspec set capName [string toupper [string index $name 0]] append capName [string range $name 1 end] @@ -689,10 +683,12 @@ proc genStubs::emitHeader {name} { append text "#define ${CAPName}_STUBS_EPOCH $epoch\n" append text "#define ${CAPName}_STUBS_REVISION $revision\n" + append text "\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n" + emitDeclarations $name text if {[info exists hooks($name)]} { - append text "\ntypedef struct ${capName}StubHooks {\n" + append text "\ntypedef struct {\n" foreach hook $hooks($name) { set capHook [string toupper [string index $hook 0]] append capHook [string range $hook 1 end] @@ -704,14 +700,17 @@ proc genStubs::emitHeader {name} { append text " int magic;\n" append text " int epoch;\n" append text " int revision;\n" - append text " const struct ${capName}StubHooks *hooks;\n\n" + if {[info exists hooks($name)]} { + append text " const ${capName}StubHooks *hooks;\n\n" + } else { + append text " void *hooks;\n\n" + } emitSlots $name text - append text "} ${capName}Stubs;\n" + append text "} ${capName}Stubs;\n\n" - append text "\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n" - append text "${scspec} const ${capName}Stubs *${name}StubsPtr;\n" + append text "extern const ${capName}Stubs *${name}StubsPtr;\n\n" append text "#ifdef __cplusplus\n}\n#endif\n" emitMacros $name text @@ -743,7 +742,7 @@ proc genStubs::emitInit {name textVar} { set CAPName [string toupper $name] if {[info exists hooks($name)]} { - append text "\nstatic const ${capName}StubHooks ${name}StubHooks = \{\n" + append text "\nstatic const ${capName}StubHooks ${name}StubHooks = \{\n" set sep " " foreach sub $hooks($name) { append text $sep "&${sub}Stubs" @@ -773,7 +772,7 @@ proc genStubs::emitInit {name textVar} { } else { append text " 0,\n" } - + forAllStubs $name makeInit noGuard text {" 0, /* $i */\n"} append text "\};\n"