Check-in [82e8ebb242]
Overview
Comment:Updated to allow external symbols to be resolved if dlopen() is available
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 82e8ebb242069f3c790cbdcd9cde93280c3ab8ab
User & Date: rkeene on 2014-06-16 04:20:11
Other Links: manifest | tags
Context
2014-06-16
04:48
Updated to not build TCC as a static so that existing symbols could resolved by TCC itself check-in: fd6711ab73 user: rkeene tags: trunk
04:20
Updated to allow external symbols to be resolved if dlopen() is available check-in: 82e8ebb242 user: rkeene tags: trunk
01:44
Updated to install DLL source code check-in: e13bdc3fcc user: rkeene tags: trunk
Changes

Added aclocal/dlsym.m4 version [9b676022d2].









































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
AC_DEFUN([TCC4TCL_FIND_DLOPEN], [
	AC_CHECK_HEADERS_ONCE([dlfcn.h])

	AC_SEARCH_LIBS([dlsym], [dl dld], [
		AC_DEFINE([HAVE_DLSYM], [1], [Have the dlsym function])
	], [
		AC_CHECK_HEADERS([windows.h])

		AC_MSG_CHECKING([for working EnumProcessModules])
		SAVE_LIBS="$LIBS"
		LIBS="$LIBS -lpsapi"
		AC_LINK_IFELSE([
			AC_LANG_PROGRAM([
#ifdef HAVE_WINDOWS_H
#  include <windows.h>
#endif
#include <psapi.h>
			], [
HANDLE cur_proc;
DWORD needed;

needed = 0;

cur_proc = GetCurrentProcess();
EnumProcessModules(cur_proc, NULL, 0, &needed);
			]
		)], [
			AC_DEFINE([HAVE_ENUMPROCESSMODULES], [1], [Have the EnumProcessModules function])
			AC_DEFINE([HAVE_PSAPI_H], [1], [Have the psapi.h header file])
			AC_MSG_RESULT([found])
		], [
			LIBS="$SAVE_LIBS"
			AC_MSG_RESULT([not found])
		])
	])
])

Added build/build-platform version [af2d67d68b].































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#! /bin/bash

platform="$1"
shift

if [ -z "${platform}" ]; then
	echo "Platforms:"
fi

for dir in work/libtclkit-*/ __fail__; do
	if [ "${dir}" == '__fail__' ]; then
		if [ -z "${platform}" ]; then
			exit 0
		fi

		echo "No such platform: ${platform}" >&2

		exit 1
	fi

	dir="$(echo "${dir}" | sed 's@/$@@')"
	dir_platform="$(basename "${dir}-" | sed 's@^libtclkit-[^-]*-@@;s@-notk-@-@g;s@-xcompile-@-@g;s@-kitdll-@-@;s@-sdk-@-@g;s@-$@@')"

	if [ -z "${platform}" ]; then
		echo "  $dir_platform"
	else
		if [ "${dir_platform}" = "${platform}" ]; then
			break
		fi
	fi
done
dir="$(pwd)/${dir}"

case "${platform}" in
	linux-i386)
		platform="x86_64-redhat5-linux 32"
		;;
	linux-mipsel)
		platform="mipsel-unknown-linux-uclibc"
		;;
	solaris-amd64)
		platform="i386-pc-solaris2.10 64"
		;;
	solaris-i386)
		platform="i386-pc-solaris2.10"
		;;
	win32-i586)
		platform="i586-mingw32msvc"
		;;
	win64-amd64)
		platform="x86_64-w64-mingw32"
		;;
	android-arm)
		platform="arm-android9-linux-androideabi"
		;;
	netbsd-amd64)
		platform="x86_64-unknown-netbsd5"
		;;
	'')
		exit 0
		;;
	*)
		echo "Unknown platform: ${platform}" >&2

		exit 1
		;;
esac

TCLKIT_SDK_DIR="${dir}"
export TCLKIT_SDK_DIR

make distclean
eval `~/root/cross-compilers/setup-cc $platform`

