Bugzilla Bug 326168: more cleanups after code review. r=darin,jshin. NSPRPUB_PRE_4_2_CLIENT_BRANCH
authorwtchang%redhat.com
Wed, 05 Apr 2006 21:12:06 +0000
branchNSPRPUB_PRE_4_2_CLIENT_BRANCH
changeset 3624 7e8c67c00b3ddb9021ba1164f63baa7baaf4c020
parent 3618 13d7f0c2d0c01e34b161497647a7189230ee2fc6
child 3625 5c2cd1e252dfcbfd2b257629ab40ddef6f0709c8
push idunknown
push userunknown
push dateunknown
reviewersdarin, jshin
bugs326168
Bugzilla Bug 326168: more cleanups after code review. r=darin,jshin. Modified files: prlink.h prlink.c w95io.c Tag: NSPRPUB_PRE_4_2_CLIENT_BRANCH
pr/include/prlink.h
pr/src/linking/prlink.c
pr/src/md/windows/w95io.c
--- a/pr/include/prlink.h
+++ b/pr/include/prlink.h
@@ -114,18 +114,18 @@ NSPR_API(PRLibrary*) PR_LoadLibrary(cons
 **
 ** On some operating systems such as Mac OS, a shared library may
 ** contain code fragments that can be individually loaded.
 ** PRLibSpec also allows NSPR clients to identify a code fragment
 ** in a library, if code fragments are supported by the OS.
 ** A code fragment can be specified by name or by an integer index.
 **
 ** Right now PRLibSpec supports four types of library specification:
-** a pathname in the native charset, a Mac code fragment by name,
-** a Mac code fragment by index, and a UTF-16 pathname.
+** a pathname in the native character encoding, a Mac code fragment
+** by name, a Mac code fragment by index, and a UTF-16 pathname.
 */
 
 typedef enum PRLibSpecType {
     PR_LibSpec_Pathname,
     PR_LibSpec_MacNamedFragment,   /* obsolete (for Mac OS Classic) */
     PR_LibSpec_MacIndexedFragment, /* obsolete (for Mac OS Classic) */
     PR_LibSpec_PathnameU           /* supported only on Win32 */ 
 } PRLibSpecType;
@@ -160,17 +160,17 @@ typedef struct PRLibSpec {
 ** as the 'flags' argument to PR_LoadLibraryWithFlags.
 ** Flags not supported by the underlying OS are ignored.
 */
 
 #define PR_LD_LAZY   0x1  /* equivalent to RTLD_LAZY on Unix */
 #define PR_LD_NOW    0x2  /* equivalent to RTLD_NOW on Unix */
 #define PR_LD_GLOBAL 0x4  /* equivalent to RTLD_GLOBAL on Unix */
 #define PR_LD_LOCAL  0x8  /* equivalent to RTLD_LOCAL on Unix */
-/*                 0x400     reserved for NSPR internal use */
+/*                0x8000     reserved for NSPR internal use */
 
 /*
 ** Load the specified library, in the manner specified by 'flags'.
 */
 
 NSPR_API(PRLibrary *)
 PR_LoadLibraryWithFlags(
     PRLibSpec libSpec,    /* the shared library */
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -156,19 +156,17 @@ struct _imcb *IAC$GL_IMAGE_LIST = NULL;
  * On these platforms, symbols have a leading '_'.
  */
 #if defined(SUNOS4) || defined(DARWIN) || defined(NEXTSTEP) \
     || defined(WIN16) || defined(XP_OS2) \
     || ((defined(OPENBSD) || defined(NETBSD)) && !defined(__ELF__))
 #define NEED_LEADING_UNDERSCORE
 #endif
 
-#ifdef WIN32
-#define PR_LD_PATHW  0x400  /* for PR_LibSpec_PathnameU */
-#endif
+#define PR_LD_PATHW 0x8000  /* for PR_LibSpec_PathnameU */
 
 /************************************************************************/
 
 struct PRLibrary {
     char*                       name;  /* Our own copy of the name string */
     PRLibrary*                  next;
     int                         refCount;
     const PRStaticLinkTable*    staticTable;
@@ -808,48 +806,50 @@ EmulateLoadLibraryW(LPCWSTR lpLibFileNam
 /*
 ** Dynamically load a library. Only load libraries once, so scan the load
 ** map first.
 */
 static PRLibrary*
 pr_LoadLibraryByPathname(const char *name, PRIntn flags)
 {
     PRLibrary *lm;
-    PRLibrary* result;
+    PRLibrary* result = NULL;
     PRInt32 oserr;
 #ifdef WIN32
     char utf8name_stack[MAX_PATH];
+    char *utf8name_malloc = NULL;
+    char *utf8name = utf8name_stack;
     PRUnichar wname_stack[MAX_PATH];
-    char *utf8name = utf8name_stack;
+    PRUnichar *wname_malloc = NULL;
     PRUnichar *wname = wname_stack;
     int len;
 #endif
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     /* See if library is already loaded */
     PR_EnterMonitor(pr_linker_lock);
 
 #ifdef WIN32
     if (flags & PR_LD_PATHW) {
         /* cast back what's cast to |char *| for the argument passing. */
         wname = (LPWSTR) name;
     } else {
         int wlen = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0);
         if (wlen > MAX_PATH)
-            wname = PR_Malloc(wlen);
+            wname = wname_malloc = PR_Malloc(wlen);
         if (wname == NULL ||
             !MultiByteToWideChar(CP_ACP, 0,  name, -1, wname, wlen)) {
             oserr = _MD_ERRNO();
             goto unlock;
         }
     }
     len = pr_ConvertUTF16toUTF8(wname, NULL, 0);
     if (len > MAX_PATH)
-        utf8name = PR_Malloc(len);
+        utf8name = utf8name_malloc = PR_Malloc(len);
     if (utf8name == NULL ||
         !pr_ConvertUTF16toUTF8(wname, utf8name, len)) {
         oserr = _MD_ERRNO();
         goto unlock;
     }
     /* the list of loaded library names are always kept in UTF-8 
      * on Win32 platforms */
     result = pr_UnlockedFindLibrary(utf8name);
@@ -1110,38 +1110,37 @@ pr_LoadLibraryByPathname(const char *nam
     PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Loaded library %s (load lib)", lm->name));
 
   unlock:
     if (result == NULL) {
         PR_SetError(PR_LOAD_LIBRARY_ERROR, oserr);
         DLLErrorInternal(oserr);  /* sets error text */
     }
 #ifdef WIN32
-    if (utf8name && utf8name != utf8name_stack) 
-        PR_Free(utf8name);
-    if (!(flags & PR_LD_PATHW) && wname && wname != wname_stack)
-        PR_Free(wname);
+    if (utf8name_malloc) 
+        PR_Free(utf8name_malloc);
+    if (wname_malloc)
+        PR_Free(wname_malloc);
 #endif
     PR_ExitMonitor(pr_linker_lock);
     return result;
 }
 
 #ifdef WIN32
 #ifdef WIN95
 /*
  * CP_UTF8 is not supported by WideCharToMultiByte on Windows 95 so that 
  * we have to emulate it
  */
 static PRStatus 
 pr_ConvertSingleCharToUTF8(PRUint32 usv, PRUint16 offset, int bufLen,
                            int *utf8Len, char * *buf)
 {
-    /* XXX No error checking. Add it for debug build */
     char* p = *buf;
-    /*if (!bufLen || !*buf) { */
+    PR_ASSERT(!bufLen || *buf);
     if (!bufLen) {
         *utf8Len += offset;
         return PR_SUCCESS;
     }
 
     if (*utf8Len + offset >= bufLen)
         return PR_FAILURE;
 
--- a/pr/src/md/windows/w95io.c
+++ b/pr/src/md/windows/w95io.c
@@ -1143,17 +1143,20 @@ static void InitUnicodeSupport(void)
 
     osvi.dwOSVersionInfoSize = sizeof(osvi);
     if (GetVersionExA(&osvi)) {
         _pr_useUnicode = (osvi.dwPlatformId >= VER_PLATFORM_WIN32_NT);
     } else {
         _pr_useUnicode = PR_FALSE;
     }
 #ifdef DEBUG
-    /* In debug builds, allow explicit use of ANSI methods for testing. */
+    /*
+     * In debug builds, allow explicit use of ANSI methods to simulate
+     * a Win9x environment for testing purposes.
+     */
     if (getenv("WINAPI_USE_ANSI"))
         _pr_useUnicode = PR_FALSE;
 #endif
 }
 
 #ifdef MOZ_UNICODE
 
 /* ================ UTF16 Interfaces ================================ */