Diff
Not logged in

Differences From Artifact [12c03ede3c]:

To Artifact [41a919782a]:


8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22







-
+







 *
 * Copyright (c) 1995 Apple Computer, Inc.
 * Copyright (c) 2001-2007 Daniel A. Steffen <das@users.sourceforge.net>
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclLoadDyld.c,v 1.35 2010/04/02 21:21:06 kennykb Exp $
 * RCS: @(#) $Id: tclLoadDyld.c,v 1.36 2010/04/02 22:52:26 dkf Exp $
 */

#include "tclInt.h"

#ifndef MODULE_SCOPE
#define MODULE_SCOPE extern
#endif
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
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







-
-
-
-
+
+
+
+
+
+



-
-
+
+
+
+

-
-
-
+
+
+
-
-



















-
+








#if (TCL_DYLD_USE_DLFCN && MAC_OS_X_VERSION_MIN_REQUIRED < 1040) || \
	defined(TCL_LOAD_FROM_MEMORY)
MODULE_SCOPE long tclMacOSXDarwinRelease;
#endif

#ifdef TCL_DEBUG_LOAD
#define TclLoadDbgMsg(m, ...) do { \
	    fprintf(stderr, "%s:%d: %s(): " m ".\n", \
	    strrchr(__FILE__, '/')+1, __LINE__, __func__, ##__VA_ARGS__); \
	} while (0)
#define TclLoadDbgMsg(m, ...) \
    do {								\
	fprintf(stderr, "%s:%d: %s(): " m ".\n",			\
		strrchr(__FILE__, '/')+1, __LINE__, __func__,		\
		##__VA_ARGS__);						\
    } while (0)
#else
#define TclLoadDbgMsg(m, ...)
#endif

/* Static functions defined in this file */

/*
 * Static functions defined in this file.
 */

static void* FindSymbol(Tcl_Interp* interp, Tcl_LoadHandle loadHandle,
			const char* symbol);
static void UnloadFile(Tcl_LoadHandle handle);
static void *		FindSymbol(Tcl_Interp *interp,
			    Tcl_LoadHandle loadHandle, const char *symbol);
static void		UnloadFile(Tcl_LoadHandle handle);



#if TCL_DYLD_USE_NSMODULE || defined(TCL_LOAD_FROM_MEMORY)
/*
 *----------------------------------------------------------------------
 *
 * DyldOFIErrorMsg --
 *
 *	Converts a numerical NSObjectFileImage error into an error message
 *	string.
 *
 * Results:
 *	Error message string.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static const char*
static const char *
DyldOFIErrorMsg(
    int err)
{
    switch(err) {
    case NSObjectFileImageSuccess:
	return NULL;
    case NSObjectFileImageFailure:
171
172
173
174
175
176
177
178

179
180
181
182
183
184
185
173
174
175
176
177
178
179

180
181
182
183
184
185
186
187







-
+







				 * (*unloadProcPtr)() to unload the file. */
    Tcl_FSUnloadFileProc **unloadProcPtr)
				/* Filled with address of Tcl_FSUnloadFileProc
				 * function which should be used for this
				 * file. */
{
    Tcl_DyldLoadHandle *dyldLoadHandle;
    Tcl_LoadHandle* newHandle;
    Tcl_LoadHandle newHandle;
#if TCL_DYLD_USE_DLFCN
    void *dlHandle = NULL;
#endif
#if TCL_DYLD_USE_NSMODULE || defined(TCL_LOAD_FROM_MEMORY)
    const struct mach_header *dyldLibHeader = NULL;
    Tcl_DyldModuleHandle *modulePtr = NULL;
#endif
315
316
317
318
319
320
321
322

323
324
325
326
327
328
329
317
318
319
320
321
322
323

324
325
326
327
328
329
330
331







-
+







#if TCL_DYLD_USE_NSMODULE || defined(TCL_LOAD_FROM_MEMORY)
	dyldLoadHandle->dyldLibHeader = dyldLibHeader;
	dyldLoadHandle->modulePtr = modulePtr;
#endif
	newHandle = (Tcl_LoadHandle) ckalloc(sizeof(*newHandle));
	newHandle->clientData = dyldLoadHandle;
	newHandle->findSymbolProcPtr = &FindSymbol;
	newHandle->unloadProcPtr = &UnloadFile;
	newHandle->unloadFileProcPtr = &UnloadFile;
	*unloadProcPtr = &UnloadFile;
	*loadHandle = newHandle;
	result = TCL_OK;
    } else {
	Tcl_AppendResult(interp, errMsg, NULL);
#if TCL_DYLD_USE_NSMODULE
	if (objFileImageErrMsg) {
351
352
353
354
355
356
357
358

359
360
361
362
363
364

365
366
367
368
369
370
371
372
353
354
355
356
357
358
359

360
361
362
363
364
365

366

367
368
369
370
371
372
373







-
+





-
+
-







 *	Returns a pointer to the function associated with 'symbol' if it is
 *	found. Otherwise returns NULL and may leave an error message in the
 *	interp's result.
 *
 *----------------------------------------------------------------------
 */

static void*
static void *
FindSymbol(
    Tcl_Interp *interp,		/* For error reporting. */
    Tcl_LoadHandle loadHandle,	/* Handle from TclpDlopen. */
    const char *symbol)		/* Symbol name to look up. */
{
    Tcl_DyldLoadHandle *dyldLoadHandle =
    Tcl_DyldLoadHandle *dyldLoadHandle = loadHandle->clientData;
	(Tcl_DyldLoadHandle *) (loadHandle->clientData);
    Tcl_PackageInitProc *proc = NULL;
    const char *errMsg = NULL;
    Tcl_DString ds;
    const char *native;

    native = Tcl_UtfToExternalDString(NULL, symbol, -1, &ds);
#if TCL_DYLD_USE_DLFCN
448
449
450
451
452
453
454
455


456
457
458
459
460
461
462
449
450
451
452
453
454
455

456
457
458
459
460
461
462
463
464







-
+
+







	}
	Tcl_DStringFree(&newName);
#endif /* TCL_DYLD_USE_NSMODULE */
    }
    Tcl_DStringFree(&ds);
    if (errMsg && (interp != NULL)) {
	Tcl_AppendResult(interp, errMsg, NULL);
	Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol, NULL);
	Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol,
		NULL);
    }
    return proc;
}