platform="$(echo "${platform}" | cut -f1 -d ' ')"

./configure --host="${platform}" --libdir="$(pwd)/INST" --with-tcl="${dir}/lib" "$@"
make 
make install

Modified configure.ac from [c1e20b872e] to [13d9b5f529].

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
AC_GNU_SOURCE
AC_LANG(C)

dnl Determine system information
DC_CHK_OS_INFO

dnl Determine if a shared or static build is requested
AC_ARG_ENABLE([shared], AS_HELP_STRING([--disble-shared], [build static library instead of shared library]), [
	if test "$enableval" = "no"; then
		TCC4TCL_TARGET=static
	else
		TCC4TCL_TARGET=shared
	fi
], [
	TCC4TCL_TARGET=shared







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
AC_GNU_SOURCE
AC_LANG(C)

dnl Determine system information
DC_CHK_OS_INFO

dnl Determine if a shared or static build is requested
AC_ARG_ENABLE([shared], AS_HELP_STRING([--disable-shared], [build static library instead of shared library]), [
	if test "$enableval" = "no"; then
		TCC4TCL_TARGET=static
	else
		TCC4TCL_TARGET=shared
	fi
], [
	TCC4TCL_TARGET=shared
65
66
67
68
69
70
71



72
73
74
75
76
77
78
79
80
81
82
83
		HOST_PATH_SEPARATOR=';'
		;;
	*)
		HOST_PATH_SEPARATOR=':'
		;;
esac
AC_SUBST(HOST_PATH_SEPARATOR)




dnl Perform Tcl Extension required stuff
TCLEXT_INIT

dnl This must be done last since it breaks the compilation
if test "${TCC4TCL_TARGET}" = "shared"; then
	DC_SETVERSIONSCRIPT([${srcdir}/tcc4tcl.vers], [tcc4tcl.syms])
	DC_FIND_STRIP_AND_REMOVESYMS([tcc4tcl.syms])
fi

dnl Produce output
AC_OUTPUT(Makefile pkgIndex.tcl tcc4tcl.syms)







>
>
>












65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
		HOST_PATH_SEPARATOR=';'
		;;
	*)
		HOST_PATH_SEPARATOR=':'
		;;
esac
AC_SUBST(HOST_PATH_SEPARATOR)

dnl Determine how to lookup symbols at runtime
TCC4TCL_FIND_DLOPEN

dnl Perform Tcl Extension required stuff
TCLEXT_INIT

dnl This must be done last since it breaks the compilation
if test "${TCC4TCL_TARGET}" = "shared"; then
	DC_SETVERSIONSCRIPT([${srcdir}/tcc4tcl.vers], [tcc4tcl.syms])
	DC_FIND_STRIP_AND_REMOVESYMS([tcc4tcl.syms])
fi

dnl Produce output
AC_OUTPUT(Makefile pkgIndex.tcl tcc4tcl.syms)

Modified tcc4tcl.c from [57a80f23fd] to [0dd7284c29].

18
19
20
21
22
23
24









25
26
27
28
29
30
31
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <tcl.h>
#include <stdlib.h>
#include "tcc.h"










struct TclTCCState {
	TCCState *s;
	int relocated;
};

static void Tcc4tclErrorFunc(Tcl_Interp * interp, char * msg) {







>
>
>
>
>
>
>
>
>







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <tcl.h>
#include <stdlib.h>
#include "tcc.h"
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#endif
#ifdef HAVE_PSAPI_H
#  ifdef HAVE_WINDOWS_H
#    include <windows.h>
#  endif
#  include <psapi.h>
#endif

struct TclTCCState {
	TCCState *s;
	int relocated;
};

static void Tcc4tclErrorFunc(Tcl_Interp * interp, char * msg) {
55
56
57
58
59
60
61
62


63
64
65
66
67

68

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

124

125
126
127
128
129
130
131
132
133
134
135
136
	int res;
	struct TclTCCState *ts;
	TCCState *s;
	Tcl_Obj *sym_addr;
	static CONST char *options[] = {
		"add_include_path", "add_file",  "add_library", 
		"add_library_path", "add_symbol", "command", "compile",
		"define", "get_symbol", "output_file", "undefine",    (char *) NULL


	};
	enum options {
		TCLTCC_ADD_INCLUDE, TCLTCC_ADD_FILE, TCLTCC_ADD_LIBRARY, 
		TCLTCC_ADD_LIBRARY_PATH, TCLTCC_ADD_SYMBOL, TCLTCC_COMMAND, TCLTCC_COMPILE,
		TCLTCC_DEFINE, TCLTCC_GET_SYMBOL, TCLTCC_OUTPUT_FILE, TCLTCC_UNDEFINE

	};


	ts = (struct TclTCCState *) cdata;
	s = ts->s;

    if (objc < 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "subcommand arg ?arg ...?");
        return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObj(interp, objv[1], options, "option", 0,
                &index) != TCL_OK) {
        return TCL_ERROR;
    }
    switch (index) {
        case TCLTCC_ADD_INCLUDE:   
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "path");
                return TCL_ERROR;
            } else {
                tcc_add_include_path(s, Tcl_GetString(objv[2]));
                return TCL_OK;
            }
        case TCLTCC_ADD_FILE:   
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "filename");
                return TCL_ERROR;
            } else {
                if(tcc_add_file(s, Tcl_GetString(objv[2]))!=0) {
                    return TCL_ERROR;
                } else {
                    return TCL_OK;
                }
            }
        case TCLTCC_ADD_LIBRARY:
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "lib");
                return TCL_ERROR;
            } else {
                tcc_add_library(s, Tcl_GetString(objv[2]));
                return TCL_OK;
            }
        case TCLTCC_ADD_LIBRARY_PATH:
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "path");
                return TCL_ERROR;
            } else {
                tcc_add_library_path(s, Tcl_GetString(objv[2]));
                return TCL_OK;
            }
