Clean old static structs from dynamic_link 49/5049/2
Antoine ELIAS [Wed, 28 Sep 2011 13:07:41 +0000 (15:07 +0200)]
Comment their calls in Xcos

Change-Id: I0f0da93178a06442d717631ada4c65b78306a578

12 files changed:
scilab/libs/dynamiclibrary/src/dynamiclibrary_windows.c
scilab/modules/core/src/c/callinterf.c
scilab/modules/dynamic_link/includes/addinter.h
scilab/modules/dynamic_link/includes/dynamic_link.h
scilab/modules/dynamic_link/sci_gateway/cpp/sci_ulink.cpp
scilab/modules/dynamic_link/src/c/GetFunctionByName.c
scilab/modules/dynamic_link/src/c/dl_genErrorMessage.c
scilab/modules/dynamic_link/src/cpp/addinter.cpp
scilab/modules/dynamic_link/src/cpp/dynamic_link.cpp
scilab/modules/scicos/sci_gateway/c/sci_model2blk.c
scilab/modules/scicos/src/c/scicos.c
scilab/modules/system_env/includes/configvariable.hxx

index 90a216e..17acb22 100644 (file)
@@ -10,6 +10,7 @@
  *
  */
 #include <string.h>
+#include <stdio.h>
 #include "dynamiclibrary_windows.h"
 #include "charEncoding.h"
 #include "MALLOC.h"
@@ -37,6 +38,10 @@ IMPORT_EXPORT_DYNAMICLIBRARY_DLL DynLibFuncPtr GetDynLibFuncPtr(DynLibHandle _hL
                retFuncPtr = GetProcAddress(_hLib, _pstEntryPointName);
        }
        
+    if(retFuncPtr == NULL)
+    {
+        printf("GetLastError : %d\n", GetLastError());
+    }
        return retFuncPtr;
 }
 /*---------------------------------------------------------------------------*/
