From d0b8c37638a26f4338e1d2af32aa910d92642f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Sun, 17 Jul 2011 10:57:55 +0000 Subject: [PATCH] [INTERPRETER] * NEW: Remove the unused GB.ExistFile() API. * NEW: Exist() now takes an additional optional boolean argument that tells if symbolic links must be followed, like Stat(). * BUG: Fix a possible memory leak if the [...] array creation operator fails for any reason. git-svn-id: svn://localhost/gambas/trunk@3940 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- app/src/gambas3/.src/Editor/Code/FCompletion.class | 1 - .../Networking/WebBrowser/.src/FBrowser.class | 2 +- gb.dbus/src/gb.dbus/.settings | 6 +++--- main/gbx/gbx_api.c | 7 ++++++- main/gbx/gbx_api.h | 1 + main/gbx/gbx_class_info.c | 2 +- main/gbx/gbx_exec_loop.c | 2 +- main/gbx/gbx_subr.h | 2 +- main/gbx/gbx_subr_file.c | 10 +++++++--- main/gbx/gbx_subr_misc.c | 10 +++++----- main/share/gambas.h | 1 - main/share/gb_file_share.h | 5 +++-- main/share/gb_file_temp.h | 13 ++----------- main/share/gb_reserved_keyword.h | 2 +- 14 files changed, 32 insertions(+), 32 deletions(-) diff --git a/app/src/gambas3/.src/Editor/Code/FCompletion.class b/app/src/gambas3/.src/Editor/Code/FCompletion.class index 932ba9de4..b02633930 100644 --- a/app/src/gambas3/.src/Editor/Code/FCompletion.class +++ b/app/src/gambas3/.src/Editor/Code/FCompletion.class @@ -485,7 +485,6 @@ Private Sub FillWithSpecial() End - ' PUBLIC SUB Form_Resize() ' ' 'PRINT "Form_Resize: ME.H = "; ME.H; " Me.ClientH =";ME.ClientH diff --git a/examples/examples/Networking/WebBrowser/.src/FBrowser.class b/examples/examples/Networking/WebBrowser/.src/FBrowser.class index 0571fc60e..5e69571b5 100644 --- a/examples/examples/Networking/WebBrowser/.src/FBrowser.class +++ b/examples/examples/Networking/WebBrowser/.src/FBrowser.class @@ -33,7 +33,7 @@ Public Sub Form_Open() tabBrowser_Click 'txtURL.Text = "http://gambas.sourceforge.net" 'txtURL_Activate - + End Private Sub GetView() As WebView diff --git a/gb.dbus/src/gb.dbus/.settings b/gb.dbus/src/gb.dbus/.settings index 62ea4153e..899554fa9 100644 --- a/gb.dbus/src/gb.dbus/.settings +++ b/gb.dbus/src/gb.dbus/.settings @@ -36,12 +36,12 @@ SearchComment=False SearchString=True [OpenFile] -File[1]=".src/MMain.module:36.32" +Active=1 +File[1]=".src/MMain.module:30.2" File[2]=".src/DBusApplication.class:92.29" File[3]=".src/DBus.class:9.0" File[4]=".src/DBusProxy.class:154.0" -Active=5 -File[5]=".src/DBusObject.class:391.2" +File[5]=".src/DBusObject.class:390.7" File[6]=".src/CTest.class:11.2" File[7]=".src/DBusSignal.class:18.3" Count=7 diff --git a/main/gbx/gbx_api.c b/main/gbx/gbx_api.c index 967553a67..27351ecdf 100644 --- a/main/gbx/gbx_api.c +++ b/main/gbx/gbx_api.c @@ -170,7 +170,6 @@ void *GAMBAS_Api[] = (void *)GB_LoadFile, (void *)STREAM_unmap, - (void *)FILE_exist, (void *)GB_TempDir, (void *)GB_TempFile, (void *)GB_CopyFile, @@ -1378,6 +1377,12 @@ bool GB_LoadFile(const char *path, int lenp, char **addr, int *len) } +bool GB_ExistFile(const char *path) +{ + return FILE_exist(path); +} + + void GB_Store(GB_TYPE type, GB_VALUE *src, void *dst) { if (src != NULL) diff --git a/main/gbx/gbx_api.h b/main/gbx/gbx_api.h index ecc5aa085..3e11e6777 100644 --- a/main/gbx/gbx_api.h +++ b/main/gbx/gbx_api.h @@ -91,6 +91,7 @@ bool GB_ExistClassLocal(const char *name); char *GB_ToZeroString(GB_STRING *src); bool GB_LoadFile(const char *path, int lenp, char **addr, int *len); +bool GB_ExistFile(const char *path); //void GB_ReleaseFile(char **addr, int len); #define GB_ReleaseFile STREAM_unmap char *GB_RealFileName(const char *path, int len); diff --git a/main/gbx/gbx_class_info.c b/main/gbx/gbx_class_info.c index 4337089c9..1afb2fc2b 100644 --- a/main/gbx/gbx_class_info.c +++ b/main/gbx/gbx_class_info.c @@ -241,7 +241,7 @@ static GB_DESC NATIVE_GambasLanguage[] = GB_METHOD("Lof", "l", NULL, "[(File)Stream;]"), GB_METHOD("Seek", "l", NULL, "(File)Stream;"), - GB_METHOD("Exist", "b", NULL, "(Path)s"), + GB_METHOD("Exist", "b", NULL, "(Path)s[(FollowLink)b]"), GB_METHOD("Stat", "Stat", NULL, "(Path)s[(FollowLink)b]"), GB_METHOD("Temp$", "s", NULL, "[(Prefix)s]"), diff --git a/main/gbx/gbx_exec_loop.c b/main/gbx/gbx_exec_loop.c index 03ed8b6af..2a220167c 100644 --- a/main/gbx/gbx_exec_loop.c +++ b/main/gbx/gbx_exec_loop.c @@ -323,7 +323,7 @@ void EXEC_loop(void) /* 88 Move */ &&_SUBR, /* 89 Copy */ &&_SUBR, /* 8A Link */ &&_SUBR, - /* 8B Exist */ &&_SUBR, + /* 8B Exist */ &&_SUBR_CODE, /* 8C Access */ &&_SUBR_CODE, /* 8D Stat */ &&_SUBR_CODE, /* 8E Dfree */ &&_SUBR, diff --git a/main/gbx/gbx_subr.h b/main/gbx/gbx_subr.h index 607f57661..2bd4e80ae 100644 --- a/main/gbx/gbx_subr.h +++ b/main/gbx/gbx_subr.h @@ -198,7 +198,7 @@ void SUBR_lock(ushort code); void SUBR_inp_out(ushort code); void SUBR_stat(ushort code); -void SUBR_exist(void); +void SUBR_exist(ushort code); void SUBR_dir(ushort code); void SUBR_kill(void); void SUBR_mkdir(void); diff --git a/main/gbx/gbx_subr_file.c b/main/gbx/gbx_subr_file.c index dbc6c4696..0146e1382 100755 --- a/main/gbx/gbx_subr_file.c +++ b/main/gbx/gbx_subr_file.c @@ -511,16 +511,20 @@ void SUBR_stat(ushort code) } -void SUBR_exist(void) +void SUBR_exist(ushort code) { bool exist; const char *path; + bool follow = FALSE; - SUBR_ENTER_PARAM(1); + SUBR_ENTER(); path = get_path(PARAM); - exist = FILE_exist(path); + if (NPARAM == 2) + follow = SUBR_get_boolean(&PARAM[1]); + + exist = FILE_exist_follow(path, follow); RETURN->type = T_BOOLEAN; RETURN->_integer.value = exist ? -1 : 0; diff --git a/main/gbx/gbx_subr_misc.c b/main/gbx/gbx_subr_misc.c index c88f6ceaa..12f9c6a36 100644 --- a/main/gbx/gbx_subr_misc.c +++ b/main/gbx/gbx_subr_misc.c @@ -299,7 +299,6 @@ _FREE: SUBR_LEAVE(); } - void SUBR_array(ushort code) { TYPE type; @@ -313,17 +312,18 @@ void SUBR_array(ushort code) if (type == T_NULL) type = T_OBJECT; + for (i = 0; i < NPARAM; i++) + VALUE_conv(&PARAM[i], type); + GB_ArrayNew(&array, type, NPARAM); + OBJECT_REF(array, "SUBR_array"); - // FIXME: If there is an error, the array is not freed! for (i = 0; i < NPARAM; i++) { - VALUE_conv(&PARAM[i], type); GB_Store(type, (GB_VALUE *)&PARAM[i], GB_ArrayGet(array, i)); RELEASE(&PARAM[i]); } - - OBJECT_REF(array, "SUBR_array"); + PARAM->_object.class = OBJECT_class(array); //CLASS_Array; PARAM->_object.object = array; SP = PARAM + 1; diff --git a/main/share/gambas.h b/main/share/gambas.h index c894f5737..2578a9fde 100644 --- a/main/share/gambas.h +++ b/main/share/gambas.h @@ -887,7 +887,6 @@ typedef bool (*LoadFile)(const char *, int, char **, int *); void (*ReleaseFile)(char *, int); - bool (*ExistFile)(char *); char *(*TempDir)(void); char *(*TempFile)(const char *); bool (*CopyFile)(const char *, const char *); diff --git a/main/share/gb_file_share.h b/main/share/gb_file_share.h index b23772487..7c8e38d00 100644 --- a/main/share/gb_file_share.h +++ b/main/share/gb_file_share.h @@ -94,8 +94,6 @@ bool FILE_is_dir(const char *path); const char *FILE_find_gambas(void); -bool FILE_exist(const char *path); - void FILE_rename(const char *src, const char *dst); void FILE_unlink(const char *path); @@ -105,6 +103,8 @@ void FILE_init(void); void FILE_remove_temp_file(void); void FILE_exit(void); +bool FILE_exist_follow(const char *path, bool follow); +#define FILE_exist(_path) FILE_exist_follow(_path, FALSE) bool FILE_exist_real(const char *path); void FILE_stat(const char *path, FILE_STAT *info, bool follow); @@ -128,6 +128,7 @@ int64_t FILE_free(const char *path); #else +bool FILE_exist(const char *path); time_t FILE_get_time(const char *path); #endif diff --git a/main/share/gb_file_temp.h b/main/share/gb_file_temp.h index e24800f88..c98353882 100644 --- a/main/share/gb_file_temp.h +++ b/main/share/gb_file_temp.h @@ -812,23 +812,14 @@ bool FILE_access(const char *path, int mode) } -bool FILE_exist(const char *path) +bool FILE_exist_follow(const char *path, bool follow) { struct stat buf; if (FILE_is_relative(path)) - { - /*if (!EXEC_arch) - { - chdir(PROJECT_path); - if (lstat(path, &buf) == 0) - return TRUE; - }*/ - return ARCHIVE_exist(NULL, path); - } - return lstat(path, &buf) == 0; + return follow ? (stat(path, &buf) == 0) : (lstat(path, &buf) == 0); } diff --git a/main/share/gb_reserved_keyword.h b/main/share/gb_reserved_keyword.h index 25cc70a73..672690ea3 100644 --- a/main/share/gb_reserved_keyword.h +++ b/main/share/gb_reserved_keyword.h @@ -454,7 +454,7 @@ SUBR_INFO COMP_subr_info[] = { ".Copy", 73, 0, 2 }, { ".Link", 74, 0, 2 }, #endif - { "Exist", 75, 0, 1 }, + { "Exist", 75, 0, 1, 2 }, { "Access", 76, 0, 1, 2 }, { "Stat", 77, 0, 1, 2 }, { "Dfree", 78, 0, 1 },