2007-12-30 17:41:49 +01:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
|
|
library.c
|
|
|
|
|
|
|
|
|
|
GAMBAS plug-in management routines
|
|
|
|
|
|
|
|
|
|
(c) 2000-2007 Benoit Minisini <gambas@users.sourceforge.net>
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 1, or (at your option)
|
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
#define __GBX_LIBRARY_C
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "gb_common.h"
|
|
|
|
|
#include "gb_common_buffer.h"
|
|
|
|
|
#include "gb_common_case.h"
|
|
|
|
|
#include "gb_error.h"
|
|
|
|
|
#include "gb_alloc.h"
|
|
|
|
|
#include "gb_replace.h"
|
|
|
|
|
#include "gb_magic.h"
|
|
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
|
|
#include "gb_error.h"
|
|
|
|
|
|
|
|
|
|
#include "gbx_class.h"
|
|
|
|
|
#include "gbx_exec.h"
|
|
|
|
|
#include "gbx_event.h"
|
|
|
|
|
#include "gbx_stack.h"
|
|
|
|
|
#include "gb_file.h"
|
|
|
|
|
#include "gbx_archive.h"
|
|
|
|
|
#include "gbx_project.h"
|
|
|
|
|
#include "gbx_api.h"
|
|
|
|
|
|
|
|
|
|
#include "gbx_string.h"
|
|
|
|
|
#include "gbx_object.h"
|
|
|
|
|
#include "gbx_component.h"
|
|
|
|
|
|
|
|
|
|
#include "gbx_library.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*#define DEBUG*/
|
|
|
|
|
//#define DEBUG_PRELOAD
|
|
|
|
|
|
2008-04-17 12:18:25 +02:00
|
|
|
|
// Maximum size of a project or startup file
|
|
|
|
|
// This avoids reading too much in the archive file!
|
|
|
|
|
|
|
|
|
|
#define MAX_SIZE 2048
|
|
|
|
|
|
|
|
|
|
int _bytes_read = 0;
|
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
#if 0
|
|
|
|
|
static lt_ptr library_malloc(size_t size)
|
|
|
|
|
{
|
|
|
|
|
lt_ptr ptr;
|
|
|
|
|
ALLOC(&ptr, size, "library_malloc");
|
|
|
|
|
printf("library_malloc: %d -> %p\n", size, ptr);
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void library_free(lt_ptr ptr)
|
|
|
|
|
{
|
|
|
|
|
printf("library_free -> %p\n", ptr);
|
|
|
|
|
FREE(&ptr, "library_free");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static void *get_symbol(LIBRARY *lib, const char *symbol, bool err)
|
|
|
|
|
{
|
|
|
|
|
void *sym;
|
|
|
|
|
|
|
|
|
|
sym = lt_dlsym(lib->handle, symbol);
|
|
|
|
|
if (sym == NULL && err)
|
|
|
|
|
{
|
2008-01-17 22:39:26 +01:00
|
|
|
|
strcpy(COMMON_buffer, lt_dlerror());
|
2007-12-30 17:41:49 +01:00
|
|
|
|
lt_dlclose(lib->handle);
|
|
|
|
|
lib->handle = NULL;
|
|
|
|
|
THROW(E_LIBRARY, lib->name, COMMON_buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sym;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
static void copy_interface(intptr_t *src, intptr_t *dst)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
for(;;)
|
|
|
|
|
{
|
2008-01-17 22:39:26 +01:00
|
|
|
|
if (*src == (intptr_t)0)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
*dst++ = *src++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool read_line(FILE *fd, char *dir, int max)
|
|
|
|
|
{
|
|
|
|
|
char *p;
|
|
|
|
|
int c;
|
|
|
|
|
//ssize_t r;
|
|
|
|
|
|
|
|
|
|
p = dir;
|
|
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
|
{
|
2008-04-17 12:18:25 +02:00
|
|
|
|
_bytes_read++;
|
|
|
|
|
if (_bytes_read > MAX_SIZE)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
|
c = fgetc(fd); //read(fd, &c, 1);
|
|
|
|
|
if (c != EOF)
|
|
|
|
|
break;
|
|
|
|
|
if (errno != EINTR)
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-17 12:18:25 +02:00
|
|
|
|
if (c == '\n')
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
*p = 0;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-17 12:18:25 +02:00
|
|
|
|
max--;
|
|
|
|
|
if (max > 0)
|
|
|
|
|
*p++ = c;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void add_preload(char **env, const char *lib)
|
|
|
|
|
{
|
|
|
|
|
char *org;
|
|
|
|
|
|
|
|
|
|
if (*env == COMMON_buffer)
|
|
|
|
|
{
|
|
|
|
|
org = getenv("LD_PRELOAD");
|
|
|
|
|
if (org && *org)
|
2008-08-08 16:41:57 +02:00
|
|
|
|
*env += sprintf(*env, "%s ", org);
|
2008-01-17 22:39:26 +01:00
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
*env += sprintf(*env, "%s ", lib);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-04-17 12:18:25 +02:00
|
|
|
|
/*
|
|
|
|
|
static const char *start_with(const char *str, const char *begin)
|
|
|
|
|
{
|
|
|
|
|
int len = strlen(begin);
|
|
|
|
|
if (!strncasecmp(str, begin, len))
|
|
|
|
|
return &str[len];
|
|
|
|
|
else
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static bool check_preload(const char *lib, char **penv)
|
|
|
|
|
{
|
|
|
|
|
if (strcasecmp(lib, "gb.qt") == 0)
|
|
|
|
|
{
|
|
|
|
|
add_preload(penv, "libqt-mt.so.3");
|
|
|
|
|
#ifdef DEBUG_PRELOAD
|
|
|
|
|
fprintf(stderr, "found %s\n", lib);
|
|
|
|
|
#endif
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
//#if HAVE_KDE_COMPONENT
|
|
|
|
|
else if (strcasecmp(lib, "gb.qt.kde") == 0)
|
|
|
|
|
{
|
|
|
|
|
/*add_preload(&env, libdir, p);*/
|
|
|
|
|
add_preload(penv, "libkdecore.so.4");
|
|
|
|
|
add_preload(penv, "libkdeui.so.4");
|
|
|
|
|
add_preload(penv, "libDCOP.so.4");
|
|
|
|
|
add_preload(penv, "libkio.so.4");
|
|
|
|
|
/*fprintf(stderr, "Warning: preloading KDE libraries\n");*/
|
|
|
|
|
#ifdef DEBUG_PRELOAD
|
|
|
|
|
fprintf(stderr, "found %s\n", lib);
|
|
|
|
|
#endif
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void LIBRARY_preload(const char *file, char **argv)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
#if DO_PRELOADING
|
|
|
|
|
const char *path;
|
|
|
|
|
char dir[MAX_PATH];
|
|
|
|
|
/*char libdir[MAX_PATH];*/
|
|
|
|
|
FILE *fd;
|
|
|
|
|
char *env;
|
|
|
|
|
bool preload;
|
|
|
|
|
char *err = NULL;
|
2008-04-17 12:18:25 +02:00
|
|
|
|
bool startup = FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
env = getenv("GAMBAS_PRELOAD");
|
|
|
|
|
|
|
|
|
|
if (env)
|
|
|
|
|
{
|
|
|
|
|
#ifdef DEBUG_PRELOAD
|
|
|
|
|
fprintf(stderr, "Preloading done.\nLD_PRELOAD=%s\nGAMBAS_PRELOAD=%s\n", getenv("LD_PRELOAD"), getenv("GAMBAS_PRELOAD"));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (*env)
|
|
|
|
|
setenv("LD_PRELOAD", env, TRUE);
|
|
|
|
|
else
|
|
|
|
|
unsetenv("LD_PRELOAD");
|
|
|
|
|
|
|
|
|
|
unsetenv("GAMBAS_PRELOAD");
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-17 12:18:25 +02:00
|
|
|
|
_bytes_read = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
preload = FALSE;
|
|
|
|
|
|
|
|
|
|
if (!EXEC_arch)
|
|
|
|
|
{
|
|
|
|
|
if (file == NULL)
|
|
|
|
|
file = ".";
|
|
|
|
|
|
|
|
|
|
if (*file == '/')
|
|
|
|
|
{
|
2008-01-17 22:39:26 +01:00
|
|
|
|
strcpy(dir, file);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (*file == '.' && file[1] == '/')
|
|
|
|
|
file += 2;
|
|
|
|
|
|
|
|
|
|
path = FILE_getcwd(file);
|
|
|
|
|
if (path == NULL)
|
|
|
|
|
goto _PANIC;
|
|
|
|
|
|
|
|
|
|
chdir(path);
|
|
|
|
|
|
|
|
|
|
path = FILE_getcwd(NULL);
|
|
|
|
|
if (path == NULL)
|
|
|
|
|
goto _PANIC;
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
strcpy(dir, path);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-04-17 12:18:25 +02:00
|
|
|
|
file = FILE_cat(dir, ".startup", NULL);
|
|
|
|
|
/*if (!FILE_exist(file))
|
|
|
|
|
file = FILE_cat(dir, ".project", NULL);*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fd = fopen(file, "r");
|
|
|
|
|
/* Silently ignored */
|
|
|
|
|
if (!fd)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (EXEC_arch)
|
|
|
|
|
fseek(fd, 32 + sizeof(ARCH_HEADER), SEEK_SET);
|
|
|
|
|
|
|
|
|
|
read_line(fd, dir, MAX_PATH);
|
|
|
|
|
|
|
|
|
|
env = COMMON_buffer;
|
2008-04-17 12:18:25 +02:00
|
|
|
|
|
|
|
|
|
//if (!start_with(dir, PROJECT_MAGIC))
|
|
|
|
|
//{
|
|
|
|
|
// We suppose that we have a .startup file.
|
|
|
|
|
startup = TRUE;
|
|
|
|
|
while (*dir)
|
|
|
|
|
read_line(fd, dir, MAX_PATH);
|
|
|
|
|
|
|
|
|
|
for(;;)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2008-04-17 12:18:25 +02:00
|
|
|
|
if (read_line(fd, dir, MAX_PATH))
|
|
|
|
|
break;
|
|
|
|
|
if (!*dir)
|
|
|
|
|
break;
|
|
|
|
|
preload |= check_preload(dir, &env);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
2008-04-17 12:18:25 +02:00
|
|
|
|
/*
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
stop = FALSE;
|
|
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
|
{
|
|
|
|
|
if (read_line(fd, dir, MAX_PATH))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if ((p = start_with(dir, "library=")) || (p = start_with(dir, "component=")))
|
|
|
|
|
{
|
|
|
|
|
preload |= check_preload(p, &env);
|
|
|
|
|
stop = TRUE;
|
|
|
|
|
}
|
|
|
|
|
else if (stop)
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
2008-04-17 12:18:25 +02:00
|
|
|
|
*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
fclose(fd);
|
|
|
|
|
|
|
|
|
|
if (preload)
|
|
|
|
|
{
|
|
|
|
|
env = getenv("LD_PRELOAD");
|
|
|
|
|
if (env && *env)
|
|
|
|
|
setenv("GAMBAS_PRELOAD", env, TRUE);
|
|
|
|
|
else
|
|
|
|
|
setenv("GAMBAS_PRELOAD", "", TRUE);
|
|
|
|
|
|
|
|
|
|
setenv("LD_PRELOAD", COMMON_buffer, TRUE);
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_PRELOAD
|
|
|
|
|
fprintf(stderr, "Preloading...\nLD_PRELOAD=%s\nGAMBAS_PRELOAD=%s\n", getenv("LD_PRELOAD"), getenv("GAMBAS_PRELOAD"));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
execv(GAMBAS_LINK_PATH, argv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_PANIC:
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "Cannot preload libraries: %s\n", err ? err : strerror(errno));
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void LIBRARY_init(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
/*if (putenv("LD_BIND_NOW=true"))
|
|
|
|
|
ERROR_panic("Cannot set LD_BIND_NOW: &1", strerror(errno));
|
|
|
|
|
|
|
|
|
|
if (putenv("KDE_MALLOC=0"))
|
|
|
|
|
ERROR_panic("Cannot set KDE_MALLOC: &1", strerror(errno));*/
|
|
|
|
|
|
|
|
|
|
/*lt_dlmalloc = library_malloc;
|
|
|
|
|
lt_dlfree = library_free;*/
|
|
|
|
|
|
|
|
|
|
#ifndef DONT_USE_LTDL
|
|
|
|
|
if (lt_dlinit())
|
|
|
|
|
ERROR_panic("Cannot initialize plug-in management: %s", lt_dlerror());
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void LIBRARY_exit(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
#ifndef DONT_USE_LTDL
|
|
|
|
|
lt_dlexit();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void LIBRARY_get_interface(LIBRARY *lib, int version, void *iface)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
char symbol[32];
|
|
|
|
|
int i, len;
|
|
|
|
|
char c;
|
|
|
|
|
|
|
|
|
|
len = strlen(lib->name);
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
|
{
|
|
|
|
|
c = toupper(lib->name[i]);
|
|
|
|
|
if (!isalnum(c))
|
|
|
|
|
c = '_';
|
|
|
|
|
|
|
|
|
|
symbol[i] = c;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
sprintf(&symbol[len], "_%d", version);
|
|
|
|
|
copy_interface((intptr_t *)get_symbol(lib, symbol, TRUE), (intptr_t *)iface);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
boolean LIBRARY_get_interface_by_name(const char *name, int version, void *iface)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
COMPONENT *comp;
|
|
|
|
|
|
|
|
|
|
comp = COMPONENT_find(name);
|
|
|
|
|
if (!comp || !comp->library)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
LIBRARY_get_interface(comp->library, version, iface);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
LIBRARY *LIBRARY_create(const char *name)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
LIBRARY *lib;
|
|
|
|
|
|
|
|
|
|
ALLOC_ZERO(&lib, sizeof(LIBRARY), "LIBRARY_create");
|
|
|
|
|
|
|
|
|
|
lib->handle = NULL;
|
|
|
|
|
lib->name = name;
|
|
|
|
|
|
|
|
|
|
/*if (name)
|
|
|
|
|
{
|
|
|
|
|
lib->persistent = FALSE;
|
|
|
|
|
lib->preload = FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
lib->persistent = TRUE;
|
|
|
|
|
lib->preload = TRUE;
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
return lib;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void LIBRARY_delete(LIBRARY *lib)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
LIBRARY_unload(lib);
|
|
|
|
|
FREE(&lib, "LIBRARY_delete");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void LIBRARY_load(LIBRARY *lib)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
int (*func)();
|
|
|
|
|
GB_INTERFACE *iface;
|
|
|
|
|
GB_DESC **desc;
|
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
clock_t t = clock();
|
|
|
|
|
fprintf(stderr, "Loading library %s\n", lib->name);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (lib->handle)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
path = FILE_buffer();
|
2008-01-17 22:39:26 +01:00
|
|
|
|
sprintf(path, LIB_PATTERN, COMPONENT_path, lib->name);
|
2008-08-08 16:41:57 +02:00
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
if (!FILE_exist(path))
|
2008-01-17 22:39:26 +01:00
|
|
|
|
sprintf(path, LIB_PATTERN, COMPONENT_user_path, lib->name);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
#ifndef DONT_USE_LTDL
|
2008-01-03 21:44:46 +01:00
|
|
|
|
/* no more available in libltld ?
|
2007-12-30 17:41:49 +01:00
|
|
|
|
lt_dlopen_flag = RTLD_LAZY;
|
2008-01-03 21:44:46 +01:00
|
|
|
|
*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
lib->handle = lt_dlopenext(path);
|
|
|
|
|
#else
|
|
|
|
|
lib->handle = dlopen(path, RTLD_LAZY);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (lib->handle == NULL)
|
|
|
|
|
THROW(E_LIBRARY, path, lt_dlerror());
|
|
|
|
|
|
|
|
|
|
func = get_symbol(lib, LIB_INIT, TRUE);
|
|
|
|
|
|
|
|
|
|
/* Interface de Gambas */
|
|
|
|
|
|
|
|
|
|
iface = get_symbol(lib, LIB_GAMBAS, TRUE);
|
2008-01-17 22:39:26 +01:00
|
|
|
|
copy_interface((intptr_t *)(void *)GAMBAS_Api, (intptr_t *)(void *)iface);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
/* Signal function */
|
|
|
|
|
lib->signal = (void(*)())get_symbol(lib, LIB_SIGNAL, FALSE);
|
|
|
|
|
lib->info = (int(*)())get_symbol(lib, LIB_INFO, FALSE);
|
|
|
|
|
|
|
|
|
|
/* Initialisation */
|
|
|
|
|
lib->persistent = (boolean)(*func)();
|
|
|
|
|
|
|
|
|
|
/* Déclaration des classes */
|
|
|
|
|
desc = get_symbol(lib, LIB_CLASS, FALSE);
|
|
|
|
|
if (desc)
|
|
|
|
|
LIBRARY_declare(desc);
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
fprintf(stderr, "Library %s loaded ", lib->name);
|
|
|
|
|
fprintf(stderr, "in %g s\n", ((double)(clock() - t) / CLOCKS_PER_SEC));
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void LIBRARY_declare(GB_DESC **desc)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
GB_DESC **p;
|
|
|
|
|
|
|
|
|
|
p = desc;
|
|
|
|
|
while (*p != NULL)
|
|
|
|
|
{
|
|
|
|
|
CLASS_find_global((*p)->name);
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p = desc;
|
|
|
|
|
while (*p != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (CLASS_register(*p) == NULL)
|
|
|
|
|
THROW(E_REGISTER, (*p)->name);
|
|
|
|
|
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void LIBRARY_unload(LIBRARY *lib)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
void (*gambas_exit)();
|
|
|
|
|
|
|
|
|
|
if (lib->handle == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Pas de lib<69>ation des classes pr<70>harg<72> ! */
|
|
|
|
|
|
|
|
|
|
/* V<>ification qu'aucune classe de la librairie n'est instanci<63> ! */
|
|
|
|
|
|
|
|
|
|
gambas_exit = lt_dlsym(lib->handle, LIB_EXIT);
|
|
|
|
|
if (gambas_exit != NULL)
|
|
|
|
|
(*gambas_exit)();
|
|
|
|
|
|
|
|
|
|
if (lib->persistent)
|
|
|
|
|
{
|
|
|
|
|
gambas_exit = lt_dlsym(lib->handle, "_fini");
|
|
|
|
|
if (gambas_exit != NULL)
|
|
|
|
|
(*gambas_exit)();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
lt_dlclose(lib->handle);
|
|
|
|
|
|
|
|
|
|
lib->handle = NULL;
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf("Unloading library %s\n", lib->name);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|