summaryrefslogtreecommitdiffstats
path: root/mac/tclMacResource.c
diff options
context:
space:
mode:
Diffstat (limited to 'mac/tclMacResource.c')
-rw-r--r--mac/tclMacResource.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/mac/tclMacResource.c b/mac/tclMacResource.c
index db06571..0689860 100644
--- a/mac/tclMacResource.c
+++ b/mac/tclMacResource.c
@@ -1241,7 +1241,7 @@ Tcl_MacEvalResource(
Handle sourceText;
Str255 rezName;
char msg[200];
- int result;
+ int result, iOpenedResFile = false;
short saveRef, fileRef = -1;
char idStr[64];
FSSpec fileSpec;
@@ -1257,7 +1257,8 @@ Tcl_MacEvalResource(
if (nativeName == NULL) {
return TCL_ERROR;
}
- err = FSpLocationFromPath(strlen(nativeName), nativeName, &fileSpec);
+ err = FSpLocationFromPath(strlen(nativeName), nativeName,
+ &fileSpec);
Tcl_DStringFree(&buffer);
if (err != noErr) {
Tcl_AppendResult(interp, "Error finding the file: \"",
@@ -1273,6 +1274,7 @@ Tcl_MacEvalResource(
}
UseResFile(fileRef);
+ iOpenedResFile = true;
} else {
/*
* The default behavior will search through all open resource files.
@@ -1313,7 +1315,8 @@ Tcl_MacEvalResource(
if (result == TCL_RETURN) {
result = TCL_OK;
} else if (result == TCL_ERROR) {
- sprintf(msg, "\n (rsrc \"%.150s\" line %d)", resourceName,
+ sprintf(msg, "\n (rsrc \"%.150s\" line %d)",
+ resourceName,
interp->errorLine);
Tcl_AddErrorInfo(interp, msg);
}
@@ -1330,12 +1333,27 @@ Tcl_MacEvalResource(
".", NULL);
rezEvalCleanUp:
+
+ /*
+ * TRICKY POINT: The code that you are sourcing here could load a
+ * shared library. This will go AHEAD of the resource we stored away
+ * in saveRef on the resource path.
+ * If you restore the saveRef in this case, you will never be able
+ * to get to the resources in the shared library, since you are now
+ * pointing too far down on the resource list.
+ * So, we only reset the current resource file if WE opened a resource
+ * explicitly, and then only if the CurResFile is still the
+ * one we opened...
+ */
+
+ if (iOpenedResFile && (CurResFile() == fileRef)) {
+ UseResFile(saveRef);
+ }
+
if (fileRef != -1) {
CloseResFile(fileRef);
}
- UseResFile(saveRef);
-
return result;
}