index 78edb75..047cf7d 100644 (file)
@@ -126,7 +126,7 @@ int C2F(callinterf) (int *k)
     count++;
     if (*k > DynInterfStart)
     {
-        C2F(userlk)(k);
+        //C2F(userlk)(k);
     }
     else
     {
index cc940bf..20df8b6 100644 (file)
@@ -48,9 +48,4 @@ DYNAMIC_LINK_IMPEXP void RemoveInterf(int id);
 */
 DYNAMIC_LINK_IMPEXP int AddInterfaceToScilab(wchar_t* _pwstDynamicLibraryName, wchar_t* _pwstModuleName, wchar_t** _pwstEntryPointName, int _iEntryPointSize);
 
-/**
-* TO DO: comments 
-*/
-DYNAMIC_LINK_IMPEXP void C2F(userlk)(int *k);
-
 #endif /*  __ADDINTER_H__ */
index f77d58f..64e8607 100644 (file)
 #include <wchar.h> /* wchar_t */
 #include "dynlib_dynamic_link.h"
 #include "BOOL.h"
-#include "machine.h" /* C2F */
-
-#define ENTRYMAX 500
-
-/**
-* OBSOLETE
-* if *ilib == -1
-*    checks if routinename is a loaded
-*    entry point
-*    the result is -1 if false
-*               or the number in the function table
-* @param[in] routinename
-* @param[in/out] ilib
-*/
-DYNAMIC_LINK_IMPEXP void C2F(iislink)(char *routinename, int *ilib);
-
-
-/**
-* returns the ii functions
-* @param ii
-* @param ptr on functions
-*/
-DYNAMIC_LINK_IMPEXP void GetDynFunc(int ii, void (**realop)());
-
-/**
-* Search a function in the table
-* Search from end to top
-* @param
-* @param
-*/
-DYNAMIC_LINK_IMPEXP int SearchInDynLinks(char *op, void (**realop) ());
-
-/**
-* unlink all linked files
-*/
-DYNAMIC_LINK_IMPEXP void unlinkallsharedlib(void);
-
-/**
-* Unlink a shared lib
-* @param i (number of shared lib)
-*/
-DYNAMIC_LINK_IMPEXP void unlinksharedlib(int *i);
-
 
 /**
 * load a shared archive and call LoadDynLibrary
@@ -75,7 +32,7 @@ DYNAMIC_LINK_IMPEXP int Sci_dlopen(wchar_t* _pwstDynLibPath);
 * return value is == 0 if the FreeDynLibrary failed
 * @param loaded_file
 */
-DYNAMIC_LINK_IMPEXP int Sci_dlclose(unsigned long _hLib);
+DYNAMIC_LINK_IMPEXP int Sci_dlclose(unsigned long long _hLib);
 
 /**
 * This routine load the entryname ename
@@ -85,19 +42,6 @@ DYNAMIC_LINK_IMPEXP int Sci_dlclose(unsigned long _hLib);
 DYNAMIC_LINK_IMPEXP int Sci_dlsym(wchar_t* _pwstEntryPointName, int _iLibID, BOOL _bFortran);
 
 /**
-* Delete entry points associated with shared lib ishared
-* then delete the shared lib
-@param ishared
-*/
-DYNAMIC_LINK_IMPEXP void Sci_Delsym(int ishared);
-
-/**
-* @param sizearray returns size of string array returned
-* @return string array with functions names loaded
-*/
-DYNAMIC_LINK_IMPEXP char **getNamesOfFunctionsInSharedLibraries(int *sizearray);
-
-/**
 * call link for scilab
 * @param _iLibID                : Id of an existing shared lib otherwise -1
 * @param _pwstLibraryName       : Dynamic library name
index 63f182d..1c47936 100644 (file)
@@ -75,7 +75,7 @@ void unLinkAll()
 /*--------------------------------------------------------------------------*/
 void unLink(int _iLib)
 {
-    unsigned long iLib = ConfigVariable::getDynamicLibrary(_iLib)->hLib;
+    unsigned long long iLib = ConfigVariable::getDynamicLibrary(_iLib)->hLib;
     ConfigVariable::removeDynamicLibrary(_iLib);
     Sci_dlclose(iLib);
 }
index 135394f..b385dbd 100644 (file)
@@ -21,44 +21,7 @@ static void Emptyfunc(void) {}
 /*--------------------------------------------------------------------------*/
 voidf GetFunctionByName (char *name, int *rep, FTAB *table)
 {
-       void (*loc)();
-       if (name)
-       {
-               int length_name = 0;
-               char *s = name;
-               char *buf = name;
-               while ( *s != ' ' && *s != '\0') { s++;length_name++;};
-
-               buf = (char*)MALLOC(sizeof(char)*(length_name+1));
-               if (buf)
-               {
-                       strncpy(buf,name,length_name);
-                       buf[length_name] = '\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
-       {
-               *rep = 0;
-       }
-       return(loc);
+       return NULL;
 }
 /*--------------------------------------------------------------------------*/
 static BOOL SearchComp(FTAB *Ftab, char *op, void (**realop) ())
index 6e2096f..de789ff 100644 (file)
@@ -26,7 +26,7 @@ void dl_genErrorMessage(wchar_t* _pwstCallerName, int _iErr, wchar_t* _pwstLibra
         break;
 
     case -2:
-        ScierrorW(999, _W("%ls: Cannot open shared files. Max entry %d reached.\n"), _pwstCallerName, ENTRYMAX);
+        //never occurs now
         break;
 
     case -3:
index de8c6e2..2bebba4 100644 (file)
@@ -38,25 +38,7 @@ extern "C"
 #include "ExceptionMessage.h"
 #endif
 }
-/* size of interface name */
-/* scilab limitation to nlgh characters (24)*/
-#define INTERFSIZE nlgh + 1 
-/*-----------------------------------------------------------------------------------*/
-typedef struct 
-{
-       char name[INTERFSIZE]; /** name of interface **/
-       void (*func)();        /** entrypoint for the interface **/
-       int Nshared; /** id of the shared library **/
-       BOOL ok;    /** flag set to TRUE if entrypoint can be used **/
-} InterfaceElement;
-/*-----------------------------------------------------------------------------------*/
-InterfaceElement *DynInterf = NULL;
-static int MaxInterfaces = MAXDYNINTERF;
-/*-----------------------------------------------------------------------------------*/
-static int LastInterf = 0;
-static void initializeInterfaces(void);
-static BOOL reallocDynInterf(void);
-/*-----------------------------------------------------------------------------------*/
+
 int AddInterfaceToScilab(wchar_t* _pwstDynamicLibraryName, wchar_t* _pwstModuleName, wchar_t** _pwstEntryPointName, int _iEntryPointSize)
 {
        int iLibID = -1; /* Id of library */
@@ -94,125 +76,3 @@ int AddInterfaceToScilab(wchar_t* _pwstDynamicLibraryName, wchar_t* _pwstModuleN
     }
        return 0;
 }
-/*-----------------------------------------------------------------------------------*/
-static void initializeInterfaces(void)
-{
-       static int first_entry_interfaces = 0;
-
-       if ( first_entry_interfaces == 0) 
-       {
-               if (DynInterf == NULL)
-               {
-                       DynInterf = (InterfaceElement*)MALLOC(sizeof(InterfaceElement)*MaxInterfaces);
-                       if (DynInterf)
-                       {
-                               int i = 0;
-                               for ( i= 0 ; i < MaxInterfaces ; i++) 
-                               {
-                                       strcpy(DynInterf[i].name,"");
-                                       DynInterf[i].func = NULL;
-
-                                       DynInterf[i].Nshared = -1;
-                                       DynInterf[i].ok = FALSE;
-                               }
-                       }
-               }
-               first_entry_interfaces++;
-       }
-}
-/*-----------------------------------------------------------------------------------*/
-/*********************************
-* used in unlinksharedlib(i) 
-*********************************/
-void RemoveInterf(int id)
-{
-       int i = 0;
-       for ( i = 0 ; i < LastInterf ; i++ ) 
-       {
-               if ( DynInterf[i].Nshared == id ) 
-               {
-                       DynInterf[i].ok = FALSE;
-                       break;
-               }
-       }
-}
-/*-----------------------------------------------------------------------------------*/
-/************************************************
-* Used when one want to call a function added 
-* with addinterf the dynamic interface number 
-* is given by *k - (DynInterfStart+1)
-************************************************/
-void C2F(userlk)(int *k)
-{
-       int k1 = *k - (DynInterfStart+1) ;
-
-       int imes = 9999;
-       if ( k1 >= LastInterf || k1 < 0 ) 
-       {
-               if (getWarningMode()) 
-               {
-                       Scierror(999,_("Error: Not a valid internal routine number %d.\n"), *k);
-               }
-               SciError(imes);
-               return;
-       }
-
-       if ( DynInterf[k1].ok == 1 ) 
-       {
-#ifdef _MSC_VER
-#ifndef _DEBUG
-               _try
-               {
-                       (*DynInterf[k1].func)();
-               }
-               _except (EXCEPTION_EXECUTE_HANDLER)
-               {
-                       ExceptionMessage(GetExceptionCode(),DynInterf[k1].name);
-               }
-#else
-               (*DynInterf[k1].func)();
-#endif
-#else
-               (*DynInterf[k1].func)();
-#endif
-       }
-       else 
-       {
-               if (getWarningMode()) sciprint(_("Interface %s not linked.\n"),DynInterf[k1].name);
-               SciError(imes);
-               return;
-       }
-}
-/*-----------------------------------------------------------------------------------*/
-static BOOL reallocDynInterf(void)
-{
-       /* increase table of interfaces by 2 */
-       int newMaxInterfaces = MaxInterfaces * 2;
-
-       if (newMaxInterfaces < ENTRYMAX)
-       {
-               if (DynInterf)
-               {
-                       int i = 0;
-                       InterfaceElement *newDynInterf = NULL;
-
-                       newDynInterf = (InterfaceElement*)REALLOC(DynInterf,sizeof(InterfaceElement)*newMaxInterfaces);
-                       if (newDynInterf == NULL) return FALSE;
-
-                       DynInterf = newDynInterf;
-
-                       for ( i= MaxInterfaces ; i < newMaxInterfaces ; i++) 
-                       {
-                               strcpy(DynInterf[i].name,"");
-                               DynInterf[i].func = NULL;
-                               DynInterf[i].Nshared = -1;
-                               DynInterf[i].ok = FALSE;
-                       }
-                       MaxInterfaces = newMaxInterfaces;
-                       return TRUE;
-               }
-               else return FALSE;
-       }
-       return FALSE;
-}
-/*-----------------------------------------------------------------------------------*/
index 57515f3..e3c822e 100644 (file)
@@ -40,56 +40,12 @@ extern "C"
 #include "BOOL.h"
 #include "charEncoding.h"
 }
-/*---------------------------------------------------------------------------*/
-static void Underscores(BOOL _bFortran, wchar_t* _pwstEntryPointName, wchar_t* _pwstTrailingName);
-static int SearchFandS(char *op, int ilib);
-/*---------------------------------------------------------------------------*/
-#define MAXNAME  256 
-#define TMPL 256
-#define debug C2F(iop).ddt==1
-/*---------------------------------------------------------------------------*/
-#ifdef _MSC_VER
-/* struct used by fortran (F2C) */
-/* required to be defined in C */
-
-typedef struct {
-    char name[nlgh+1];
-} CINTER_struct;
 
-__declspec (dllexport) CINTER_struct C2F(cinter);
-
-/* struct used by fortran (F2C) */
-/* required to be defined in C */
-typedef struct {
-    int ibuf[lsiz];
-} IBFU_struct;
-__declspec (dllexport) CINTER_struct C2F(ibfu);
-
-#endif
-/*---------------------------------------------------------------------------*/
-typedef char Name[MAXNAME];   /* could be changed to dynamic structure */
+static void Underscores(BOOL _bFortran, wchar_t* _pwstEntryPointName, wchar_t* _pwstTrailingName);
 
 typedef void (*function) (wchar_t*);
 
-typedef struct 
-{ 
-    function epoint;            /* the entry point */ 
-    Name     name;              /* entry point name */
-    int      Nshared;           /* number of the shared file */
-} Epoints;
 
-typedef struct 
-{
-    int ok;
-    char tmp_file[TMPL];
-    unsigned long  shl;
-} Hd;
-
-static Hd  hd[ENTRYMAX]; /* shared libs handler */
-static int Nshared = 0;
-static int NEpoints = 0; /* Number of Linked names */
-static Epoints EP[ENTRYMAX];  /* entryPoints */
-/*---------------------------------------------------------------------------*/
 int scilabLink(int _iLibID, wchar_t* _pwstLibraryName, wchar_t** _pwstEntryPointName, int _iEntryPointSize, BOOL _bFortran ,int *_piErr)
 {
     int iLibID = -1; 
@@ -167,36 +123,6 @@ int scilabLink(int _iLibID, wchar_t* _pwstLibraryName, wchar_t** _pwstEntryPoint
     return iLibID;
 }
 /*---------------------------------------------------------------------------*/
-char **getNamesOfFunctionsInSharedLibraries(int *sizearray)
-{
-    char **NamesOfFunctions = NULL;
-    *sizearray = 0;
-
-    if( (NEpoints) && (NEpoints > 0) )
-    {
-        int i = 0;
-        NamesOfFunctions = (char **) MALLOC((NEpoints)*sizeof(char *));
-        if(NamesOfFunctions)
-        {
-            for ( i = NEpoints-1 ; i >= 0 ; i--) 
-            {
-                if(EP[i].name)
-                {
-                    char *EntryName = (char *)MALLOC(((int)strlen(EP[i].name)+1)*sizeof(char));
-
-                    if(EntryName)
-                    {
-                        (*sizearray)++;
-                        strcpy(EntryName , EP[i].name);
-                        NamesOfFunctions[(*sizearray)-1] = EntryName;
-                    }
-                }
-            }
-        }
-    }
-    return NamesOfFunctions;
-}
-/*---------------------------------------------------------------------------*/
 /**
 * Underscores : deals with the trailing _ 
 * in entry names 
@@ -217,83 +143,9 @@ static void Underscores(BOOL _bFortran, wchar_t* _pwstEntryPointName, wchar_t* _
     return;
 }
 /*---------------------------------------------------------------------------*/
-BOOL c_link(char *routinename,int *ilib)
-{
-    void (*loc)();
-    if( *ilib != -1 ) *ilib = SearchFandS(routinename,*ilib);
-    else *ilib = SearchInDynLinks(routinename,&loc);
-
-    if(*ilib == -1) return FALSE;
-    return TRUE;
-}
-/*---------------------------------------------------------------------------*/
-void C2F(iislink)(char *routinename, int *ilib)
-{
-    c_link(routinename,ilib);
-}
-/*---------------------------------------------------------------------------*/
-void GetDynFunc(int ii, void (**realop) ())
-{
-    //if( EP[ii].Nshared != -1 ) *realop = EP[ii].epoint;
-    //else *realop = (function) 0;
-}
-/*---------------------------------------------------------------------------*/
-int SearchInDynLinks(char *op, void (**realop) ())
-{
-    //int i=0;
-    //for ( i = NEpoints-1 ; i >=0 ; i--) 
-    //{
-    //    if( strcmp(op,EP[i].name) == 0) 
-    //    {
-    //        *realop = EP[i].epoint;
-    //        return(EP[i].Nshared );
-    //    }
-    //}
-    return(-1);
-}
-/*---------------------------------------------------------------------------*/
-/**
-* Search a (function,libid) in the table 
-* Search from end to top 
-*/
-static int SearchFandS(char *op, int ilib)
-{
-    int i = 0;
-    for ( i = NEpoints-1 ; i >=0 ; i--) 
-    {
-        if( strcmp(op,EP[i].name) == 0 && EP[i].Nshared == ilib)
-        {
-            return(i);
-        }
-    }
-    return(-1);
-}
-/*---------------------------------------------------------------------------*/
-/*---------------------------------------------------------------------------*/
-void unlinkallsharedlib(void)
-{
-    int i=0;
-    for ( i = 0 ; i < Nshared ; i++) 
-    {
-        unlinksharedlib(&i);
-    }
-}
-/*---------------------------------------------------------------------------*/
-void unlinksharedlib(int *i) 
+int Sci_dlclose(unsigned long long _hLib)
 {
-    /* delete entry points in shared lib *i */
-    Sci_Delsym(*i);
-    /* delete entry points used in addinter in shared lib *i */
-    RemoveInterf(*i);
-}
-/*---------------------------------------------------------------------------*/
-int Sci_dlclose(unsigned long _hLib)
-{
-#ifdef _MSC_VER
-        return FreeDynLibrary ((DynLibHandle) ULongToHandle(_hLib));
-#else
-        return FreeDynLibrary ((DynLibHandle) _hLib);
-#endif
+    return FreeDynLibrary((DynLibHandle)_hLib);
 }
 /*---------------------------------------------------------------------------*/
 int Sci_dlopen(wchar_t* _pwstDynLibPath)
@@ -318,15 +170,9 @@ int Sci_dlopen(wchar_t* _pwstDynLibPath)
         return -1 ; /* the shared archive was not loaded. */
     }
 
-    /* Warning x64 windows */
-
     ConfigVariable::DynamicLibraryStr* pDL = ConfigVariable::getNewDynamicLibraryStr();
     ConfigVariable::setLibraryName(pDL, _pwstDynLibPath);
-#ifdef _MSC_VER
-    pDL->hLib =   PtrToUlong(hLib);
-#else
-    pDL->hLib = (unsigned long)hLib;
-#endif
+    pDL->hLib = (unsigned long long)hLib;
 
     
     return ConfigVariable::addDynamicLibrary(pDL);
@@ -355,13 +201,8 @@ int Sci_dlsym(wchar_t* _pwstEntryPointName, int _iLibID, BOOL _bFortran)
         return -4;
     }
 
-    /* Warning x64 windows */
     pEP->iLibIndex = _iLibID;
-#ifdef _MSC_VER
-    hDynLib = (DynLibHandle)  ULongToHandle(ConfigVariable::getDynamicLibrary(_iLibID)->hLib);
-#else
     hDynLib = (DynLibHandle)  ConfigVariable::getDynamicLibrary(_iLibID)->hLib;
-#endif
 #ifdef _MCS_VER
     pEP->functionPtr = (function) GetDynLibFuncPtrW(hDynLib, pwstEntryPointName);
 #else
@@ -378,8 +219,8 @@ int Sci_dlsym(wchar_t* _pwstEntryPointName, int _iLibID, BOOL _bFortran)
         return -5;
     }
 