#if 0
        case TCLTCC_ADD_SYMBOL:
            if (objc != 4) {
                Tcl_WrongNumArgs(interp, 2, objv, "symbol value");
                return TCL_ERROR;
            }

            Tcl_GetLongFromObj(interp,objv[3], &val);


            tcc_add_symbol(s,Tcl_GetString(objv[2]),val); 
            return TCL_OK; 
#endif
        case TCLTCC_COMMAND:
            if (objc != 4) {
                Tcl_WrongNumArgs(interp, 2, objv, "tclname cname");
                return TCL_ERROR;
            }
            if (!ts->relocated) {     
                if(tcc_relocate(s, TCC_RELOCATE_AUTO)!=0) {
                    Tcl_AppendResult(interp, "relocating failed", NULL);







|
>
>


|
|
|
>

>














|







|










|







|







<
|




>
|
>

|

<
|







64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130

131
132
133
134
135
136
137
138
139
140
141

142
143
144
145
146
147
148
149
	int res;
	struct TclTCCState *ts;
	TCCState *s;
	Tcl_Obj *sym_addr;
	static CONST char *options[] = {
		"add_include_path", "add_file",  "add_library", 
		"add_library_path", "add_symbol", "command", "compile",
		"define", "get_symbol", "output_file", "undefine",
		"add_runtime_sym",
		(char *) NULL
	};
	enum options {
		TCC4TCL_ADD_INCLUDE, TCC4TCL_ADD_FILE, TCC4TCL_ADD_LIBRARY, 
		TCC4TCL_ADD_LIBRARY_PATH, TCC4TCL_ADD_SYMBOL, TCC4TCL_COMMAND, TCC4TCL_COMPILE,
		TCC4TCL_DEFINE, TCC4TCL_GET_SYMBOL, TCC4TCL_OUTPUT_FILE, TCC4TCL_UNDEFINE,
		TCC4TCL_ADD_RUNTIME_SYM
	};
	char *str;

	ts = (struct TclTCCState *) cdata;
	s = ts->s;

    if (objc < 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "subcommand arg ?arg ...?");
        return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObj(interp, objv[1], options, "option", 0,
                &index) != TCL_OK) {
        return TCL_ERROR;
    }
    switch (index) {
        case TCC4TCL_ADD_INCLUDE:   
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "path");
                return TCL_ERROR;
            } else {
                tcc_add_include_path(s, Tcl_GetString(objv[2]));
                return TCL_OK;
            }
        case TCC4TCL_ADD_FILE:   
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "filename");
                return TCL_ERROR;
            } else {
                if(tcc_add_file(s, Tcl_GetString(objv[2]))!=0) {
                    return TCL_ERROR;
                } else {
                    return TCL_OK;
                }
            }
        case TCC4TCL_ADD_LIBRARY:
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "lib");
                return TCL_ERROR;
            } else {
                tcc_add_library(s, Tcl_GetString(objv[2]));
                return TCL_OK;
            }
        case TCC4TCL_ADD_LIBRARY_PATH:
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "path");
                return TCL_ERROR;
            } else {
                tcc_add_library_path(s, Tcl_GetString(objv[2]));
                return TCL_OK;
            }

        case TCC4TCL_ADD_SYMBOL:
            if (objc != 4) {
                Tcl_WrongNumArgs(interp, 2, objv, "symbol value");
                return TCL_ERROR;
            }

            Tcl_GetLongFromObj(interp, objv[3], &val);
            val_p = (void *) val;

            tcc_add_symbol(s,Tcl_GetString(objv[2]), val_p); 
            return TCL_OK; 

        case TCC4TCL_COMMAND:
            if (objc != 4) {
                Tcl_WrongNumArgs(interp, 2, objv, "tclname cname");
                return TCL_ERROR;
            }
            if (!ts->relocated) {     
                if(tcc_relocate(s, TCC_RELOCATE_AUTO)!=0) {
                    Tcl_AppendResult(interp, "relocating failed", NULL);
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227

















































228
229
230
231
232
233
234
		    Tcl_AppendResult(interp, "symbol '", Tcl_GetString(objv[3]),"' not found", NULL);
		    return TCL_ERROR;
	    }

            /*printf("symbol: %x\n",val); */
            Tcl_CreateObjCommand(interp,Tcl_GetString(objv[2]),val_p,NULL,NULL);
            return TCL_OK;
        case TCLTCC_COMPILE:
            if(ts->relocated == 1) {
                Tcl_AppendResult(interp, "code already relocated, cannot compile more",NULL);
                return TCL_ERROR;
            }
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "ccode");
                return TCL_ERROR;
            } else {

                int i;
                Tcl_GetString(objv[2]);
                i = tcc_compile_string(s,Tcl_GetString(objv[2]));
                if (i!=0) {
                    Tcl_AppendResult(interp,"compilation failed",NULL);
                    return TCL_ERROR;
                } else {
                    return TCL_OK;
                }
            }
        case TCLTCC_DEFINE:
            if (objc != 4) {
                Tcl_WrongNumArgs(interp, 2, objv, "symbol value");
                return TCL_ERROR;
            }
            tcc_define_symbol(s,Tcl_GetString(objv[2]),Tcl_GetString(objv[3]));
            return TCL_OK;
        case TCLTCC_GET_SYMBOL:
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "symbol");
                return TCL_ERROR;
            }
            if (!ts->relocated) {     
                if(tcc_relocate(s, TCC_RELOCATE_AUTO)!=0) {
                    Tcl_AppendResult(interp, "relocating failed", NULL);
                    return TCL_ERROR;
                } else {
                    ts->relocated=1;
                }
            }
            val_p = tcc_get_symbol(s,Tcl_GetString(objv[2]));
            if(val_p == NULL) {
                Tcl_AppendResult(interp, "symbol '", Tcl_GetString(objv[2]),"' not found", NULL);
                return TCL_ERROR;
            }
            sym_addr = Tcl_NewWideIntObj((Tcl_WideInt) val_p);
            Tcl_SetObjResult(interp, sym_addr);
            return TCL_OK; 
        case TCLTCC_OUTPUT_FILE:
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "filename");
                return TCL_ERROR;
            }
            if (ts->relocated) {     
                Tcl_AppendResult(interp, "code already relocated, cannot output to file", NULL);
                return TCL_ERROR;
            }
            if (s->output_type == TCC_OUTPUT_MEMORY) {     
                Tcl_AppendResult(interp, "output_type memory not valid for output to file", NULL);
                return TCL_ERROR;
            }
            res = tcc_output_file(s,Tcl_GetString(objv[2]));

            if (res!=0) {
                Tcl_AppendResult(interp, "output to file failed", NULL);
                return TCL_ERROR;
            } else {
                return TCL_OK;
            }
        case TCLTCC_UNDEFINE:
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "symbol");
                return TCL_ERROR;
            }
            tcc_undefine_symbol(s,Tcl_GetString(objv[2]));
            return TCL_OK;

















































        default:
            Tcl_Panic("internal error during option lookup");
    }
    return TCL_OK;
} 

