You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by yd...@apache.org on 2014/02/22 15:29:08 UTC

svn commit: r1570843 - /openoffice/trunk/main/sal/osl/os2/module.c

Author: ydario
Date: Sat Feb 22 14:29:08 2014
New Revision: 1570843

URL: http://svn.apache.org/r1570843
Log:
#i118923# OS/2 port, report correct error string in case of dlopen() failure, rewrote code to use more dl* functions.

Modified:
    openoffice/trunk/main/sal/osl/os2/module.c

Modified: openoffice/trunk/main/sal/osl/os2/module.c
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sal/osl/os2/module.c?rev=1570843&r1=1570842&r2=1570843&view=diff
==============================================================================
--- openoffice/trunk/main/sal/osl/os2/module.c (original)
+++ openoffice/trunk/main/sal/osl/os2/module.c Sat Feb 22 14:29:08 2014
@@ -22,8 +22,6 @@
 
 
 
-#include "system.h"
-
 #include <osl/module.h>
 #include <osl/diagnose.h>
 #include <osl/file.h>
@@ -32,106 +30,97 @@
 #include <stdlib.h>
 #include <dlfcn.h>
 
-int UnicodeToText(char *, size_t, const sal_Unicode *, sal_Int32);
+#include "system.h"
 
-// static data for holding SAL dll module and full path
-static HMODULE hModSal;
-static char	szSalDir[ _MAX_PATH];
-static char	szSalDrive[ _MAX_PATH];
+/* implemented in file.cxx */
+int UnicodeToText(char *, size_t, const sal_Unicode *, sal_Int32);
 
 /*****************************************************************************/
 /* osl_loadModule */
 /*****************************************************************************/
 
-ULONG APIENTRY _DosLoadModule (PSZ pszObject, ULONG uObjectLen, PCSZ pszModule,
-    PHMODULE phmod)
-{
-	APIRET	rc;
-	rc = DosLoadModule( pszObject, uObjectLen, pszModule, phmod);
-	// YD 22/05/06 issue again if first call fails (why?)
-	if (rc == ERROR_INVALID_PARAMETER)
-		rc = DosLoadModule( pszObject, uObjectLen, pszModule, phmod);
-	return rc;
-}
-
-oslModule SAL_CALL osl_loadAsciiModule( const sal_Char* pModuleName, sal_Int32 nRtldMode )
-{
-	rtl_uString* pUniName = NULL;
-	rtl_uString_newFromAscii( &pUniName, pModuleName );
-	oslModule aModule = osl_loadModule( pUniName, nRtldMode );
-	rtl_uString_release( pUniName );
-	return aModule;
-}
-
 oslModule SAL_CALL osl_loadModule(rtl_uString *ustrModuleName, sal_Int32 nRtldMode)
 {
-    HMODULE hModule;
-    BYTE szErrorMessage[256];
-    APIRET rc;
     oslModule pModule=0;
     rtl_uString* ustrTmp = NULL;
 
     OSL_ENSURE(ustrModuleName,"osl_loadModule : string is not valid");
 
     /* ensure ustrTmp hold valid string */
-    if( osl_File_E_None != osl_getSystemPathFromFileURL( ustrModuleName, &ustrTmp ) )
-        rtl_uString_assign( &ustrTmp, ustrModuleName );
+    if (osl_File_E_None != osl_getSystemPathFromFileURL(ustrModuleName, &ustrTmp))
+        rtl_uString_assign(&ustrTmp, ustrModuleName);
 
-    if( ustrTmp )
+    if (ustrTmp)
     {
         char buffer[PATH_MAX];
 
-        if( UnicodeToText( buffer, PATH_MAX, ustrTmp->buffer, ustrTmp->length ) )
-		{
-			char drive[_MAX_DRIVE], dir[_MAX_DIR];
-			char fname[_MAX_FNAME], ext[_MAX_EXT];
-			char* dot;
-			// 21/02/2006 YD dll names must be 8.3: since .uno.dll files
-			// have hardcoded names, I'm truncating names here and also in
-			// the build system
-			_splitpath (buffer, drive, dir, fname, ext);
-			if (strlen(fname)>8)
-				fname[8] = 0;	// truncate to 8.3
-			dot = strchr( fname, '.');
-			if (dot)
-				*dot = '\0';	// truncate on dot
-			// if drive is not specified, remove starting \ from dir name
-			// so dll is loaded from LIBPATH
-			if (drive[0] == 0 && dir[0] == '\\' && dir[1] == '\\') {
-				while( dir[0] == '\\')
-					strcpy( dir, dir+1);
-			}
-			_makepath( buffer, drive, dir, fname, ext);
+        if (UnicodeToText(buffer, PATH_MAX, ustrTmp->buffer, ustrTmp->length))
+            pModule = osl_loadAsciiModule(buffer, nRtldMode);
+        rtl_uString_release(ustrTmp);
+    }
 
-#if OSL_DEBUG_LEVEL>10
-			debug_printf("osl_loadModule module %s", buffer);
+    return pModule;
+}
+
+/*****************************************************************************/
+/* osl_loadAsciiModule */
+/*****************************************************************************/
+
+oslModule SAL_CALL osl_loadAsciiModule(const sal_Char *pszModuleName, sal_Int32 nRtldMode)
+{
+	char drive[_MAX_DRIVE], dir[_MAX_DIR];
+	char fname[_MAX_FNAME], ext[_MAX_EXT];
+	char buffer[PATH_MAX];
+	char* dot;
+	void* hModule;
+	oslModule pModule = NULL;
+
+	if (!pszModuleName)
+		return NULL;
+
+	// 21/02/2006 YD dll names must be 8.3: since .uno.dll files
+	// have hardcoded names, I'm truncating names here and also in
+	// the build system
+	_splitpath (pszModuleName, drive, dir, fname, ext);
+	if (strlen(fname)>8)
+		fname[8] = 0;	// truncate to 8.3
+	dot = strchr( fname, '.');
+	if (dot)
+		*dot = '\0';	// truncate on dot
+
+	// if drive is not specified, remove starting \ from dir name
+	// so dll is loaded from LIBPATH
+	if (drive[0] == 0 && dir[0] == '\\' && dir[1] == '\\') {
+		while( dir[0] == '\\')
+			strcpy( dir, dir+1);
+	}
+	_makepath( buffer, drive, dir, fname, ext);
+
+#if OSL_DEBUG_LEVEL>1
+	debug_printf("osl_loadModule module %s", buffer);
 #endif
-			hModule = dlopen( buffer, RTLD_LOCAL);
-			if (hModule != NULL )
-				pModule = (oslModule)hModule;
-			else
-			{
-					sal_Char szError[ PATH_MAX*2 ];
-					sprintf( szError, "Module: %s; errno: %d;\n"
-							"Please contact technical support and report above informations.\n\n", 
-							buffer, errno );
+	
+	hModule = dlopen( buffer, RTLD_LOCAL);
+	if (hModule != NULL)
+		pModule = (oslModule)hModule;
+	else
+	{
+		sal_Char szError[ PATH_MAX*2 ];
+		sprintf( szError, "Module: %s;\n error: %s;\n\n"
+				 "Please contact technical support and report above informations.\n\n", 
+				 buffer, dlerror() );
 #if OSL_DEBUG_LEVEL>0
-					fprintf( stderr, szError);
+		debug_printf("osl_loadModule error %s", szError);
 #endif
-					debug_printf("osl_loadModule error %s", szError);
-
+		
 #if (OSL_DEBUG_LEVEL==0) || !defined(OSL_DEBUG_LEVEL)
-					WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,
-						szError, "Critical error: DosLoadModule failed",
-						0, MB_ERROR | MB_OK | MB_MOVEABLE);
+		WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,
+					  szError, "Critical error: DosLoadModule failed",
+					  0, MB_ERROR | MB_OK | MB_MOVEABLE);
 #endif
-			}
-		}
-    }
-
-    rtl_uString_release( ustrTmp );
+	}
 
