예제 #1
0
/* ========================================================================== */
int sci_gpuLoadDynLib(char* fname)
{
    int row         = 0;
    int col         = 0;
    int* piLen      = NULL;
    char** pstData  = NULL;
    int* pstrA      = NULL;
    int inputType_A = 0;
    int  i          = 0;

    CheckRhs(1, 1);
    CheckLhs(0, 1);

    // get lib
    getVarAddressFromPosition(pvApiCtx,1,&pstrA);
    getVarType(pvApiCtx, pstrA, &inputType_A);
    getMatrixOfString(pvApiCtx, pstrA, &row, &col, NULL, NULL);
    piLen = (int*)malloc(sizeof(int) * row * col);
    getMatrixOfString(pvApiCtx, pstrA, &row, &col, piLen, NULL);
    pstData = (char**)malloc(sizeof(char*) * row * col);
    for(i = 0 ; i < row * col ; i++)
    {
        pstData[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));
    }
    getMatrixOfString(pvApiCtx, pstrA, &row, &col, piLen, pstData);

    // open lib
    printf("%s\n", *pstData);
    Sci_dlopen(*pstData);

    LhsVar(1) = Rhs + 1;
    PutLhsVar();

    return 0;
}
예제 #2
0
/*---------------------------------------------------------------------------*/
int scilabLink(int idsharedlibrary,
               char *filename,
               char **subnamesarray, int sizesubnamesarray,
               BOOL fflag, int *ierr)
{
    int IdSharedLib = -1;

    initializeLink();

    if (idsharedlibrary == -1)
    {
        IdSharedLib = Sci_dlopen(filename);
    }
    else
    {
        IdSharedLib = idsharedlibrary;
    }

    if (IdSharedLib == -1 )
    {
        if ( getWarningMode() )
        {
#ifdef _MSC_VER
            if (isDll(filename))
            {
#ifdef _WIN64
                if (isX86Dll(filename))
                {
                    if (getIlibVerboseLevel() != ILIB_VERBOSE_NO_OUTPUT)
                    {
                        sciprint(_("%s: can not to load a x86 dll in a x64 environment.\n" ), "link");
                    }
                    SetLastError(ERROR_DLL_INIT_FAILED);
                }
#else
                if (isX64Dll(filename))
                {
                    if (getIlibVerboseLevel() != ILIB_VERBOSE_NO_OUTPUT)
                    {
                        sciprint(_("%s: can not load a x64 dll in a x86 environment.\n" ), "link");
                    }
                    SetLastError(ERROR_DLL_INIT_FAILED);
                }
#endif
            }
            else
            {
                char *pathSearch = searchEnv(filename, "PATH");
                if (pathSearch == NULL)
                {
                    if (getIlibVerboseLevel() != ILIB_VERBOSE_NO_OUTPUT)
                    {
                        sciprint(_("%s: The file %s does not exist in PATH environment.\n" ), "link", filename);
                    }
                }
            }
#else
            if (getIlibVerboseLevel() != ILIB_VERBOSE_NO_OUTPUT)
            {
                sciprint(_("Link failed for dynamic library '%s'.\n"), filename);
                sciprint(_("An error occurred: %s\n"), GetLastDynLibError());
            }
#endif
        }
        *ierr = -1;
        return IdSharedLib;
    }

    if ( (idsharedlibrary == -1) && (getIlibVerboseLevel() != ILIB_VERBOSE_NO_OUTPUT))
    {
        sciprint(_("Shared archive loaded.\n"));
        sciprint(_("Link done.\n"));
    }

    if (sizesubnamesarray > 0)
    {
        int errorcode = 0;
        int i = 0;
        for (i = 0; i < sizesubnamesarray ; i++)
        {
            if (fflag)
            {
                errorcode = Sci_dlsym(subnamesarray[i], IdSharedLib, "f");
            }
            else
            {
                errorcode = Sci_dlsym(subnamesarray[i], IdSharedLib, "c");
            }

            if (errorcode < 0)
            {
                *ierr = errorcode;
            }
        }
    }
    return IdSharedLib;
}