[prev in list] [next in list] [prev in thread] [next in thread]
List: mono-patches
Subject: [Mono-patches] mono/mono/metadata ChangeLog,1.1913,1.1914 image.c,1.91,1.92
From: lluis () mono-cvs ! ximian ! com (Lluis Sanchez <lluis () ximian ! com>)
Date: 2004-09-30 15:30:03
Message-ID: 20040930153003.B07B094762 () mono-cvs ! ximian ! com
[Download RAW message or body]
Update of /cvs/public/mono/mono/metadata
In directory mono-cvs.ximian.com:/tmp/cvs-serv1223
Modified Files:
ChangeLog image.c
Log Message:
* image.c: Always canonicalize image file names, to avoid loading
the same assembly twice when referenced using a relative path.
Index: ChangeLog
===================================================================
RCS file: /cvs/public/mono/mono/metadata/ChangeLog,v
retrieving revision 1.1913
retrieving revision 1.1914
diff -u -d -r1.1913 -r1.1914
--- ChangeLog 30 Sep 2004 10:28:34 -0000 1.1913
+++ ChangeLog 30 Sep 2004 15:30:01 -0000 1.1914
@@ -1,3 +1,8 @@
+2004-09-30 Lluis Sanchez Gual <lluis@novell.com>
+
+ * image.c: Always canonicalize image file names, to avoid loading
+ the same assembly twice when referenced using a relative path.
+
2004-09-30 Zoltan Varga <vargaz@freemail.hu>
* marshal.h marshal.c icall.c: Fix bugs in previous patch.
Index: image.c
===================================================================
RCS file: /cvs/public/mono/mono/metadata/image.c,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -d -r1.91 -r1.92
--- image.c 28 Sep 2004 11:30:44 -0000 1.91
+++ image.c 30 Sep 2004 15:30:01 -0000 1.92
@@ -75,6 +75,48 @@
return NULL;
}
+static gchar *
+canonicalize_path (const char *path)
+{
+ gchar *abspath, *pos, *lastpos, *dest;
+ int backc;
+
+ if (g_path_is_absolute (path)) {
+ abspath = g_strdup (path);
+ } else {
+ gchar *tmpdir = g_get_current_dir ();
+ abspath = g_build_filename (tmpdir, path, NULL);
+ g_free (tmpdir);
+ }
+
+ abspath = g_strreverse (abspath);
+
+ backc = 0;
+ dest = lastpos = abspath;
+ pos = strchr (lastpos, G_DIR_SEPARATOR);
+
+ while (pos != NULL) {
+ int len = pos - lastpos;
+ if (len == 1 && lastpos [0] == '.') {
+ // nop
+ } else if (len == 2 && lastpos [0] == '.' && lastpos [1] == '.') {
+ backc++;
+ } else if (len > 0) {
+ if (backc > 0) {
+ backc--;
+ } else {
+ if (dest != lastpos) strncpy (dest, lastpos, len + 1);
+ dest += len + 1;
+ }
+ }
+ lastpos = pos + 1;
+ pos = strchr (lastpos, G_DIR_SEPARATOR);
+ }
+
+ if (dest != lastpos) strcpy (dest, lastpos);
+ return g_strreverse (abspath);
+}
+
/**
* mono_images_init:
*
@@ -771,14 +813,7 @@
image->f = filed;
iinfo = g_new0 (MonoCLIImageInfo, 1);
image->image_info = iinfo;
-
- if (g_path_is_absolute (fname))
- image->name = g_strdup (fname);
- else {
- gchar *path = g_get_current_dir ();
- image->name = g_build_filename (path, fname, NULL);
- g_free (path);
- }
+ image->name = canonicalize_path (fname);
return do_mono_image_load (image, status);
}
@@ -856,13 +891,7 @@
g_return_val_if_fail (fname != NULL, NULL);
- if (g_path_is_absolute (fname))
- absfname = (char*)fname;
- else {
- gchar *path = g_get_current_dir ();
- absfname = g_build_filename (path, fname, NULL);
- g_free (path);
- }
+ absfname = canonicalize_path (fname);
/*
* The easiest solution would be to do all the loading inside the mutex,
@@ -872,9 +901,7 @@
*/
EnterCriticalSection (&images_mutex);
image = g_hash_table_lookup (loaded_images_hash, absfname);
-
- if (absfname != fname)
- g_free (absfname);
+ g_free (absfname);
if (image){
image->ref_count++;
@@ -888,13 +915,13 @@
return NULL;
EnterCriticalSection (&images_mutex);
- image2 = g_hash_table_lookup (loaded_images_hash, fname);
+ image2 = g_hash_table_lookup (loaded_images_hash, image->name);
+
if (image2) {
/* Somebody else beat us to it */
image2->ref_count ++;
LeaveCriticalSection (&images_mutex);
mono_image_close (image);
-
return image2;
}
g_hash_table_insert (loaded_images_hash, image->name, image);
_______________________________________________
Mono-patches maillist - Mono-patches@ximian.com
http://lists.ximian.com/mailman/listinfo/mono-patches
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic