bug 3647
Allan Cornet [Thu, 9 Oct 2008 10:13:05 +0000 (10:13 +0000)]
scilab/CHANGES_5.1
scilab/modules/dynamic_link/macros/ilib_for_link.sci
scilab/modules/dynamic_link/macros/ilib_gen_loader.sci
scilab/modules/dynamic_link/sci_gateway/fortran/sci_fort.f
scilab/modules/dynamic_link/src/c/AddFunctionInTable.c
scilab/modules/dynamic_link/tests/nonreg_tests/bug_3647.tst [new file with mode: 0644]
scilab/modules/dynamic_link/tests/nonreg_tests/bug_3647.win.dia.ref [new file with mode: 0644]

index 7ffa39b..f6077d2 100644 (file)
@@ -86,3 +86,5 @@ Bug fixes:
 * bug 3630 fixed - functions added by 'addinter' are not visible by 'what'
 
 * bug 3604 fixed - Problems with getting Frame uicontrol position (Scilab crash)
+
+* bug 3647 fixed - 'call' doesn't manage external functions named with more 23 characters
index 75cf860..d1fcdf8 100644 (file)
@@ -134,13 +134,19 @@ function ilib_link_gen_loader(names,flag,loadername,libs,libname)
   
   lib_suf = getdynlibext();
   if libname=="" then libname = names(1);end 
-    
+  
+  if ( length(libname) + length('_path') ) > 24 then
+   shortlibname_path = part(libname,1:(24 - length('_path')));
+  else
+   shortlibname_path = libname;
+  end
+  
   fd=mopen(loadername,"w");
   mfprintf(fd,"// ------------------------------------------------------\n");
   mfprintf(fd,"// generated by builder.sce: Please do not edit this file\n");
   mfprintf(fd,"// ------------------------------------------------------\n");
   mfprintf(fd,"\n");
-  mfprintf(fd,"%s_path = get_absolute_file_path(''%s'');\n",libname,basename(loadername+'.x'));
+  mfprintf(fd,"%s_path = get_absolute_file_path(''%s'');\n",shortlibname_path,basename(loadername+'.x'));
   mfprintf(fd,"\n");
   
   //** first "link" : external libraries 
@@ -155,7 +161,7 @@ function ilib_link_gen_loader(names,flag,loadername,libs,libname)
          else
            [diri, basenamei, exti] = fileparts(libs(i));
            if (diri == '') then
-            mfprintf(fd,"link(%s_path+''%s%s'');\n",libname,libs(i),lib_suf);
+            mfprintf(fd,"link(%s_path+''%s%s'');\n",shortlibname_path,libs(i),lib_suf);
            else
             mfprintf(fd,"link(''%s%s'');\n",libs(i),lib_suf);
            end
@@ -164,7 +170,7 @@ function ilib_link_gen_loader(names,flag,loadername,libs,libname)
   end  
   
   //** second "link" : user defined functions  
-  mfprintf(fd,"link(%s_path+''lib%s%s'',[",libname,libname,lib_suf);
+  mfprintf(fd,"link(%s_path+''lib%s%s'',[",shortlibname_path,libname,lib_suf);
   
   names = names(:)';
   n = size(names,'*');
@@ -188,7 +194,7 @@ function ilib_link_gen_loader(names,flag,loadername,libs,libname)
 
   mfprintf(fd,"''%s'');\n",flag);
   mfprintf(fd,"// remove temp. variables on stack\n");
-  mfprintf(fd,"clear %s_path;\n",libname);
+  mfprintf(fd,"clear %s_path;\n",shortlibname_path);
   mfprintf(fd,"clear get_file_path;\n");
   mfprintf(fd,"// ------------------------------------------------------\n");
   mclose(fd);
index 758ac28..2098ce9 100644 (file)
@@ -25,16 +25,22 @@ function ilib_gen_loader(name,tables,libs)
     end 
   end
   