/*
 *----------------------------------------------------------------------
 *
479
480
481
482
483
484
485
486

487
488
489
490
491
492
493
494
481
482
483
484
485
486
487

488

489
490
491
492
493
494
495







-
+
-








static void
UnloadFile(
    Tcl_LoadHandle loadHandle)	/* loadHandle returned by a previous call to
				 * TclpDlopen(). The loadHandle is a token
				 * that represents the loaded file. */
{
    Tcl_DyldLoadHandle *dyldLoadHandle = 
    Tcl_DyldLoadHandle *dyldLoadHandle = loadHandle->clientData;
	(Tcl_DyldLoadHandle *) (loadHandle->clientData);

#if TCL_DYLD_USE_DLFCN
    if (dyldLoadHandle->dlHandle) {
	int result;

	result = dlclose(dyldLoadHandle->dlHandle);
	if (!result) {
515
516
517
518
519
520
521
522
523


524
525
526
527
528
529
530
516
517
518
519
520
521
522


523
524
525
526
527
528
529
530
531







-
-
+
+







	    }
	    ptr = modulePtr;
	    modulePtr = modulePtr->nextPtr;
	    ckfree(ptr);
	}
#endif /* TCL_DYLD_USE_NSMODULE */
    }
    ckfree((char*) dyldLoadHandle);
    ckfree((char*) loadHandle);
    ckfree((char *) dyldLoadHandle);
    ckfree((char *) loadHandle);
}

/*
 *----------------------------------------------------------------------
 *
 * TclGuessPackageName --
 *