object cfc4c487d685814dbd19f0cd95af7c36c8dbf3f5

0 views
Skip to first unread message

letha...@gmail.com

unread,
May 24, 2009, 11:19:16 AM5/24/09
to syx-c...@googlegroups.com
Branch: object
commit cfc4c487d685814dbd19f0cd95af7c36c8dbf3f5
Author: Luca Bruno <letha...@gmail.com>
Date: Sun May 24 17:14:44 2009 +0200

Add syx_file_exists and fix image resolution order on initialization.

:100644 100644 454660c... 3117090... M ChangeLog
:100644 100644 861421b... a622552... M doc/manual/introsyx.texi
:100644 100644 e8400f9... 0100480... M examples/embedding/add.c
:100644 100644 44b55c2... 7c646bf... M syx/syx-init.c
:100644 100644 7397f6f... ea2bb34... M syx/syx-utils.c
:100644 100644 b399f88... 33993f6... M syx/syx-utils.h

diff --git a/ChangeLog b/ChangeLog
index 454660c..3117090 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
2009-05-24 Luca Bruno <letha...@gmail.com>

+ * syx/syx-utils.c (syx_file_exists): added
+
* syx/syx-primitives.c (FileStream_fileOp): free obtained string with #next:, fixes memory leak

* syx/syx-memory.c (syx_memory_clear, _syx_memory_gc_compact): free stacks to avoid memory leaks
@@ -9,6 +11,7 @@
* syx/syx-interp.c (syx_interp_init): reset state

* syx/syx-init.c (syx_initialize_system): use the right startupProcess variable
+ (syx_init): fix image resolution order

* syx/syx-object.c (_syx_struct_sizes): ensure HAVE_LIBGMP for large integer size

diff --git a/doc/manual/introsyx.texi b/doc/manual/introsyx.texi
index 861421b..a622552 100644
--- a/doc/manual/introsyx.texi
+++ b/doc/manual/introsyx.texi
@@ -174,6 +174,7 @@ Specify the @emph{image} to load. This can be specified also with the @var{SYX_I
@item check for @command{-i, --image}
@item check for a @file{default.sim} in the current directory
@item check for the @var{SYX_IMAGE_PATH} environment variable
+@item check for a @file{default.sim} in the root directory
@item use the default path specified at compile time (usually @file{/usr/share/syx/default.sim})
@end enumerate

diff --git a/examples/embedding/add.c b/examples/embedding/add.c
index e8400f9..0100480 100644
--- a/examples/embedding/add.c
+++ b/examples/embedding/add.c
@@ -8,10 +8,12 @@ int main (int argc, char *argv[])
SyxOop result;

/* initialize Syx */
- syx_init (argc, argv, NULL);
+ if (!syx_init (argc, argv, NULL))
+ syx_error ("Couldn't initialize Syx");

/* load the default image */
- syx_memory_load_image (NULL);
+ if (!syx_memory_load_image (NULL))
+ syx_error ("Couldn't load image");

/* now file in class and method declarations from our ST file */
syx_file_in_blocking ("add.st");
diff --git a/syx/syx-init.c b/syx/syx-init.c
index 44b55c2..7c646bf 100644
--- a/syx/syx-init.c
+++ b/syx/syx-init.c
@@ -387,21 +387,8 @@ syx_init (syx_varsize argc, syx_string *argv, syx_symbol root_path)
goto end;
#endif

- /* first look in the root directory */
- if (root_path && !strcmp (root_path, _syx_root_path))
- {
- _syx_image_path = (syx_string) syx_malloc (strlen (_syx_root_path) + 13);
- sprintf ((syx_string) _syx_image_path, "%s%c%s", _syx_root_path, SYX_PATH_SEPARATOR, "default.sim");
- initialized = TRUE;
- return TRUE;
- }
-
/* first look in the working directory */
-#ifdef HAVE_ACCESS
- if (access ("default.sim", R_OK) == 0)
-#else
- if (fopen ("default.sim", "r"))
-#endif
+ if (syx_file_exists ("default.sim"))
{
_syx_image_path = "default.sim";
goto end;
@@ -413,6 +400,15 @@ syx_init (syx_varsize argc, syx_string *argv, syx_symbol root_path)
if (_syx_image_path)
goto end;
#endif
+
+ /* in the root directory */
+ _syx_image_path = (syx_string) syx_malloc (strlen (_syx_root_path) + 13);
+ sprintf ((syx_string) _syx_image_path, "%s%c%s", _syx_root_path, SYX_PATH_SEPARATOR, "default.sim");
+ if (syx_file_exists (_syx_image_path))
+ {
+ initialized = TRUE;
+ return TRUE;
+ }

/* return the default path defined by the installation */
_syx_image_path = SYX_IMAGE_PATH;
@@ -479,12 +475,7 @@ syx_set_root_path (syx_symbol root_path)

_syx_root_path = syx_strdup (root_path);

-#ifdef HAVE_ACCESS
- if (access (_syx_root_path, R_OK) < 0)
- return FALSE;
-#endif
-
- return TRUE;
+ return syx_file_exists (_syx_root_path);
}

/*! Sets the initial image path */
diff --git a/syx/syx-utils.c b/syx/syx-utils.c
index 7397f6f..ea2bb34 100644
--- a/syx/syx-utils.c
+++ b/syx/syx-utils.c
@@ -651,6 +651,23 @@ syx_find_first_non_whitespace (syx_symbol string)
return 0;
}

+/*! Checks for file existance and its readability */
+syx_bool
+syx_file_exists (syx_symbol filename)
+{
+ if (!filename)
+ return FALSE;
+
+ FILE *f = fopen (filename, "r");
+ if (f)
+ {
+ fclose (f);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
/*! Print to stdout the current execution state of the interpreter and the Process traceback */
void
syx_show_traceback (void)
diff --git a/syx/syx-utils.h b/syx/syx-utils.h
index b399f88..33993f6 100644
--- a/syx/syx-utils.h
+++ b/syx/syx-utils.h
@@ -70,6 +70,10 @@ EXPORT syx_wstring syx_to_wstring (syx_symbol s);
EXPORT syx_string syx_to_string (syx_wsymbol ws);
EXPORT syx_uint32 syx_find_first_non_whitespace (syx_symbol string);

+/* File operations */
+
+EXPORT syx_bool syx_file_exists (syx_symbol filename) SYX_GNUC_UNUSED;
+

#ifdef UNICODE

Reply all
Reply to author
Forward
0 new messages