~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/blenlib/intern/dynlib.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * $Id: dynlib.c 28254 2010-04-18 10:28:37Z campbellbarton $
3
 
 *
 
1
/*
4
2
 * ***** BEGIN GPL LICENSE BLOCK *****
5
3
 *
6
4
 * This program is free software; you can redistribute it and/or
27
25
 * ***** END GPL LICENSE BLOCK *****
28
26
 */
29
27
 
 
28
/** \file blender/blenlib/intern/dynlib.c
 
29
 *  \ingroup bli
 
30
 */
 
31
 
 
32
#include <stdio.h>
30
33
#include <stdlib.h>
31
 
 
32
 
#include "../PIL_dynlib.h"
33
 
 
34
 
#if !defined(CHAR_MAX)
35
 
#define CHAR_MAX 255
36
 
#endif
37
 
 
38
 
/*
39
 
 * XXX, should use mallocN so we can see
40
 
 * handle's not being released. fixme zr
41
 
 */
42
 
 
 
34
#include <string.h>
 
35
 
 
36
#include "MEM_guardedalloc.h"
 
37
 
 
38
#include "BLI_dynlib.h"
 
39
 
 
40
struct DynamicLibrary {
 
41
        void *handle;
 
42
};
 
43
 
43
44
#ifdef WIN32
44
 
#include <string.h>
45
 
#include <stdio.h>
46
45
 
47
46
#include <windows.h>
 
47
#include "utf_winfunc.h"
 
48
#include "utfconv.h"
48
49
 
49
 
struct PILdynlib {
 
50
DynamicLibrary *BLI_dynlib_open(char *name)
 
51
{
 
52
        DynamicLibrary *lib;
50
53
        void *handle;
51
 
};
52
 
 
53
 
PILdynlib *PIL_dynlib_open(char *name) {
54
 
        void *handle= LoadLibrary(name);
55
 
 
56
 
        if (handle) {   
57
 
                PILdynlib *lib= malloc(sizeof(*lib));
58
 
                lib->handle= handle;
 
54
 
 
55
        UTF16_ENCODE(name);
 
56
        handle= LoadLibraryW(name_16);
 
57
        UTF16_UN_ENCODE(name);
 
58
 
 
59
        if (!handle)
 
60
                return NULL;
 
61
 
 
62
        lib= MEM_callocN(sizeof(*lib), "Dynamic Library");
 
63
        lib->handle= handle;
59
64
                
60
 
                return lib;
61
 
        } else {
62
 
                return NULL;
63
 
        }
 
65
        return lib;
64
66
}
65
67
 
66
 
void *PIL_dynlib_find_symbol(PILdynlib* lib, char *symname) {
 
68
void *BLI_dynlib_find_symbol(DynamicLibrary *lib, const char *symname)
 
69
{
67
70
        return GetProcAddress(lib->handle, symname);
68
71
}
69
72
 
70
 
char *PIL_dynlib_get_error_as_string(PILdynlib* lib) {
 
73
char *BLI_dynlib_get_error_as_string(DynamicLibrary *lib)
 
74
{
71
75
        int err;
72
76
 
73
77
        /* if lib is NULL reset the last error code */
74
78
        err= GetLastError();
75
 
        if (!lib) SetLastError(ERROR_SUCCESS);
 
79
        if (!lib)
 
80
                SetLastError(ERROR_SUCCESS);
76
81
 
77
82
        if (err) {
78
83
                static char buf[1024];
79
84
 
80
85
                if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, 
81
 
                                        NULL, 
82
 
                                        err, 
83
 
                                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
84
 
                                        buf, 
85
 
                                        sizeof(buf), 
86
 
                                        NULL))
 
86
                        NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
 
87
                        buf, sizeof(buf), NULL))
87
88
                        return buf;
88
89
        }
89
90
        
90
 
        return err;
 
91
        return NULL;
91
92
}
92
93
 
93
 
void PIL_dynlib_close(PILdynlib *lib) {
 
94
void BLI_dynlib_close(DynamicLibrary *lib)
 
95
{
94
96
        FreeLibrary(lib->handle);
95
 
        
96
 
        free(lib);
 
97
        MEM_freeN(lib);
97
98
}
98
99
 
99
 
#else   /* Unix */
 
100
#else /* Unix */
100
101
 
101
102
#include <dlfcn.h>
102
103
 
103
 
struct PILdynlib {
104
 
        void *handle;
105
 
};
106
 
 
107
 
PILdynlib *PIL_dynlib_open(char *name) {
 
104
DynamicLibrary *BLI_dynlib_open(char *name)
 
105
{
 
106
        DynamicLibrary *lib;
108
107
        void *handle= dlopen(name, RTLD_LAZY);
109
108
 
110
 
        if (handle) {   
111
 
                PILdynlib *lib= malloc(sizeof(*lib));
112
 
                lib->handle= handle;
 
109
        if (!handle)
 
110
                return NULL;
 
111
 
 
112
        lib= MEM_callocN(sizeof(*lib), "Dynamic Library");
 
113
        lib->handle= handle;
113
114
                
114
 
                return lib;
115
 
        } else {
116
 
                return NULL;
117
 
        }
 
115
        return lib;
118
116
}
119
117
 
120
 
void *PIL_dynlib_find_symbol(PILdynlib* lib, char *symname) {
 
118
void *BLI_dynlib_find_symbol(DynamicLibrary *lib, const char *symname)
 
119
{
121
120
        return dlsym(lib->handle, symname);
122
121
}
123
122
 
124
 
char *PIL_dynlib_get_error_as_string(PILdynlib* lib) {
 
123
char *BLI_dynlib_get_error_as_string(DynamicLibrary *lib)
 
124
{
 
125
        (void)lib; /* unused */
125
126
        return dlerror();
126
127
}
127
128
        
128
 
void PIL_dynlib_close(PILdynlib *lib) {
 
129
void BLI_dynlib_close(DynamicLibrary *lib)
 
130
{
129
131
        dlclose(lib->handle);
130
 
        
131
 
        free(lib);
 
132
        MEM_freeN(lib);
132
133
}
133
134
 
134
135
#endif