static int Tcc4tclCreateCmd( ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]){







|



















|






|




















|




















|






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
		    Tcl_AppendResult(interp, "symbol '", Tcl_GetString(objv[3]),"' not found", NULL);
		    return TCL_ERROR;
	    }

            /*printf("symbol: %x\n",val); */
            Tcl_CreateObjCommand(interp,Tcl_GetString(objv[2]),val_p,NULL,NULL);
            return TCL_OK;
        case TCC4TCL_COMPILE:
            if(ts->relocated == 1) {
                Tcl_AppendResult(interp, "code already relocated, cannot compile more",NULL);
                return TCL_ERROR;
            }
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "ccode");
                return TCL_ERROR;
            } else {

                int i;
                Tcl_GetString(objv[2]);
                i = tcc_compile_string(s,Tcl_GetString(objv[2]));
                if (i!=0) {
                    Tcl_AppendResult(interp,"compilation failed",NULL);
                    return TCL_ERROR;
                } else {
                    return TCL_OK;
                }
            }
        case TCC4TCL_DEFINE:
            if (objc != 4) {
                Tcl_WrongNumArgs(interp, 2, objv, "symbol value");
                return TCL_ERROR;
            }
            tcc_define_symbol(s,Tcl_GetString(objv[2]),Tcl_GetString(objv[3]));
            return TCL_OK;
        case TCC4TCL_GET_SYMBOL:
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "symbol");
                return TCL_ERROR;
            }
            if (!ts->relocated) {     
                if(tcc_relocate(s, TCC_RELOCATE_AUTO)!=0) {
                    Tcl_AppendResult(interp, "relocating failed", NULL);
                    return TCL_ERROR;
                } else {
                    ts->relocated=1;
                }
            }
            val_p = tcc_get_symbol(s,Tcl_GetString(objv[2]));
            if(val_p == NULL) {
                Tcl_AppendResult(interp, "symbol '", Tcl_GetString(objv[2]),"' not found", NULL);
                return TCL_ERROR;
            }
            sym_addr = Tcl_NewWideIntObj((Tcl_WideInt) val_p);
            Tcl_SetObjResult(interp, sym_addr);
            return TCL_OK; 
        case TCC4TCL_OUTPUT_FILE:
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "filename");
                return TCL_ERROR;
            }
            if (ts->relocated) {     
                Tcl_AppendResult(interp, "code already relocated, cannot output to file", NULL);
                return TCL_ERROR;
            }
            if (s->output_type == TCC_OUTPUT_MEMORY) {     
                Tcl_AppendResult(interp, "output_type memory not valid for output to file", NULL);
                return TCL_ERROR;
            }
            res = tcc_output_file(s,Tcl_GetString(objv[2]));

            if (res!=0) {
                Tcl_AppendResult(interp, "output to file failed", NULL);
                return TCL_ERROR;
            } else {
                return TCL_OK;
            }
        case TCC4TCL_UNDEFINE:
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "symbol");
                return TCL_ERROR;
            }
            tcc_undefine_symbol(s,Tcl_GetString(objv[2]));
            return TCL_OK;
	case TCC4TCL_ADD_RUNTIME_SYM:
		if (objc != 3) {
			Tcl_WrongNumArgs(interp, 2, objv, "symbol_name");
			return(TCL_ERROR);
		}

		str = Tcl_GetString(objv[2]);
