| 1 |
/* |
| 2 |
* pkgooa.c -- |
| 3 |
* |
| 4 |
* This file contains a simple Tcl package "pkgooa" that is intended for |
| 5 |
* testing the Tcl dynamic loading facilities. |
| 6 |
* |
| 7 |
* Copyright (c) 1995 Sun Microsystems, Inc. |
| 8 |
* |
| 9 |
* See the file "license.terms" for information on usage and redistribution of |
| 10 |
* this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 11 |
*/ |
| 12 |
|
| 13 |
#undef STATIC_BUILD |
| 14 |
#include "tclOO.h" |
| 15 |
#include <string.h> |
| 16 |
|
| 17 |
/* |
| 18 |
*---------------------------------------------------------------------- |
| 19 |
* |
| 20 |
* Pkgooa_StubsOKObjCmd -- |
| 21 |
* |
| 22 |
* This procedure is invoked to process the "pkgooa_stubsok" Tcl command. |
| 23 |
* It gives 1 if stubs are used correctly, 0 if stubs are not OK. |
| 24 |
* |
| 25 |
* Results: |
| 26 |
* A standard Tcl result. |
| 27 |
* |
| 28 |
* Side effects: |
| 29 |
* See the user documentation. |
| 30 |
* |
| 31 |
*---------------------------------------------------------------------- |
| 32 |
*/ |
| 33 |
|
| 34 |
static int |
| 35 |
Pkgooa_StubsOKObjCmd( |
| 36 |
void *dummy, /* Not used. */ |
| 37 |
Tcl_Interp *interp, /* Current interpreter. */ |
| 38 |
int objc, /* Number of arguments. */ |
| 39 |
Tcl_Obj *const objv[]) /* Argument objects. */ |
| 40 |
{ |
| 41 |
(void)dummy; |
| 42 |
|
| 43 |
if (objc != 1) { |
| 44 |
Tcl_WrongNumArgs(interp, 1, objv, ""); |
| 45 |
return TCL_ERROR; |
| 46 |
} |
| 47 |
Tcl_SetObjResult(interp, Tcl_NewIntObj( |
| 48 |
Tcl_CopyObjectInstance == tclOOStubsPtr->tcl_CopyObjectInstance)); |
| 49 |
return TCL_OK; |
| 50 |
} |
| 51 |
|
| 52 |
/* |
| 53 |
*---------------------------------------------------------------------- |
| 54 |
* |
| 55 |
* Pkgooa_Init -- |
| 56 |
* |
| 57 |
* This is a package initialization procedure, which is called by Tcl |
| 58 |
* when this package is to be added to an interpreter. |
| 59 |
* |
| 60 |
* Results: |
| 61 |
* None. |
| 62 |
* |
| 63 |
* Side effects: |
| 64 |
* None. |
| 65 |
* |
| 66 |
*---------------------------------------------------------------------- |
| 67 |
*/ |
| 68 |
|
| 69 |
extern void *tclOOIntStubsPtr; |
| 70 |
|
| 71 |
static TclOOStubs stubsCopy = { |
| 72 |
TCL_STUB_MAGIC, |
| 73 |
NULL, |
| 74 |
/* It doesn't really matter what implementation of |
| 75 |
* Tcl_CopyObjectInstance is put in the "pseudo" |
| 76 |
* stub table, since the test-case never actually |
| 77 |
* calls this function. All that matters is that it's |
| 78 |
* a function with a different memory address than |
| 79 |
* the real Tcl_CopyObjectInstance function in Tcl. */ |
| 80 |
(Tcl_Object (*) (Tcl_Interp *, Tcl_Object, const char *, |
| 81 |
const char *t))(void *)Pkgooa_StubsOKObjCmd, |
| 82 |
/* More entries could be here, but those are not used |
| 83 |
* for this test-case. So, being NULL is OK. */ |
| 84 |
NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 85 |
NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 86 |
NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 87 |
NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 88 |
NULL, NULL, NULL, NULL, NULL, NULL |
| 89 |
}; |
| 90 |
|
| 91 |
DLLEXPORT int |
| 92 |
Pkgooa_Init( |
| 93 |
Tcl_Interp *interp) /* Interpreter in which the package is to be |
| 94 |
* made available. */ |
| 95 |
{ |
| 96 |
int code; |
| 97 |
|
| 98 |
/* Any TclOO extension which uses stubs, calls |
| 99 |
* both Tcl_InitStubs and Tcl_OOInitStubs() and |
| 100 |
* does not use any Tcl 8.6 features should be |
| 101 |
* loadable in Tcl 8.5 as well, provided the |
| 102 |
* TclOO extension (for Tcl 8.5) is installed. |
| 103 |
* This worked in Tcl 8.6.0, and is expected |
| 104 |
* to keep working in all future Tcl 8.x releases. |
| 105 |
*/ |
| 106 |
if (Tcl_InitStubs(interp, "8.5-", 0) == NULL) { |
| 107 |
return TCL_ERROR; |
| 108 |
} |
| 109 |
if (tclStubsPtr == NULL) { |
| 110 |
Tcl_AppendResult(interp, "Tcl stubs are not initialized, " |
| 111 |
"did you compile using -DUSE_TCL_STUBS? ", (char *)NULL); |
| 112 |
return TCL_ERROR; |
| 113 |
} |
| 114 |
if (Tcl_OOInitStubs(interp) == NULL) { |
| 115 |
return TCL_ERROR; |
| 116 |
} |
| 117 |
if (tclOOStubsPtr == NULL) { |
| 118 |
Tcl_AppendResult(interp, "TclOO stubs are not initialized", (char *)NULL); |
| 119 |
return TCL_ERROR; |
| 120 |
} |
| 121 |
if (tclOOIntStubsPtr == NULL) { |
| 122 |
Tcl_AppendResult(interp, "TclOO internal stubs are not initialized", (char *)NULL); |
| 123 |
return TCL_ERROR; |
| 124 |
} |
| 125 |
|
| 126 |
/* Test case for Bug [f51efe99a7]. |
| 127 |
* |
| 128 |
* Let tclOOStubsPtr point to an alternate stub table |
| 129 |
* (with only a single function, that's enough for |
| 130 |
* this test). This way, the function "pkgooa_stubsok" |
| 131 |
* can check whether the TclOO function calls really |
| 132 |
* use the stub table, or only pretend to. |
| 133 |
* |
| 134 |
* On platforms without backlinking (Windows, Cygwin, |
| 135 |
* AIX), this code doesn't even compile without using |
| 136 |
* stubs, but on UNIX ELF systems, the problem is |
| 137 |
* less visible. |
| 138 |
*/ |
| 139 |
|
| 140 |
tclOOStubsPtr = &stubsCopy; |
| 141 |
|
| 142 |
code = Tcl_PkgProvide(interp, "pkgooa", "1.0"); |
| 143 |
if (code != TCL_OK) { |
| 144 |
return code; |
| 145 |
} |
| 146 |
Tcl_CreateObjCommand(interp, "pkgooa_stubsok", Pkgooa_StubsOKObjCmd, NULL, NULL); |
| 147 |
return TCL_OK; |
| 148 |
} |