Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: third_party/dlfcn-win32/test.c

Issue 137143003: Add dlfcn-win32 to third_party (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/deps/
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/dlfcn-win32/dlfcn.c ('k') | third_party/dlfcn-win32/testdll.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 /*
2 * dlfcn-win32
3 * Copyright (c) 2007 Ramiro Polla
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US A
18 */
19
20 #include <stdio.h>
21 #include "dlfcn.h"
22
23 /* If these dlclose's fails, we don't care as the handles are going to be
24 closed eventually when the program ends. */
25 #define CLOSE_LIB dlclose( library );
26 #define CLOSE_GLOBAL dlclose( global );
27
28 #define RETURN_ERROR return 1;
29
30 /* This is what this test does:
31 * - Open library with RTLD_GLOBAL
32 * - Get global object
33 * - Get symbol from library through library object <- works
34 * - Run function if it worked
35 * - Get symbol from library through global object <- works
36 * - Run function if it worked
37 * - Close library
38 * - Open library with RTLD_LOCAL
39 * - Get symbol from library through library object <- works
40 * - Run function if it worked
41 * - Get symbol from library through global object <- fails
42 * - Run function if it worked
43 * - Open library again (without closing it first) with RTLD_GLOBAL
44 * - Get symbol from library through global object <- works
45 * - Close library
46 * - Close global object
47 */
48
49 int main()
50 {
51 void *global;
52 void *library;
53 char *error;
54 int (*function)( void );
55 int ret;
56
57 library = dlopen( "testdll.dll", RTLD_GLOBAL );
58 if( !library )
59 {
60 error = dlerror( );
61 printf( "Could not open library globally: %s\n", error ? error : "" );
62 }
63 else
64 printf( "Opened library globally: %p\n", library );
65
66 global = dlopen( 0, RTLD_GLOBAL );
67 if( !global )
68 {
69 error = dlerror( );
70 printf( "Could not open global handle: %s\n", error ? error : "" );
71 CLOSE_LIB
72 RETURN_ERROR
73 }
74 else
75 printf( "Got global handle: %p\n", global );
76
77 function = dlsym( library, "function" );
78 if( !function )
79 {
80 error = dlerror( );
81 printf( "Could not get symbol from library handle: %s\n",
82 error ? error : "" );
83 CLOSE_LIB
84 CLOSE_GLOBAL
85 RETURN_ERROR
86 }
87 else
88 printf( "Got symbol from library handle: %p\n", function );
89
90 if( function )
91 function( );
92
93 function = dlsym( global, "function" );
94 if( !function )
95 {
96 error = dlerror( );
97 printf( "Could not get symbol from global handle: %s\n",
98 error ? error : "" );
99 CLOSE_LIB
100 CLOSE_GLOBAL
101 RETURN_ERROR
102 }
103 else
104 printf( "Got symbol from global handle: %p\n", function );
105
106 if( function )
107 function( );
108
109 ret = dlclose( library );
110 if( ret )
111 {
112 error = dlerror( );
113 printf( "Could not close library: %s\n", error ? error : "" );
114 }
115 else
116 printf( "Closed library.\n" );
117
118 library = dlopen( "testdll.dll", RTLD_LOCAL );
119 if( !library )
120 {
121 error = dlerror( );
122 printf( "Could not open library locally: %s\n", error ? error : "" );
123 CLOSE_LIB
124 CLOSE_GLOBAL
125 RETURN_ERROR
126 }
127 else
128 printf( "Opened library locally: %p\n", library );
129
130 function = dlsym( library, "function" );
131 if( !function )
132 {
133 error = dlerror( );
134 printf( "Could not get symbol from library handle: %s\n",
135 error ? error : "" );
136 CLOSE_LIB
137 CLOSE_GLOBAL
138 RETURN_ERROR
139 }
140 else
141 printf( "Got symbol from library handle: %p\n", function );
142
143 if( function )
144 function( );
145
146 function = dlsym( global, "function" );
147 if( function )
148 {
149 error = dlerror( );
150 printf( "Got local symbol from global handle: %s\n",
151 error ? error : "" );
152 CLOSE_LIB
153 CLOSE_GLOBAL
154 RETURN_ERROR
155 }
156 else
157 printf( "Did not get local symbol from global handle: %p\n", function );
158
159 if( function )
160 function( );
161
162 ret = dlclose( library );
163 if( ret )
164 {
165 error = dlerror( );
166 printf( "Could not close library: %s\n", error ? error : "" );
167 CLOSE_GLOBAL
168 RETURN_ERROR
169 }
170 else
171 printf( "Closed library.\n" );
172
173 ret = dlclose( global );
174 if( ret )
175 {
176 error = dlerror( );
177 printf( "Could not close global handle: %s\n", error ? error : "" );
178 RETURN_ERROR
179 }
180 else
181 printf( "Closed global handle.\n" );
182
183 return 0;
184 }
OLDNEW
« no previous file with comments | « third_party/dlfcn-win32/dlfcn.c ('k') | third_party/dlfcn-win32/testdll.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698