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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/dlfcn-win32/dlfcn.c ('k') | third_party/dlfcn-win32/testdll.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/dlfcn-win32/test.c
===================================================================
--- third_party/dlfcn-win32/test.c (revision 0)
+++ third_party/dlfcn-win32/test.c (revision 0)
@@ -0,0 +1,184 @@
+/*
+ * dlfcn-win32
+ * Copyright (c) 2007 Ramiro Polla
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include "dlfcn.h"
+
+/* If these dlclose's fails, we don't care as the handles are going to be
+ closed eventually when the program ends. */
+#define CLOSE_LIB dlclose( library );
+#define CLOSE_GLOBAL dlclose( global );
+
+#define RETURN_ERROR return 1;
+
+/* This is what this test does:
+ * - Open library with RTLD_GLOBAL
+ * - Get global object
+ * - Get symbol from library through library object <- works
+ * - Run function if it worked
+ * - Get symbol from library through global object <- works
+ * - Run function if it worked
+ * - Close library
+ * - Open library with RTLD_LOCAL
+ * - Get symbol from library through library object <- works
+ * - Run function if it worked
+ * - Get symbol from library through global object <- fails
+ * - Run function if it worked
+ * - Open library again (without closing it first) with RTLD_GLOBAL
+ * - Get symbol from library through global object <- works
+ * - Close library
+ * - Close global object
+ */
+
+int main()
+{
+ void *global;
+ void *library;
+ char *error;
+ int (*function)( void );
+ int ret;
+
+ library = dlopen( "testdll.dll", RTLD_GLOBAL );
+ if( !library )
+ {
+ error = dlerror( );
+ printf( "Could not open library globally: %s\n", error ? error : "" );
+ }
+ else
+ printf( "Opened library globally: %p\n", library );
+
+ global = dlopen( 0, RTLD_GLOBAL );
+ if( !global )
+ {
+ error = dlerror( );
+ printf( "Could not open global handle: %s\n", error ? error : "" );
+ CLOSE_LIB
+ RETURN_ERROR
+ }
+ else
+ printf( "Got global handle: %p\n", global );
+
+ function = dlsym( library, "function" );
+ if( !function )
+ {
+ error = dlerror( );
+ printf( "Could not get symbol from library handle: %s\n",
+ error ? error : "" );
+ CLOSE_LIB
+ CLOSE_GLOBAL
+ RETURN_ERROR
+ }
+ else
+ printf( "Got symbol from library handle: %p\n", function );
+
+ if( function )
+ function( );
+
+ function = dlsym( global, "function" );
+ if( !function )
+ {
+ error = dlerror( );
+ printf( "Could not get symbol from global handle: %s\n",
+ error ? error : "" );
+ CLOSE_LIB
+ CLOSE_GLOBAL
+ RETURN_ERROR
+ }
+ else
+ printf( "Got symbol from global handle: %p\n", function );
+
+ if( function )
+ function( );
+
+ ret = dlclose( library );
+ if( ret )
+ {
+ error = dlerror( );
+ printf( "Could not close library: %s\n", error ? error : "" );
+ }
+ else
+ printf( "Closed library.\n" );
+
+ library = dlopen( "testdll.dll", RTLD_LOCAL );
+ if( !library )
+ {
+ error = dlerror( );
+ printf( "Could not open library locally: %s\n", error ? error : "" );
+ CLOSE_LIB
+ CLOSE_GLOBAL
+ RETURN_ERROR
+ }
+ else
+ printf( "Opened library locally: %p\n", library );
+
+ function = dlsym( library, "function" );
+ if( !function )
+ {
+ error = dlerror( );
+ printf( "Could not get symbol from library handle: %s\n",
+ error ? error : "" );
+ CLOSE_LIB
+ CLOSE_GLOBAL
+ RETURN_ERROR
+ }
+ else
+ printf( "Got symbol from library handle: %p\n", function );
+
+ if( function )
+ function( );
+
+ function = dlsym( global, "function" );
+ if( function )
+ {
+ error = dlerror( );
+ printf( "Got local symbol from global handle: %s\n",
+ error ? error : "" );
+ CLOSE_LIB
+ CLOSE_GLOBAL
+ RETURN_ERROR
+ }
+ else
+ printf( "Did not get local symbol from global handle: %p\n", function );
+
+ if( function )
+ function( );
+
+ ret = dlclose( library );
+ if( ret )
+ {
+ error = dlerror( );
+ printf( "Could not close library: %s\n", error ? error : "" );
+ CLOSE_GLOBAL
+ RETURN_ERROR
+ }
+ else
+ printf( "Closed library.\n" );
+
+ ret = dlclose( global );
+ if( ret )
+ {
+ error = dlerror( );
+ printf( "Could not close global handle: %s\n", error ? error : "" );
+ RETURN_ERROR
+ }
+ else
+ printf( "Closed global handle.\n" );
+
+ return 0;
+}
Property changes on: third_party/dlfcn-win32/test.c
___________________________________________________________________
Added: svn:eol-style
+ LF
« 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