+  if length(name) + length('_path') > 24 then
+    name_path = part(name,1:(24 - length('_path')));
+  else
+    name_path = name;
+  end
+  
   fd=mopen('loader.sce',"wt");
   mfprintf(fd,"// ------------------------------------------------------\n");
   mfprintf(fd,"// generated by builder.sce: Please do not edit this file\n");
   mfprintf(fd,"// ------------------------------------------------------\n");
   mfprintf(fd,"\n");
-  mfprintf(fd,"%s_path = get_file_path(''loader.sce'');\n",name);
+  mfprintf(fd,"%s_path = get_file_path(''loader.sce'');\n",name_path);
 
   nl = size(libs,'*');
   for i=1:nl 
-    mfprintf(fd,"link(%s_path+''/%s%s'');\n",name,libs(i),getdynlibext());
+    mfprintf(fd,"link(%s_path+''/%s%s'');\n",name_path,libs(i),getdynlibext());
   end 
 
   if L == 1 then 
@@ -47,11 +53,11 @@ function ilib_gen_loader(name,tables,libs)
     end
     mfprintf(fd,"];\n");
 
-    mfprintf(fd,"addinter(%s_path+''/%s%s'',''%s'',list_functions);\n",name, ..
+    mfprintf(fd,"addinter(%s_path+''/%s%s'',''%s'',list_functions);\n",name_path, ..
                      name,getdynlibext(),name);
   else
     // on link then a set of addinter 
-    mfprintf(fd,"ilib = link(%s_path+filesep()+''%s%s'');\n",name, ..
+    mfprintf(fd,"ilib = link(%s_path+filesep()+''%s%s'');\n",name_path, ..
                 name,getdynlibext());
     for itable=1:L 
       // loop on a list of tables 
@@ -69,7 +75,7 @@ function ilib_gen_loader(name,tables,libs)
   end
   
   mfprintf(fd,"// remove temp. variables on stack\n");
-  mfprintf(fd,"clear %s_path;\n",name);
+  mfprintf(fd,"clear %s_path;\n",name_path);
   mfprintf(fd,"clear list_functions;\n");
   mfprintf(fd,"clear get_file_path;\n");
   mfprintf(fd,"// ------------------------------------------------------\n");
index 995b569..496a6bc 100644 (file)
@@ -38,11 +38,6 @@ c     get a scilab string the fort function name
       top2=top-rhs+1
       if(.not.getsmat(fname,top,top2,m1,n1,1,1,lrc,nc))return
       name=' '
-      if ( nc.gt.fortname ) then 
-         buf = fname // ' first argument must be of length < 24'
-         call error(999)
-         return
-      endif
       call cvstr(nc,istk(lrc),name,1)
       name(nc+1:nc+1)=char(0)
 C     Check the name in the <<fort>> table 
index e9236a9..1c56da2 100644 (file)
 #include "dynamic_link.h"
 #include "MALLOC.h"
 /*--------------------------------------------------------------------------*/
-#define MAXNAME 32
-static char buf[MAXNAME];
-/*--------------------------------------------------------------------------*/
 static BOOL SearchComp(FTAB *Ftab, char *op, void (**realop) ());
 static void Emptyfunc(void) {}
 /*--------------------------------------------------------------------------*/
 voidf AddFunctionInTable (char *name, int *rep, FTAB *table)
 {
        void (*loc)();
-       char *s = NULL;
-
-       strncpy(buf,name,MAXNAME);
-       s=buf;
-       while ( *s != ' ' && *s != '\0') { s++;};
-       *s= '\0';
 
-       if ( ( SearchComp(table,buf,&loc) == TRUE) || ( SearchInDynLinks(buf,&loc) >= 0 ) )
+       if (name)
        {
-               *rep = 0;
+               char *buf = (char*)MALLOC(sizeof(char)*(strlen(name)+1));
+               if (buf)
+               {
+                       char *s = NULL;
+                       strncpy(buf,name,(int)strlen(name));
+                       /* remove space */
+                       s = buf;
+                       while ( *s != ' ' && *s != '\0') { s++;};
+                       *s= '\0';
+                       /* search name in functions table */
+                       if ( ( SearchComp(table,buf,&loc) == TRUE) || ( SearchInDynLinks(buf,&loc) >= 0 ) )
+                       {
+                               *rep = 0;
+                       }
+                       else
+                       {
+                               loc = Emptyfunc;
+                               *rep = 1;
+                       }
+
+                       FREE(buf);
+                       buf = NULL;
+               }
+               else
+               {
+                       *rep = 0;
+               }
        }
        else
        {
-               loc = Emptyfunc;
-               *rep = 1;
+               *rep = 0;
        }
        return(loc);
 }
diff --git a/scilab/modules/dynamic_link/tests/nonreg_tests/bug_3647.tst b/scilab/modules/dynamic_link/tests/nonreg_tests/bug_3647.tst
new file mode 100644 (file)
index 0000000..3b28022
--- /dev/null
@@ -0,0 +1,42 @@
+// =============================================================================\r
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab\r
+// Copyright (C) 2008 - DIGITEO - Allan CORNET\r
+//\r
+//  This file is distributed under the same license as the Scilab package.\r
+// =============================================================================\r
+\r
+// <-- Non-regression test for bug 3647 -->\r
+//\r
+// <-- Bugzilla URL -->\r
+// http://bugzilla.scilab.org/show_bug.cgi?id=3647\r
+//\r
+// <-- Short Description -->\r
+// C functions having more than 23 characters are not usable with scilab\r
+\r
+\r
+foo=['void verylongfunctionnamewithmore24characters(double *a,double *b,double *c)';\r
+     '{ *c = *a + *b; }'  ];\r
+\r
+// we use TMPDIR for compilation \r
+       \r
+if ~c_link('foo') then\r
+  curPath = getcwd(); \r
+  chdir(TMPDIR); \r
+  mputl(foo,'foo.c');\r
+  \r
+  ilib_for_link(['verylongfunctionnamewithmore24characters'],'foo.o',[],"c");\r
+  \r
+  // disable message\r
+  warning_mode = warning('query');\r
+  warning('off');\r
+  // load the shared library \r
+  exec loader.sce ;\r
+  // enable message\r
+  warning(warning_mode);\r
+  chdir(curPath) \r
+end    \r
+\r
+//5+7 by C function\r
+v = call('verylongfunctionnamewithmore24characters',5,1,'d',7,2,'d','out',[1,1],3,'d')\r
+if v <> 12 then pause,end\r
+//================================================\r
diff --git a/scilab/modules/dynamic_link/tests/nonreg_tests/bug_3647.win.dia.ref b/scilab/modules/dynamic_link/tests/nonreg_tests/bug_3647.win.dia.ref
new file mode 100644 (file)
index 0000000..fb95217
--- /dev/null
@@ -0,0 +1,46 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2008 - DIGITEO - Allan CORNET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- Non-regression test for bug 3647 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=3647
+//
+// <-- Short Description -->
+// C functions having more than 23 characters are not usable with scilab
+foo=['void verylongfunctionnamewithmore24characters(double *a,double *b,double *c)';
+     '{ *c = *a + *b; }'  ];
+// we use TMPDIR for compilation
+       
+if ~c_link('foo') then
+  curPath = getcwd();
+  chdir(TMPDIR);
+  mputl(foo,'foo.c');
+  ilib_for_link(['verylongfunctionnamewithmore24characters'],'foo.o',[],"c");
+   Generate a loader file
+   Generate a Makefile
+   Running the Makefile
+   Compilation of foo
+   Building shared library (be patient)
+  // disable message
+  warning_mode = warning('query');
+  warning('off');
+  // load the shared library
+  exec loader.sce ;
+  // enable message
+  warning(warning_mode);
+  chdir(curPath)
+ ans  =
+  T  
+end    
+//5+7 by C function
+v = call('verylongfunctionnamewithmore24characters',5,1,'d',7,2,'d','out',[1,1],3,'d')
+ v  =
+    12.  
+if v <> 12 then bugmes();quit;end
+//================================================