You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/04/14 20:48:15 UTC
svn commit: r1092438 - in /commons/sandbox/runtime/trunk/src/main/native:
os/win32/arch_defs.h os/win32/arch_opts.h os/win32/dso.c os/win32/init.c
os/win32/os.c os/win32/platform.c os/win32/semaphore.c os/win32/time.c
os/win32/util.c shared/string.c
Author: mturk
Date: Thu Apr 14 18:48:14 2011
New Revision: 1092438
URL: http://svn.apache.org/viewvc?rev=1092438&view=rev
Log:
Implement win32 native methods
Added:
commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h
commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/platform.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/time.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c
commons/sandbox/runtime/trunk/src/main/native/shared/string.c
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h?rev=1092438&r1=1092437&r2=1092438&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h Thu Apr 14 18:48:14 2011
@@ -157,54 +157,4 @@ static __inline int isblank(int c)
#define WAIT_OBJECT_3 (WAIT_OBJECT_0 + 3)
#define WAIT_OBJECT_4 (WAIT_OBJECT_0 + 4)
-extern HANDLE acr_raised_event;
-extern volatile LONG acr_signal_waiters;
-
-static __inline DWORD AcrWaitForObjectOrSignal(HANDLE handle, DWORD dwTimeout)
-{
- DWORD rc;
- HANDLE wh[2];
-
- wh[0] = acr_raised_event;
- wh[1] = handle;
- InterlockedIncrement(&acr_signal_waiters);
- rc = WaitForMultipleObjectsEx(2, wh, FALSE, dwTimeout, TRUE);
- InterlockedDecrement(&acr_signal_waiters);
- if (rc < (WAIT_OBJECT_0 + 2))
- return rc;
- else if (rc == WAIT_IO_COMPLETION)
- return WAIT_OBJECT_0;
- else if (rc >= WAIT_ABANDONED_0 && rc < (WAIT_ABANDONED_0 + 2))
- return WAIT_OBJECT_0 + rc - WAIT_ABANDONED_0;
- else
- return rc;
-}
-
-static __inline DWORD AcrWaitForMultipleObjectsOrSignal(DWORD nCount,
- const HANDLE *handles,
- DWORD dwTimeout)
-{
- DWORD rc;
- DWORD wn;
- HANDLE wh[MAXIMUM_WAIT_OBJECTS];
-
- wh[0] = acr_raised_event;
- for (wn = 0; wn < nCount; wn++) {
- if (wn > (MAXIMUM_WAIT_OBJECTS - 2))
- break;
- wh[wn + 1] = handles[wn];
- }
- InterlockedIncrement(&acr_signal_waiters);
- rc = WaitForMultipleObjectsEx(nCount + 1, wh, FALSE, dwTimeout, TRUE);
- InterlockedDecrement(&acr_signal_waiters);
- if (rc < (WAIT_OBJECT_0 + MAXIMUM_WAIT_OBJECTS))
- return rc;
- else if (rc == WAIT_IO_COMPLETION)
- return WAIT_OBJECT_0;
- else if (rc >= WAIT_ABANDONED_0 && rc < (WAIT_ABANDONED_0 + nCount))
- return WAIT_OBJECT_0 + rc - WAIT_ABANDONED_0;
- else
- return rc;
-}
-
#endif /* _ACR_ARCH_DEFS_H_ */
Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h?rev=1092438&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h Thu Apr 14 18:48:14 2011
@@ -0,0 +1,206 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ACR_ARCH_OPTS_H_
+#define _ACR_ARCH_OPTS_H_
+
+
+typedef enum {
+ SYSDLL_KERNEL32 = 0, /* kernel32 From WinBase.h */
+ SYSDLL_NTDLL = 1, /* ntdll From our real kernel */
+ SYSDLL_USER32 = 2, /* user32 From WinUser.h */
+ SYSDLL_IPHLPAPI = 3, /* iphlpapi From Iphlpapi.h */
+ SYSDLL_MSWSOCK = 4, /* mswsock From WinSock.h */
+ SYSDLL_WS2_32 = 5, /* ws2_32 From WinSock2.h */
+ SYSDLL_SHELL32 = 6, /* shell32 From ShellAPI.h */
+ SYSDLL_ADVAPI32 = 7, /* advapi32 From WinBase.h */
+ SYSDLL_MSVCRT = 8, /* msvcrt */
+ SYSDLL_RICHED32 = 9, /* riched32 */
+ SYSDLL_MSHTML = 10, /* mshtml */
+ SYSDLL_JVM = 11, /* jvm From our own jvm.dll */
+ SYSDLL_KTMW32 = 12, /* ktmw32 From Ktmw32.h */
+
+ SYSDLL_DEFINED = 13 /* must define as last SYSDLL_ + 1 */
+} SYSDLL_TOKEN;
+
+HMODULE AcrGetLateDLL(SYSDLL_TOKEN libidx);
+FARPROC AcrGetLateDLLAddress(SYSDLL_TOKEN libidx, const char *name, int undec);
+int AcrLoadLateDLLs(void);
+
+#define ACR_DECLARE_LATE_DLL_FUNC1(lib, rettype, def, calltype, \
+ fn, ord, args, names) \
+ typedef rettype (calltype *_delayload_fpt_##fn) args; \
+ static _delayload_fpt_##fn _delayload_pfn_##fn = 0; \
+ static __inline int _delayload_ld_##fn() \
+ { if (_delayload_pfn_##fn != 0) return 1; \
+ if (_delayload_pfn_##fn == 0) \
+ _delayload_pfn_##fn = (_delayload_fpt_##fn) \
+ AcrGetLateDLLAddress(lib, #fn, ord); \
+ if (_delayload_pfn_##fn != 0) return 1; else return 0; } \
+ static __inline rettype _delayload_##fn args \
+ { if (_delayload_ld_##fn()) \
+ return (*(_delayload_pfn_##fn)) names; \
+ else { SetLastError(ERROR_INVALID_FUNCTION); return def;} \
+} //
+
+#define ACR_DECLARE_LATE_DLL_FUNC0(lib, calltype, \
+ fn, ord, args, names) \
+ typedef void (calltype *_delayload_fpt_##fn) args; \
+ static _delayload_fpt_##fn _delayload_pfn_##fn = 0; \
+ static __inline int _delayload_ld_##fn() \
+ { if (_delayload_pfn_##fn != 0) return 1; \
+ if (_delayload_pfn_##fn == 0) \
+ _delayload_pfn_##fn = (_delayload_fpt_##fn) \
+ AcrGetLateDLLAddress(lib, #fn, ord); \
+ if (_delayload_pfn_##fn != 0) return 1; else return 0; } \
+ static __inline void _delayload_##fn args \
+ { if (_delayload_ld_##fn()) \
+ (*(_delayload_pfn_##fn)) names; \
+ else { SetLastError(ERROR_INVALID_FUNCTION); } \
+} //
+
+#define ACR_DECL_LATE_DLL_FUNC(fn) _delayload_fpt_##fn _delayload_pfn_##fn
+#define ACR_HAVE_LATE_DLL_FUNC(fn) _delayload_ld_##fn()
+#define ACR_HAVE_LATE_DLL(lx) (AcrGetLateDLL(lx) != 0)
+
+#ifdef GetNamedPipeClientProcessId
+#undef GetNamedPipeClientProcessId
+#endif
+ACR_DECLARE_LATE_DLL_FUNC1(SYSDLL_KERNEL32, BOOL, FALSE,
+ WINAPI, GetNamedPipeClientProcessId, 0, (
+ IN HANDLE Pipe,
+ OUT PULONG ClientProcessId),
+ (Pipe, ClientProcessId));
+#define GetNamedPipeClientProcessId _delayload_GetNamedPipeClientProcessId
+
+#ifdef GetFinalPathNameByHandleW
+#undef GetFinalPathNameByHandleW
+#endif
+#if !defined(FILE_NAME_NORMALIZED)
+#define FILE_NAME_NORMALIZED 0
+#endif
+ACR_DECLARE_LATE_DLL_FUNC1(SYSDLL_KERNEL32, DWORD, 0,
+ WINAPI, GetFinalPathNameByHandleW, 0, (
+ IN HANDLE hFile,
+ OUT LPWSTR lpszFilePath,
+ IN DWORD cchFilePath,
+ IN DWORD dwFlags),
+ (hFile, lpszFilePath, cchFilePath, dwFlags));
+#define GetFinalPathNameByHandleW _delayload_GetFinalPathNameByHandleW
+
+#ifdef CreateSymbolicLinkW
+#undef CreateSymbolicLinkW
+#endif
+#ifndef SYMBOLIC_LINK_FLAG_DIRECTORY
+#define SYMBOLIC_LINK_FLAG_DIRECTORY 0x01
+#endif
+ACR_DECLARE_LATE_DLL_FUNC1(SYSDLL_KERNEL32, BOOL, FALSE,
+ WINAPI, CreateSymbolicLinkW, 0, (
+ IN LPCWSTR lpSymlinkFileName,
+ IN LPCWSTR lpTargetFileName,
+ IN DWORD dwFlags),
+ (lpSymlinkFileName, lpTargetFileName, dwFlags));
+#define CreateSymbolicLinkW _delayload_CreateSymbolicLinkW
+
+
+extern HANDLE acr_raised_event;
+extern volatile LONG acr_signal_waiters;
+
+static __inline DWORD AcrWaitForObjectOrSignal(HANDLE handle, DWORD dwTimeout)
+{
+ DWORD rc;
+ HANDLE wh[2];
+
+ wh[0] = acr_raised_event;
+ wh[1] = handle;
+ InterlockedIncrement(&acr_signal_waiters);
+ rc = WaitForMultipleObjectsEx(2, wh, FALSE, dwTimeout, TRUE);
+ InterlockedDecrement(&acr_signal_waiters);
+ if (rc < (WAIT_OBJECT_0 + 2))
+ return rc;
+ else if (rc == WAIT_IO_COMPLETION)
+ return WAIT_OBJECT_0;
+ else if (rc >= WAIT_ABANDONED_0 && rc < (WAIT_ABANDONED_0 + 2))
+ return WAIT_OBJECT_0 + rc - WAIT_ABANDONED_0;
+ else
+ return rc;
+}
+
+static __inline DWORD AcrWaitForMultipleObjectsOrSignal(DWORD nCount,
+ const HANDLE *handles,
+ DWORD dwTimeout)
+{
+ DWORD rc;
+ DWORD wn;
+ HANDLE wh[MAXIMUM_WAIT_OBJECTS];
+
+ wh[0] = acr_raised_event;
+ for (wn = 0; wn < nCount; wn++) {
+ if (wn > (MAXIMUM_WAIT_OBJECTS - 2))
+ break;
+ wh[wn + 1] = handles[wn];
+ }
+ InterlockedIncrement(&acr_signal_waiters);
+ rc = WaitForMultipleObjectsEx(nCount + 1, wh, FALSE, dwTimeout, TRUE);
+ InterlockedDecrement(&acr_signal_waiters);
+ if (rc < (WAIT_OBJECT_0 + MAXIMUM_WAIT_OBJECTS))
+ return rc;
+ else if (rc == WAIT_IO_COMPLETION)
+ return WAIT_OBJECT_0;
+ else if (rc >= WAIT_ABANDONED_0 && rc < (WAIT_ABANDONED_0 + nCount))
+ return WAIT_OBJECT_0 + rc - WAIT_ABANDONED_0;
+ else
+ return rc;
+}
+
+static __inline acr_time_t FileTimeToUsecTime(LPFILETIME input)
+{
+ acr_time_t result;
+ /* Convert FILETIME one 64 bit number so we can work with it. */
+ result = ((LARGE_INTEGER *)input)->QuadPart;
+ /* Convert from 100 nano-sec periods to micro-seconds. */
+ result /= 10;
+ /* Convert from Windows epoch to Unix epoch */
+ result -= ACR_DELTA_EPOCH_IN_USEC;
+ return result;
+}
+
+static __inline acr_time_t FileTimeToMsecTime(LPFILETIME input)
+{
+ acr_time_t result;
+ /* Convert FILETIME one 64 bit number so we can work with it. */
+ result = ((LARGE_INTEGER *)input)->QuadPart;
+ /* Convert from 100 nano-sec periods to micro-seconds. */
+ result /= 10000LL;
+ /* Convert from Windows epoch to Unix epoch */
+ result -= ACR_DELTA_EPOCH_IN_USEC;
+ return result;
+}
+
+
+static __inline void UsecTimeToFileTime(LPFILETIME result, acr_time_t t)
+{
+ ((LARGE_INTEGER *)result)->QuadPart = (t + ACR_DELTA_EPOCH_IN_USEC) * 10;
+ return;
+}
+
+static __inline void MsecTimeToFileTime(LPFILETIME result, acr_time_t t)
+{
+ ((LARGE_INTEGER *)result)->QuadPart = (t + ACR_DELTA_EPOCH_IN_USEC) * 10000;
+ return;
+}
+
+#endif /* _ACR_ARCH_OPTS_H_ */
Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c?rev=1092438&r1=1092437&r2=1092438&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c Thu Apr 14 18:48:14 2011
@@ -18,5 +18,49 @@
#include "acr/error.h"
#include "acr/port.h"
#include "acr/dso.h"
-#include "arch_defs.h"
+#include "arch_opts.h"
+
+acr_dso_t
+AcrDsoLoad(const wchar_t *name)
+{
+ HINSTANCE handle = 0;
+ UINT em;
+
+ /* Do not display message box */
+ em = SetErrorMode(SEM_FAILCRITICALERRORS);
+
+ handle = LoadLibraryExW(name, NULL, 0);
+ if (IS_INVALID_HANDLE(handle))
+ handle = LoadLibraryExW(name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
+ if (IS_INVALID_HANDLE(handle)) {
+ if (GetFileAttributesW(name) != INVALID_FILE_ATTRIBUTES) {
+ wchar_t *fp;
+ wchar_t *wname = wcsdup(name);
+ /* Try with alternate search path */
+ fp = wcsrchr(wname, L'\\');
+ if (fp != 0) {
+ *fp = L'\0';
+ SetDllDirectoryW(wname);
+ *fp = L'\\';
+ handle = LoadLibraryExW(wname, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
+ if (IS_INVALID_HANDLE(handle))
+ SetDllDirectoryW(0); /* Restore default order */
+ }
+ free(wname);
+ }
+ }
+ /* Restore original error mode */
+ SetErrorMode(em);
+ return handle;
+}
+
+void *
+AcrGetProcAddress(acr_dso_t dso, const char *name)
+{
+ if (dso == 0) {
+ ACR_SET_OS_ERROR(ACR_EINIT);
+ return 0;
+ }
+ return GetProcAddress(dso, name);
+}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c?rev=1092438&r1=1092437&r2=1092438&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c Thu Apr 14 18:48:14 2011
@@ -20,7 +20,7 @@
#include "acr/port.h"
#include "acr/clazz.h"
#include "acr/misc.h"
-#include "arch_defs.h"
+#include "arch_opts.h"
static JavaVM *_java_vm = 0;
static CRITICAL_SECTION _lib_mutex;
@@ -150,7 +150,8 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
acr_raised_event = CreateEvent(0, TRUE, FALSE, 0);
if (IS_INVALID_HANDLE(acr_raised_event))
return JNI_ERR;
-
+ if (AcrLoadLateDLLs() != 0)
+ return JNI_ERR;
if ((env = AcrGetJNIEnv()) == 0)
return JNI_ERR;
if (AcrInitCoreClasses(env) != 0)
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c?rev=1092438&r1=1092437&r2=1092438&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c Thu Apr 14 18:48:14 2011
@@ -16,6 +16,7 @@
#include "acr/jniapi.h"
#include "acr/string.h"
+#include "arch_opts.h"
static const char _unknown[] = "unknown";
extern LPSYSTEM_INFO acr_osinf;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/platform.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/platform.c?rev=1092438&r1=1092437&r2=1092438&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/platform.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/platform.c Thu Apr 14 18:48:14 2011
@@ -16,6 +16,7 @@
#include "acr/string.h"
#include "acr/port.h"
+#include "arch_opts.h"
extern int acr_native_codepage;
extern LPOSVERSIONINFOEXA acr_osver;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c?rev=1092438&r1=1092437&r2=1092438&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c Thu Apr 14 18:48:14 2011
@@ -17,7 +17,7 @@
#include "acr/string.h"
#include "acr/clazz.h"
#include "acr/port.h"
-#include "arch_defs.h"
+#include "arch_opts.h"
J_DECLARE_CLAZZ = {
INVALID_FIELD_OFFSET,
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/time.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/time.c?rev=1092438&r1=1092437&r2=1092438&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/time.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/time.c Thu Apr 14 18:48:14 2011
@@ -15,4 +15,58 @@
*/
#include "acr/time.h"
+#include "arch_opts.h"
+acr_time_t
+AcrTimeNow()
+{
+ FILETIME time;
+
+ GetSystemTimeAsFileTime(&time);
+ return FileTimeToUsecTime(&time);
+}
+
+acr_time_t
+AcrTimeMilliseconds()
+{
+ FILETIME time;
+
+ GetSystemTimeAsFileTime(&time);
+ return FileTimeToMsecTime(&time);
+}
+
+acr_time_t
+AcrDOSTimeToTime(acr_uint32_t t)
+{
+ FILETIME ft;
+ WORD dd = (WORD)(t >> 16);
+ WORD dt = (WORD)(t & 0xFFFF);
+
+ if (DosDateTimeToFileTime(dd, dt, &ft)) {
+ return FileTimeToUsecTime(&ft);
+ }
+ else {
+ /* January 1st 1980 as unix time in microseconds */
+ return ACR_I64_C(315532800000000);
+ }
+}
+
+acr_uint32_t
+AcrTimeToDOSTime(acr_time_t t)
+{
+ FILETIME ft;
+ WORD dd;
+ WORD dt;
+
+ /* Round up to two seconds */
+ t = ACR_ALIGN((t / ACR_USEC_PER_SEC), 2) * ACR_USEC_PER_SEC;
+ UsecTimeToFileTime(&ft, t);
+ if (FileTimeToDosDateTime(&ft, &dd, &dt))
+ return ((acr_uint32_t)dd << 16) | (acr_uint32_t)dt;
+ else {
+ if (t > ACR_I64_C(4354819198000000))
+ return 0xFF9FBF7D;
+ else
+ return 0x00210000;
+ }
+}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c?rev=1092438&r1=1092437&r2=1092438&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c Thu Apr 14 18:48:14 2011
@@ -17,3 +17,104 @@
#include "acr/error.h"
#include "acr/memory.h"
#include "acr/port.h"
+#include "arch_opts.h"
+
+/* This is the helper code to resolve late bound entry points
+ * missing from one or more releases of the Win32 API
+ */
+static const char* const _opt_libname[SYSDLL_DEFINED] = {
+ "kernel32.dll",
+ "ntdll.dll",
+ "user32.dll",
+ "iphlpapi.dll",
+ "mswsock.dll",
+ "ws2_32.dll",
+ "shell32.dll",
+ "advapi32.dll",
+ "msvcrt.dll",
+ "riched32.dll",
+ "mshtml.dll",
+ "jvm.dll",
+ "ktmw32.dll"
+};
+
+static HMODULE _opt_libinst[SYSDLL_DEFINED] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+HMODULE
+AcrGetLateDLL(SYSDLL_TOKEN libidx)
+{
+ int rc = 0;
+
+ if (_opt_libinst[libidx] == 0) {
+ /* First see if the .dll is already loaded in the process */
+ _opt_libinst[libidx] = GetModuleHandleA(_opt_libname[libidx]);
+ if (_opt_libinst[libidx] == 0) {
+ /* Do not display error messages when loading library */
+ UINT em = SetErrorMode(SEM_FAILCRITICALERRORS);
+ _opt_libinst[libidx] = LoadLibraryA(_opt_libname[libidx]);
+ rc = GetLastError();
+ SetErrorMode(em);
+ }
+ }
+ if (_opt_libinst[libidx] == 0)
+ SetLastError(rc);
+ return _opt_libinst[libidx];
+}
+
+FARPROC
+ AcrGetLateDLLAddress(SYSDLL_TOKEN libidx, const char *name, int undec)
+{
+ int rc = 0;
+ FARPROC fp = 0;
+
+ if (_opt_libinst[libidx] == 0) {
+ /* First see if the .dll is already loaded in the process */
+ _opt_libinst[libidx] = GetModuleHandleA(_opt_libname[libidx]);
+ if (_opt_libinst[libidx] == 0) {
+ /* Do not display error messages when loading library */
+ UINT em = SetErrorMode(SEM_FAILCRITICALERRORS);
+ _opt_libinst[libidx] = LoadLibraryA(_opt_libname[libidx]);
+ rc = GetLastError();
+ SetErrorMode(em);
+ }
+ if (_opt_libinst[libidx] == 0) {
+ SetLastError(rc);
+ return 0;
+ }
+ }
+ if (undec) {
+ char name[256];
+ snprintf(name, sizeof(name), "_%s@%d", name, undec);
+ fp = GetProcAddress(_opt_libinst[libidx], name);
+ if (fp == 0) {
+ /* Try with double stack size
+ */
+ snprintf(name, sizeof(name), "_%s@%d", name, undec * 2);
+ fp = GetProcAddress(_opt_libinst[libidx], name);
+ }
+ }
+ if (fp == 0) {
+ /* Try function name if ordinal failed */
+ fp = GetProcAddress(_opt_libinst[libidx], name);
+ }
+ return fp;
+}
+
+int
+AcrLoadLateDLLs()
+{
+ SYSDLL_TOKEN idx = SYSDLL_KERNEL32;
+
+ for (idx = SYSDLL_KERNEL32; idx < SYSDLL_DEFINED; idx++) {
+ if (AcrGetLateDLL(idx) == 0 && (idx < SYSDLL_JVM)) {
+ /* Unable to load required library
+ * Make sure all optional libs are defined after
+ * SYSDLL_JVM (see win32/arch_dlld.h)
+ */
+ return GetLastError();
+ }
+ }
+ return 0;
+}
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=1092438&r1=1092437&r2=1092438&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Thu Apr 14 18:48:14 2011
@@ -837,7 +837,7 @@ static jstring new_string_iso_8859_1(JNI
else {
jchar *cc;
if ((cc = ACR_MALLOC(jchar, sl + 1)) != 0) {
- size_t i;
+ jsize i;
for (i = 0; i < sl; i++) {
cc[i] = s[i];
}
@@ -867,7 +867,7 @@ static jstring new_string_cp_1252(JNIEnv
else {
jchar *cc;
if ((cc = ACR_MALLOC(jchar, sl + 1)) != 0) {
- size_t i;
+ jsize i;
for (i = 0; i < sl; i++) {
cc[i] = _cp_1252[(unsigned char)s[i]];
}