-    /* we don't add the _ in the table */
-    if(debug)
+
+    if(0 /*debug mode*/)
     {
         sciprintW(_W("Linking %ls.\n"), _pwstEntryPointName);
     }
@@ -390,33 +231,3 @@ int Sci_dlsym(wchar_t* _pwstEntryPointName, int _iLibID, BOOL _bFortran)
     return 0;  
 }
 /*---------------------------------------------------------------------------*/
-void Sci_Delsym(int ishared) 
-{
-    int ish = Min(Max(0,ishared),ENTRYMAX-1);
-    int i=0;
-    for ( i = NEpoints-1 ; i >=0 ; i--) 
-    {
-        if( EP[i].Nshared == ish )
-        {
-            int j;
-            for ( j = i ; j <= NEpoints - 2 ; j++ )
-            {
-                EP[j].epoint = EP[j+1].epoint;
-                EP[j].Nshared = EP[j+1].Nshared;
-                strcpy(EP[j].name,EP[j+1].name);
-            }
-            NEpoints--;
-        }
-    }
-    if( hd[ish].ok != FALSE)
-    {
-        /* Warning x64 windows */
-#ifdef _MSC_VER
-        FreeDynLibrary ((DynLibHandle) ULongToHandle(hd[ish].shl));
-#else
-        FreeDynLibrary ((DynLibHandle) hd[ish].shl);
-#endif
-        hd[ish].ok = FALSE;
-    }
-}
-/*---------------------------------------------------------------------------*/
index 99baf20..0782e08 100644 (file)
@@ -245,7 +245,7 @@ int sci_model2blk(char *fname, unsigned long fname_len)
        else 
        {
                lfunpt -= (ntabsim+1);
-               GetDynFunc(lfunpt,&Block.funpt);
+               //GetDynFunc(lfunpt,&Block.funpt); // TODO: old Scilab 5 function to be replaced
                if (Block.funpt == (voidf) 0) 
                {
                        Scierror(888,_("%s : Function not found\n"),fname);
index 4783fc2..b643beb 100644 (file)
@@ -497,7 +497,7 @@ int C2F(scicos)(double *x_in, int *xptr_in, double *z__,
                }
                else {
                        i -= (ntabsim+1);
-                       GetDynFunc(i,&Blocks[kf].funpt);
+                       //GetDynFunc(i,&Blocks[kf].funpt);  // TODO: old Scilab 5 function to be replaced
                        if ( Blocks[kf].funpt == (voidf) 0) {
                                sciprint(_("Function not found\n"));
                                *ierr =1000+kf+1;
@@ -4387,7 +4387,7 @@ int C2F(funnum)(char * fname)
                i++;
        }
        ln=(int)strlen(fname);
-       C2F(iislink)(fname,&loc);C2F(iislink)(fname,&loc);
+       //C2F(iislink)(fname,&loc);C2F(iislink)(fname,&loc); // TODO: old Scilab 5 function to be replaced
        if (loc >= 0) return(ntabsim+(int)loc+1);
        return(0);
 }/* funnum */
index 54c0e87..1f3b897 100644 (file)
@@ -227,7 +227,7 @@ public :
     typedef struct 
     {
         wchar_t* pwstLibraryName;   /** name of dynamic library **/
-        unsigned long  hLib;        /** handle of the library **/
+        unsigned long long hLib;        /** handle of the library **/
     } DynamicLibraryStr;
 
     typedef struct