Skip to content

Commit

Permalink
Put extern "C" guard around stub table definition. See also same chan…
Browse files Browse the repository at this point in the history
  • Loading branch information
jan.nijtmans committed Oct 30, 2013
1 parent 79035e3 commit 0852c2e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
18 changes: 18 additions & 0 deletions generic/tdbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down
33 changes: 7 additions & 26 deletions generic/tdbcDecls.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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) */

Expand Down
2 changes: 2 additions & 0 deletions generic/tdbcStubLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define USE_TDBC_STUBS 1
#include "tdbc.h"

MODULE_SCOPE const TdbcStubs *tdbcStubsPtr;

const TdbcStubs *tdbcStubsPtr = NULL;

/*
Expand Down
37 changes: 18 additions & 19 deletions tools/genStubs.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down Expand Up @@ -527,7 +527,7 @@ proc genStubs::makeSlot {name decl index} {
append text ")"
}
}

append text "; /* $index */\n"
return $text
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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"
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 0852c2e

Please sign in to comment.