#ifdef HAVE_DLSYM
		val_p = dlsym(NULL, str);
#elif defined(HAVE_ENUMPROCESSMODULES)
		val_p = NULL;
		{
			HANDLE cur_proc;
			HMODULE *modules;
			DWORD needed, i;

			needed = 0;

			cur_proc = GetCurrentProcess();
			EnumProcessModules(cur_proc, NULL, 0, &needed);

			if (needed > 0) {
				modules = (void *) ckalloc(needed);
				if (EnumProcessModules(cur_proc, modules, needed, &needed)) {
					for (i = 0; i < (needed / sizeof(HMODULE)); i++) {
						val_p = (void *) GetProcAddress(modules[i], str);

						if (val_p) {
							break;
						}
					}
				}

				ckfree((void *) modules);
			}
		}
#else
		val_p = NULL;
#endif

		if (val_p == NULL) {
			Tcl_AppendResult(interp, "symbol not found", NULL);

			return(TCL_ERROR);
		}

		tcc_add_symbol(s, Tcl_GetString(objv[2]), val_p); 

		return(TCL_OK);
        default:
            Tcl_Panic("internal error during option lookup");
    }
    return TCL_OK;
} 

static int Tcc4tclCreateCmd( ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]){
267
268
269
270
271
272
273


274
275
276
277
278
279
280
	ts = (void *) ckalloc(sizeof(*ts));
	ts->s = s;
    	ts->relocated = 0;

	/*printf("type: %d\n", index); */
	tcc_set_output_type(s,index);
	Tcl_CreateObjCommand(interp,Tcl_GetString(objv[objc-1]),Tcc4tclHandleCmd,ts,Tcc4tclCCommandDeleteProc);



	return TCL_OK;
}

