forked from bartvdbraak/blender
Code cleanup: PIL_dynlib, renamed to BLI_dynlib, and other tweaks.
This commit is contained in:
parent
e26b0c68a4
commit
4eb1b5256e
@ -37,7 +37,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "MEM_guardedalloc.h"
|
#include "MEM_guardedalloc.h"
|
||||||
#include "PIL_dynlib.h"
|
#include "BLI_dynlib.h"
|
||||||
|
|
||||||
#include "BLI_math.h" /* windows needs for M_PI */
|
#include "BLI_math.h" /* windows needs for M_PI */
|
||||||
#include "BLI_utildefines.h"
|
#include "BLI_utildefines.h"
|
||||||
@ -138,18 +138,18 @@ static void open_plugin_seq(PluginSeq *pis, const char *seqname)
|
|||||||
pis->instance_private_data = NULL;
|
pis->instance_private_data = NULL;
|
||||||
|
|
||||||
/* clear the error list */
|
/* clear the error list */
|
||||||
PIL_dynlib_get_error_as_string(NULL);
|
BLI_dynlib_get_error_as_string(NULL);
|
||||||
|
|
||||||
/* if(pis->handle) PIL_dynlib_close(pis->handle); */
|
/* if(pis->handle) BLI_dynlib_close(pis->handle); */
|
||||||
/* pis->handle= 0; */
|
/* pis->handle= 0; */
|
||||||
|
|
||||||
/* open the needed object */
|
/* open the needed object */
|
||||||
pis->handle= PIL_dynlib_open(pis->name);
|
pis->handle= BLI_dynlib_open(pis->name);
|
||||||
if(test_dlerr(pis->name, pis->name)) return;
|
if(test_dlerr(pis->name, pis->name)) return;
|
||||||
|
|
||||||
if (pis->handle != NULL) {
|
if (pis->handle != NULL) {
|
||||||
/* find the address of the version function */
|
/* find the address of the version function */
|
||||||
version= (int (*)(void))PIL_dynlib_find_symbol(pis->handle, "plugin_seq_getversion");
|
version= (int (*)(void))BLI_dynlib_find_symbol(pis->handle, "plugin_seq_getversion");
|
||||||
if (test_dlerr(pis->name, "plugin_seq_getversion")) return;
|
if (test_dlerr(pis->name, "plugin_seq_getversion")) return;
|
||||||
|
|
||||||
if (version != NULL) {
|
if (version != NULL) {
|
||||||
@ -158,7 +158,7 @@ static void open_plugin_seq(PluginSeq *pis, const char *seqname)
|
|||||||
int (*info_func)(PluginInfo *);
|
int (*info_func)(PluginInfo *);
|
||||||
PluginInfo *info= (PluginInfo*) MEM_mallocN(sizeof(PluginInfo), "plugin_info");
|
PluginInfo *info= (PluginInfo*) MEM_mallocN(sizeof(PluginInfo), "plugin_info");
|
||||||
|
|
||||||
info_func= (int (*)(PluginInfo *))PIL_dynlib_find_symbol(pis->handle, "plugin_getinfo");
|
info_func= (int (*)(PluginInfo *))BLI_dynlib_find_symbol(pis->handle, "plugin_getinfo");
|
||||||
|
|
||||||
if(info_func == NULL) error("No info func");
|
if(info_func == NULL) error("No info func");
|
||||||
else {
|
else {
|
||||||
@ -176,21 +176,21 @@ static void open_plugin_seq(PluginSeq *pis, const char *seqname)
|
|||||||
}
|
}
|
||||||
MEM_freeN(info);
|
MEM_freeN(info);
|
||||||
|
|
||||||
cp= PIL_dynlib_find_symbol(pis->handle, "seqname");
|
cp= BLI_dynlib_find_symbol(pis->handle, "seqname");
|
||||||
if(cp) strncpy(cp, seqname, 21);
|
if(cp) strncpy(cp, seqname, 21);
|
||||||
} else {
|
} else {
|
||||||
printf ("Plugin returned unrecognized version number\n");
|
printf ("Plugin returned unrecognized version number\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
alloc_private = (void* (*)(void))PIL_dynlib_find_symbol(
|
alloc_private = (void* (*)(void))BLI_dynlib_find_symbol(
|
||||||
pis->handle, "plugin_seq_alloc_private_data");
|
pis->handle, "plugin_seq_alloc_private_data");
|
||||||
if (alloc_private) {
|
if (alloc_private) {
|
||||||
pis->instance_private_data = alloc_private();
|
pis->instance_private_data = alloc_private();
|
||||||
}
|
}
|
||||||
|
|
||||||
pis->current_private_data = (void**)
|
pis->current_private_data = (void**)
|
||||||
PIL_dynlib_find_symbol(
|
BLI_dynlib_find_symbol(
|
||||||
pis->handle, "plugin_private_data");
|
pis->handle, "plugin_private_data");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -229,12 +229,12 @@ static void free_plugin_seq(PluginSeq *pis)
|
|||||||
{
|
{
|
||||||
if(pis==NULL) return;
|
if(pis==NULL) return;
|
||||||
|
|
||||||
/* no PIL_dynlib_close: same plugin can be opened multiple times with 1 handle */
|
/* no BLI_dynlib_close: same plugin can be opened multiple times with 1 handle */
|
||||||
|
|
||||||
if (pis->instance_private_data) {
|
if (pis->instance_private_data) {
|
||||||
void (*free_private)(void *);
|
void (*free_private)(void *);
|
||||||
|
|
||||||
free_private = (void (*)(void *))PIL_dynlib_find_symbol(
|
free_private = (void (*)(void *))BLI_dynlib_find_symbol(
|
||||||
pis->handle, "plugin_seq_free_private_data");
|
pis->handle, "plugin_seq_free_private_data");
|
||||||
if (free_private) {
|
if (free_private) {
|
||||||
free_private(pis->instance_private_data);
|
free_private(pis->instance_private_data);
|
||||||
@ -301,7 +301,7 @@ static struct ImBuf * do_plugin_effect(
|
|||||||
if(seq->plugin->cfra)
|
if(seq->plugin->cfra)
|
||||||
*(seq->plugin->cfra)= cfra;
|
*(seq->plugin->cfra)= cfra;
|
||||||
|
|
||||||
cp = PIL_dynlib_find_symbol(
|
cp = BLI_dynlib_find_symbol(
|
||||||
seq->plugin->handle, "seqname");
|
seq->plugin->handle, "seqname");
|
||||||
|
|
||||||
if(cp) strncpy(cp, seq->name+2, 22);
|
if(cp) strncpy(cp, seq->name+2, 22);
|
||||||
|
@ -41,9 +41,8 @@
|
|||||||
|
|
||||||
#include "MEM_guardedalloc.h"
|
#include "MEM_guardedalloc.h"
|
||||||
|
|
||||||
#include "PIL_dynlib.h"
|
|
||||||
|
|
||||||
#include "BLI_blenlib.h"
|
#include "BLI_blenlib.h"
|
||||||
|
#include "BLI_dynlib.h"
|
||||||
#include "BLI_math.h"
|
#include "BLI_math.h"
|
||||||
#include "BLI_kdopbvh.h"
|
#include "BLI_kdopbvh.h"
|
||||||
#include "BLI_utildefines.h"
|
#include "BLI_utildefines.h"
|
||||||
@ -82,7 +81,7 @@ int test_dlerr(const char *name, const char *symbol)
|
|||||||
{
|
{
|
||||||
char *err;
|
char *err;
|
||||||
|
|
||||||
err= PIL_dynlib_get_error_as_string(NULL);
|
err= BLI_dynlib_get_error_as_string(NULL);
|
||||||
if(err) {
|
if(err) {
|
||||||
printf("var1: %s, var2: %s, var3: %s\n", name, symbol, err);
|
printf("var1: %s, var2: %s, var3: %s\n", name, symbol, err);
|
||||||
return 1;
|
return 1;
|
||||||
@ -108,19 +107,19 @@ void open_plugin_tex(PluginTex *pit)
|
|||||||
pit->instance_init= NULL;
|
pit->instance_init= NULL;
|
||||||
|
|
||||||
/* clear the error list */
|
/* clear the error list */
|
||||||
PIL_dynlib_get_error_as_string(NULL);
|
BLI_dynlib_get_error_as_string(NULL);
|
||||||
|
|
||||||
/* no PIL_dynlib_close! multiple opened plugins... */
|
/* no BLI_dynlib_close! multiple opened plugins... */
|
||||||
/* if(pit->handle) PIL_dynlib_close(pit->handle); */
|
/* if(pit->handle) BLI_dynlib_close(pit->handle); */
|
||||||
/* pit->handle= 0; */
|
/* pit->handle= 0; */
|
||||||
|
|
||||||
/* open the needed object */
|
/* open the needed object */
|
||||||
pit->handle= PIL_dynlib_open(pit->name);
|
pit->handle= BLI_dynlib_open(pit->name);
|
||||||
if(test_dlerr(pit->name, pit->name)) return;
|
if(test_dlerr(pit->name, pit->name)) return;
|
||||||
|
|
||||||
if (pit->handle != NULL) {
|
if (pit->handle != NULL) {
|
||||||
/* find the address of the version function */
|
/* find the address of the version function */
|
||||||
version= (int (*)(void)) PIL_dynlib_find_symbol(pit->handle, "plugin_tex_getversion");
|
version= (int (*)(void)) BLI_dynlib_find_symbol(pit->handle, "plugin_tex_getversion");
|
||||||
if (test_dlerr(pit->name, "plugin_tex_getversion")) return;
|
if (test_dlerr(pit->name, "plugin_tex_getversion")) return;
|
||||||
|
|
||||||
if (version != NULL) {
|
if (version != NULL) {
|
||||||
@ -129,7 +128,7 @@ void open_plugin_tex(PluginTex *pit)
|
|||||||
int (*info_func)(PluginInfo *);
|
int (*info_func)(PluginInfo *);
|
||||||
PluginInfo *info= (PluginInfo*) MEM_mallocN(sizeof(PluginInfo), "plugin_info");
|
PluginInfo *info= (PluginInfo*) MEM_mallocN(sizeof(PluginInfo), "plugin_info");
|
||||||
|
|
||||||
info_func= (int (*)(PluginInfo *))PIL_dynlib_find_symbol(pit->handle, "plugin_getinfo");
|
info_func= (int (*)(PluginInfo *))BLI_dynlib_find_symbol(pit->handle, "plugin_getinfo");
|
||||||
if (!test_dlerr(pit->name, "plugin_getinfo")) {
|
if (!test_dlerr(pit->name, "plugin_getinfo")) {
|
||||||
info->instance_init = NULL;
|
info->instance_init = NULL;
|
||||||
|
|
||||||
@ -200,7 +199,7 @@ void free_plugin_tex(PluginTex *pit)
|
|||||||
{
|
{
|
||||||
if(pit==NULL) return;
|
if(pit==NULL) return;
|
||||||
|
|
||||||
/* no PIL_dynlib_close: same plugin can be opened multiple times, 1 handle */
|
/* no BLI_dynlib_close: same plugin can be opened multiple times, 1 handle */
|
||||||
MEM_freeN(pit);
|
MEM_freeN(pit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,31 +27,19 @@
|
|||||||
* ***** END GPL LICENSE BLOCK *****
|
* ***** END GPL LICENSE BLOCK *****
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** \file blender/blenlib/PIL_dynlib.h
|
/** \file blender/blenlib/BLI_dynlib.h
|
||||||
* \ingroup bli
|
* \ingroup bli
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __PIL_DYNLIB_H__
|
#ifndef __BLI_DYNLIB_H__
|
||||||
#define __PIL_DYNLIB_H__
|
#define __BLI_DYNLIB_H__
|
||||||
|
|
||||||
typedef struct PILdynlib PILdynlib;
|
typedef struct DynamicLibrary DynamicLibrary;
|
||||||
|
|
||||||
PILdynlib*
|
DynamicLibrary *BLI_dynlib_open(char *name);
|
||||||
PIL_dynlib_open(
|
void *BLI_dynlib_find_symbol(DynamicLibrary* lib, const char *symname);
|
||||||
char *name);
|
char *BLI_dynlib_get_error_as_string(DynamicLibrary* lib);
|
||||||
|
void BLI_dynlib_close(DynamicLibrary* lib);
|
||||||
|
|
||||||
void*
|
#endif /* __BLI_DYNLIB_H__ */
|
||||||
PIL_dynlib_find_symbol(
|
|
||||||
PILdynlib* lib,
|
|
||||||
const char *symname);
|
|
||||||
|
|
||||||
char*
|
|
||||||
PIL_dynlib_get_error_as_string(
|
|
||||||
PILdynlib* lib);
|
|
||||||
|
|
||||||
void
|
|
||||||
PIL_dynlib_close(
|
|
||||||
PILdynlib* lib);
|
|
||||||
|
|
||||||
#endif /* __PIL_DYNLIB_H__ */
|
|
||||||
|
|
@ -88,6 +88,7 @@ set(SRC
|
|||||||
BLI_bpath.h
|
BLI_bpath.h
|
||||||
BLI_cpu.h
|
BLI_cpu.h
|
||||||
BLI_dlrbTree.h
|
BLI_dlrbTree.h
|
||||||
|
BLI_dynlib.h
|
||||||
BLI_dynstr.h
|
BLI_dynstr.h
|
||||||
BLI_edgehash.h
|
BLI_edgehash.h
|
||||||
BLI_editVert.h
|
BLI_editVert.h
|
||||||
@ -127,7 +128,6 @@ set(SRC
|
|||||||
BLI_vfontdata.h
|
BLI_vfontdata.h
|
||||||
BLI_voxel.h
|
BLI_voxel.h
|
||||||
BLI_winstuff.h
|
BLI_winstuff.h
|
||||||
PIL_dynlib.h
|
|
||||||
PIL_time.h
|
PIL_time.h
|
||||||
intern/BLI_callbacks.h
|
intern/BLI_callbacks.h
|
||||||
intern/dynamiclist.h
|
intern/dynamiclist.h
|
||||||
|
@ -31,110 +31,101 @@
|
|||||||
* \ingroup bli
|
* \ingroup bli
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "../PIL_dynlib.h"
|
|
||||||
|
|
||||||
#if !defined(CHAR_MAX)
|
|
||||||
#define CHAR_MAX 255
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* XXX, should use mallocN so we can see
|
|
||||||
* handle's not being released. fixme zr
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <windows.h>
|
#include "MEM_guardedalloc.h"
|
||||||
|
|
||||||
struct PILdynlib {
|
#include "BLI_dynlib.h"
|
||||||
|
|
||||||
|
struct DynamicLibrary {
|
||||||
void *handle;
|
void *handle;
|
||||||
};
|
};
|
||||||
|
|
||||||
PILdynlib *PIL_dynlib_open(char *name) {
|
#ifdef WIN32
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
DynamicLibrary *BLI_dynlib_open(char *name)
|
||||||
|
{
|
||||||
|
DynamicLibrary *lib;
|
||||||
void *handle= LoadLibrary(name);
|
void *handle= LoadLibrary(name);
|
||||||
|
|
||||||
if (handle) {
|
if(!handle)
|
||||||
PILdynlib *lib= malloc(sizeof(*lib));
|
|
||||||
lib->handle= handle;
|
|
||||||
|
|
||||||
return lib;
|
|
||||||
} else {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
lib= MEM_callocN(sizeof(*lib), "Dynamic Library");
|
||||||
|
lib->handle= handle;
|
||||||
|
|
||||||
|
return lib;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *PIL_dynlib_find_symbol(PILdynlib* lib, const char *symname) {
|
void *BLI_dynlib_find_symbol(DynamicLibrary *lib, const char *symname)
|
||||||
|
{
|
||||||
return GetProcAddress(lib->handle, symname);
|
return GetProcAddress(lib->handle, symname);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *PIL_dynlib_get_error_as_string(PILdynlib* lib) {
|
char *BLI_dynlib_get_error_as_string(DynamicLibrary *lib)
|
||||||
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
/* if lib is NULL reset the last error code */
|
/* if lib is NULL reset the last error code */
|
||||||
err= GetLastError();
|
err= GetLastError();
|
||||||
if (!lib) SetLastError(ERROR_SUCCESS);
|
if(!lib)
|
||||||
|
SetLastError(ERROR_SUCCESS);
|
||||||
|
|
||||||
if (err) {
|
if(err) {
|
||||||
static char buf[1024];
|
static char buf[1024];
|
||||||
|
|
||||||
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
|
if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
NULL,
|
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
err,
|
buf, sizeof(buf), NULL))
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
||||||
buf,
|
|
||||||
sizeof(buf),
|
|
||||||
NULL))
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PIL_dynlib_close(PILdynlib *lib) {
|
void BLI_dynlib_close(DynamicLibrary *lib)
|
||||||
|
{
|
||||||
FreeLibrary(lib->handle);
|
FreeLibrary(lib->handle);
|
||||||
|
MEM_freeN(lib);
|
||||||
free(lib);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* Unix */
|
#else /* Unix */
|
||||||
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
|
||||||
struct PILdynlib {
|
DynamicLibrary *BLI_dynlib_open(char *name)
|
||||||
void *handle;
|
{
|
||||||
};
|
DynamicLibrary *lib;
|
||||||
|
|
||||||
PILdynlib *PIL_dynlib_open(char *name) {
|
|
||||||
void *handle= dlopen(name, RTLD_LAZY);
|
void *handle= dlopen(name, RTLD_LAZY);
|
||||||
|
|
||||||
if (handle) {
|
if(!handle)
|
||||||
PILdynlib *lib= malloc(sizeof(*lib));
|
|
||||||
lib->handle= handle;
|
|
||||||
|
|
||||||
return lib;
|
|
||||||
} else {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
lib= MEM_callocN(sizeof(*lib), "Dynamic Library");
|
||||||
|
lib->handle= handle;
|
||||||
|
|
||||||
|
return lib;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *PIL_dynlib_find_symbol(PILdynlib* lib, const char *symname) {
|
void *BLI_dynlib_find_symbol(DynamicLibrary *lib, const char *symname)
|
||||||
|
{
|
||||||
return dlsym(lib->handle, symname);
|
return dlsym(lib->handle, symname);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *PIL_dynlib_get_error_as_string(PILdynlib* lib) {
|
char *BLI_dynlib_get_error_as_string(DynamicLibrary *lib)
|
||||||
|
{
|
||||||
(void)lib; /* unused */
|
(void)lib; /* unused */
|
||||||
return dlerror();
|
return dlerror();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PIL_dynlib_close(PILdynlib *lib) {
|
void BLI_dynlib_close(DynamicLibrary *lib)
|
||||||
|
{
|
||||||
dlclose(lib->handle);
|
dlclose(lib->handle);
|
||||||
|
MEM_freeN(lib);
|
||||||
free(lib);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user