-    return pModule;
+	return pModule;
 }
 
 /*****************************************************************************/
@@ -143,27 +132,45 @@ osl_getModuleHandle(rtl_uString *pModule
 {
     HMODULE hmod;
     APIRET  rc;
-    rc = DosQueryModuleHandle(pModuleName->buffer, &hmod);
-    if( rc == NO_ERROR)
+
+    OSL_ENSURE(pModuleName,"osl_loadModule : string is not valid");
+    
+    if (pModuleName)
     {
-        *pResult = (oslModule) hmod;
-        return sal_True;
+        char buffer[PATH_MAX];
+
+        if (UnicodeToText(buffer, PATH_MAX, pModuleName->buffer, 
+                          pModuleName->length)) 
+        {
+            rc = DosQueryModuleHandle(buffer, &hmod);
+            if( rc == NO_ERROR)
+            {
+                *pResult = (oslModule) hmod;
+                return sal_True;
+            }
+        }
     }
-    
+
     return sal_False;
 }
 
 /*****************************************************************************/
 /* osl_unloadModule */
 /*****************************************************************************/
-void SAL_CALL osl_unloadModule(oslModule Module)
+void SAL_CALL osl_unloadModule(oslModule hModule)
 {
-#if OSL_DEBUG_LEVEL>0
-    if (!Module)
-       fprintf( stderr, "osl_unloadModule NULL HANDLE.\n");
-#endif
-
-    DosFreeModule((HMODULE)Module);
+	if (hModule)
+	{
+		int nRet = dlclose(hModule);
+#if OSL_DEBUG_LEVEL > 1
+        if (nRet != 0)
+        {
+            debug_printf( "osl_unloadModule failed with %s\n", dlerror());
+        }
+#else
+        (void) nRet;
+#endif /* if OSL_DEBUG_LEVEL */
+    }
 }
 
 /*****************************************************************************/