1/*
2 * memchanStubLib.c --
3 *
4 *	Stub object that will be statically linked into extensions that wish
5 *	to access the Memchan API.
6 *
7 * Copyright (c) 1998 Paul Duffin.
8 * Copyright (c) 1998-1999 by Scriptics Corporation.
9 *
10 * See the file "license.terms" for information on usage and redistribution
11 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 *
13 * $Id: memchanStubLib.c,v 1.2 2005/06/08 17:47:59 andreas_kupries Exp $
14 */
15
16#ifndef USE_TCL_STUBS
17#define USE_TCL_STUBS
18#endif
19
20#include "memchan.h"
21#include "buf.h"
22
23#undef  TCL_STORAGE_CLASS
24#define TCL_STORAGE_CLASS DLLEXPORT
25
26extern BufStubs *bufStubsPtr;
27MemchanStubs *memchanStubsPtr;
28
29/*
30 *----------------------------------------------------------------------
31 *
32 * Memchan_InitStubs --
33 *
34 *	Loads the Memchan extension and initializes the stubs table.
35 *
36 * Results:
37 *	The actual version of Memchan in use. NULL if an error occurred.
38 *
39 * Side effects:
40 *	Sets the stub table pointers.
41 *
42 *----------------------------------------------------------------------
43 */
44
45CONST char *
46Memchan_InitStubs(interp, version, exact)
47    Tcl_Interp *interp;
48    CONST char *version;
49    int exact;
50{
51    CONST char *result;
52
53    /* HACK: de-CONST 'version' if compiled against 8.3.
54     * The API has no CONST despite not modifying the argument
55     * And a debug build with high warning-level on windows
56     * will abort the compilation.
57     */
58
59#if ((TCL_MAJOR_VERSION < 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION < 4)))
60#define UNCONST (char*)
61#else
62#define UNCONST
63#endif
64
65    /* NOTE: Memchan actuall provide the Buf stubs. The Memchan stubs
66     *       table is hooked into this.
67     */
68
69    result = Tcl_PkgRequireEx(interp, "Memchan", UNCONST version, exact,
70		(ClientData *) &bufStubsPtr);
71    if (!result || !bufStubsPtr) {
72        return (char *) NULL;
73    }
74
75    memchanStubsPtr = bufStubsPtr->hooks->memchanStubs;
76    return result;
77}
78#undef UNCONST
79