int Tcc4tcl_Init(Tcl_Interp *interp) {
#ifdef USE_TCL_STUBS
	if (Tcl_InitStubs(interp, "8.4" , 0) == 0L) {







>
>







329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
	ts = (void *) ckalloc(sizeof(*ts));
	ts->s = s;
    	ts->relocated = 0;

	/*printf("type: %d\n", index); */
	tcc_set_output_type(s,index);
	Tcl_CreateObjCommand(interp,Tcl_GetString(objv[objc-1]),Tcc4tclHandleCmd,ts,Tcc4tclCCommandDeleteProc);

	Tcl_SetObjResult(interp, objv[objc-1]);

	return TCL_OK;
}

int Tcc4tcl_Init(Tcl_Interp *interp) {
#ifdef USE_TCL_STUBS
	if (Tcl_InitStubs(interp, "8.4" , 0) == 0L) {

Modified tcc4tcl.tcl from [c36e097dd3] to [47dd5cbf47].

352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
	append code $body
	append code "\nreturn TCL_OK;\n\}"

	return $code
}

#---------------------------------------------------------------------
proc ::tcc4tcl::cproc {name adefs rtype {body "#"}} {
	foreach {code cbody} [wrap $name $adefs $rtype $body] break

	::tcc4tcl::ccode $code

	uplevel 1 [list ::tcc4tcl::ccommand $name {dummy ip objc objv} $cbody]
}

#---------------------------------------------------------------------
proc ::tcc4tcl::cdata {name data} {
	# Extract bytes from data
	binary scan $data c* bytes








|




|







352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
	append code $body
	append code "\nreturn TCL_OK;\n\}"

	return $code
}

#---------------------------------------------------------------------
proc ::tcc4tcl::cproc {name adefs rtype {body "#"} {addfuncs ""}} {
	foreach {code cbody} [wrap $name $adefs $rtype $body] break

	::tcc4tcl::ccode $code

	uplevel 1 [list ::tcc4tcl::ccommand $name {dummy ip objc objv} $cbody $addfuncs]
}

#---------------------------------------------------------------------
proc ::tcc4tcl::cdata {name data} {
	# Extract bytes from data
	binary scan $data c* bytes

405
406
407
408
409
410
411
412
413
414
415
416
417
418
419

	uplevel 1 [list tcc4tcl::ccommand $name {dummy ip objc objv} $cbody]

	return $name
}

#-------------------------------------------------------------------
proc ::tcc4tcl::ccommand {procname anames args} {
	variable tcc

	# Fully qualified proc name
	if {[string match "::*" $procname]} {
		# procname is already absolute
	} else {
		set nsfrom [uplevel 1 {namespace current}]    







|







405
406
407
408
409
410
411
412
413
414
415
416
417
418
419

	uplevel 1 [list tcc4tcl::ccommand $name {dummy ip objc objv} $cbody]

	return $name
}

#-------------------------------------------------------------------
proc ::tcc4tcl::ccommand {procname anames body {addfuncs ""}} {
	variable tcc

	# Fully qualified proc name
	if {[string match "::*" $procname]} {
		# procname is already absolute
	} else {
		set nsfrom [uplevel 1 {namespace current}]    
458
459
460
461
462
463
464
465
466








467
468
469
470
471
472
473
		append code $tcc(code)
		append code "\n"
	}
	set tcc(code) ""

	append code "int $cname (ClientData $v(clientdata),Tcl_Interp *$v(interp),"
	append code "int $v(objc),Tcl_Obj *CONST $v(objv)\[\]) {" "\n"
	append code [lindex $args end] "\n"
	append code "}" "\n"









	if {[catch {
		uplevel 1 [list tcc4tcl::cc $code]
	} err]} {
		unset tcc(cc)
		tcc4tcl::reset








|

>
>
>
>
>
>
>
>







458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
		append code $tcc(code)
		append code "\n"
	}
	set tcc(code) ""

	append code "int $cname (ClientData $v(clientdata),Tcl_Interp *$v(interp),"
	append code "int $v(objc),Tcl_Obj *CONST $v(objv)\[\]) {" "\n"
	append code $body "\n"
	append code "}" "\n"

	if {[llength $addfuncs] > 0} {
		set tcc(cc) [tcc4tcl::new]

		foreach addfunc $addfuncs {
			$tcc(cc) add_runtime_sym $addfunc
		}
	}

	if {[catch {
		uplevel 1 [list tcc4tcl::cc $code]
	} err]} {
		unset tcc(cc)
		tcc4tcl::reset

Modified test from [cf0138864c] to [e2e01fc434].

13
14
15
16
17
18
19













20
21
22
23
24
25







}

# This should work
tcc4tcl::cproc test3 {int i} int { return(i+42); }

# Multiple arguments
tcc4tcl::cproc add {int a int b} int { return(a+b); }














puts [test 1]
puts [test1 1]
puts [test3 1]
puts [::bob::test1 1]
puts [add [test 1] 1]














>
>
>
>
>
>
>
>
>
>
>
>
>






>
>
>
>
>
>
>
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
}

# This should work
tcc4tcl::cproc test3 {int i} int { return(i+42); }

# Multiple arguments
tcc4tcl::cproc add {int a int b} int { return(a+b); }

# Add external functions
tcc4tcl::cproc mkdir {char* dir} ok {
	int rv;

	rv = mkdir(dir);
	if (rv == 0) {
		return(TCL_OK);
	};

	return(TCL_ERROR);
} [list mkdir]


puts [test 1]
puts [test1 1]
puts [test3 1]
puts [::bob::test1 1]
puts [add [test 1] 1]

catch {
	puts [mkdir "/"]
} err
if {$err != ""} {
	error "\[mkdir\] did not return the expected error"
}