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 2009/04/13 09:42:52 UTC
svn commit: r764366 [2/2] - in /commons/sandbox/runtime/trunk/src:
main/java/org/apache/commons/runtime/ main/native/ main/native/include/
main/native/include/arch/ main/native/include/arch/darwin/
main/native/include/arch/hpux/ main/native/include/arc...
Added: commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h?rev=764366&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h Mon Apr 13 07:42:50 2009
@@ -0,0 +1,41 @@
+/* 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_PRIVATE_H
+#define _ACR_ARCH_PRIVATE_H
+
+#include "acr_arch_private.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file acr_arch_private.h
+ * @brief
+ *
+ * ACR HP-UX platform private macros and defines
+ *
+ */
+#define ACR_ARCHIMPL_CLASS_PATH ACR_CLASS_PATH "platform/hpux/"
+#define ACR_JNI_ARCHIMPL_DECLARE(RT, CL, FN) \
+ JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_platform_hpux_##CL##_##FN
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ACR_ARCH_PRIVATE_H */
Propchange: commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h?rev=764366&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h Mon Apr 13 07:42:50 2009
@@ -0,0 +1,42 @@
+/* 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_PRIVATE_H
+#define _ACR_ARCH_PRIVATE_H
+
+#include "acr_arch_private.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file acr_arch_private.h
+ * @brief
+ *
+ * ACR Linux platform private macros and defines
+ *
+ */
+
+#define ACR_ARCHIMPL_CLASS_PATH ACR_CLASS_PATH "platform/linux/"
+#define ACR_JNI_ARCHIMPL_DECLARE(RT, CL, FN) \
+ JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_platform_unix_##CL##_##FN
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ACR_ARCH_PRIVATE_H */
Propchange: commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h?rev=764366&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h Mon Apr 13 07:42:50 2009
@@ -0,0 +1,41 @@
+/* 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_PRIVATE_H
+#define _ACR_ARCH_PRIVATE_H
+
+#include "acr_arch_private.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file acr_arch_private.h
+ * @brief
+ *
+ * ACR SunOS platform private macros and defines
+ *
+ */
+#define ACR_ARCHIMPL_CLASS_PATH ACR_CLASS_PATH "platform/solaris/"
+#define ACR_JNI_ARCHIMPL_DECLARE(RT, CL, FN) \
+ JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_platform_solaris_##CL##_##FN
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ACR_ARCH_PRIVATE_H */
Propchange: commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h?rev=764366&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h Mon Apr 13 07:42:50 2009
@@ -0,0 +1,34 @@
+/* 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_H
+#define _ACR_ARCH_H
+
+#include "acr_arch_private.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define ACR_PLATFORM_CLASS_PATH ACR_CLASS_PATH "platform/unix/"
+#define ACR_JNI_PLATFORM_DECLARE(RT, CL, FN) \
+ JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_platform_unix_##CL##_##FN
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ACR_ARCH_H */
Propchange: commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h?rev=764366&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h Mon Apr 13 07:42:50 2009
@@ -0,0 +1,380 @@
+/* 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_H
+#define _ACR_ARCH_H
+
+#include "acr_arch_private.h"
+
+#if defined (NTDDI_VISTA)
+#ifndef NTDDI_LONGHORN
+#define NTDDI_LONGHORN
+#endif
+#endif
+
+#if !defined(NTDDI_VISTA) && !defined(NTDDI_LONGHORN)
+/* Vista Platform SDK definitions */
+
+typedef enum
+_TCP_TABLE_CLASS {
+ TCP_TABLE_BASIC_LISTENER,
+ TCP_TABLE_BASIC_CONNECTIONS,
+ TCP_TABLE_BASIC_ALL,
+ TCP_TABLE_OWNER_PID_LISTENER,
+ TCP_TABLE_OWNER_PID_CONNECTIONS,
+ TCP_TABLE_OWNER_PID_ALL,
+ TCP_TABLE_OWNER_MODULE_LISTENER,
+ TCP_TABLE_OWNER_MODULE_CONNECTIONS,
+ TCP_TABLE_OWNER_MODULE_ALL
+} TCP_TABLE_CLASS, *PTCP_TABLE_CLASS;
+
+typedef enum
+_UDP_TABLE_CLASS {
+ UDP_TABLE_BASIC,
+ UDP_TABLE_OWNER_PID,
+ UDP_TABLE_OWNER_MODULE
+} UDP_TABLE_CLASS, *PUDP_TABLE_CLASS;
+
+#endif /* PRODUCT_UNDEFINED */
+
+/* Copied from http://source.winehq.org/source/include/winternl.h */
+
+typedef struct _CURDIR
+{
+ UNICODE_STRING DosPath;
+ PVOID Handle;
+} CURDIR, *PCURDIR;
+
+typedef struct RTL_DRIVE_LETTER_CURDIR
+{
+ USHORT Flags;
+ USHORT Length;
+ ULONG TimeStamp;
+ UNICODE_STRING DosPath;
+} RTL_DRIVE_LETTER_CURDIR, *PRTL_DRIVE_LETTER_CURDIR;
+
+typedef struct tagRTL_BITMAP {
+ ULONG SizeOfBitMap; /* Number of bits in the bitmap */
+ PULONG Buffer; /* Bitmap data, assumed sized to a DWORD boundary */
+} RTL_BITMAP, *PRTL_BITMAP;
+
+typedef struct _RTL_USER_PROCESS_PARAMETERS
+{
+ ULONG AllocationSize;
+ ULONG Size;
+ ULONG Flags;
+ ULONG DebugFlags;
+ HANDLE ConsoleHandle;
+ ULONG ConsoleFlags;
+ HANDLE hStdInput;
+ HANDLE hStdOutput;
+ HANDLE hStdError;
+ CURDIR CurrentDirectory;
+ UNICODE_STRING DllPath;
+ UNICODE_STRING ImagePathName;
+ UNICODE_STRING CommandLine;
+ PWSTR Environment;
+ ULONG dwX;
+ ULONG dwY;
+ ULONG dwXSize;
+ ULONG dwYSize;
+ ULONG dwXCountChars;
+ ULONG dwYCountChars;
+ ULONG dwFillAttribute;
+ ULONG dwFlags;
+ ULONG wShowWindow;
+ UNICODE_STRING WindowTitle;
+ UNICODE_STRING Desktop;
+ UNICODE_STRING ShellInfo;
+ UNICODE_STRING RuntimeInfo;
+ RTL_DRIVE_LETTER_CURDIR DLCurrentDirectory[0x20];
+} RTL_USER_PROCESS_PARAMETERS, *PRTL_USER_PROCESS_PARAMETERS;
+
+typedef struct _PEB_LDR_DATA
+{
+ ULONG Length;
+ BOOLEAN Initialized;
+ PVOID SsHandle;
+ LIST_ENTRY InLoadOrderModuleList;
+ LIST_ENTRY InMemoryOrderModuleList;
+ LIST_ENTRY InInitializationOrderModuleList;
+} PEB_LDR_DATA, *PPEB_LDR_DATA;
+
+/***********************************************************************
+ * PEB data structure (472 bytes)
+ */
+typedef struct _ACR_PEB
+{
+ BOOLEAN InheritedAddressSpace; /* 00 */
+ BOOLEAN ReadImageFileExecOptions; /* 01 */
+ BOOLEAN BeingDebugged; /* 02 */
+ BOOLEAN SpareBool; /* 03 */
+ HANDLE Mutant; /* 04 */
+ HMODULE ImageBaseAddress; /* 08 */
+ PPEB_LDR_DATA LdrData; /* 0c */
+ RTL_USER_PROCESS_PARAMETERS *ProcessParameters; /* 10 */
+ PVOID SubSystemData; /* 14 */
+ HANDLE ProcessHeap; /* 18 */
+ PRTL_CRITICAL_SECTION FastPebLock; /* 1c */
+ PVOID /*PPEBLOCKROUTINE*/ FastPebLockRoutine; /* 20 */
+ PVOID /*PPEBLOCKROUTINE*/ FastPebUnlockRoutine; /* 24 */
+ ULONG EnvironmentUpdateCount; /* 28 */
+ PVOID KernelCallbackTable; /* 2c */
+ PVOID EventLogSection; /* 30 */
+ PVOID EventLog; /* 34 */
+ PVOID /*PPEB_FREE_BLOCK*/ FreeList; /* 38 */
+ ULONG TlsExpansionCounter; /* 3c */
+ PRTL_BITMAP TlsBitmap; /* 40 */
+ ULONG TlsBitmapBits[2]; /* 44 */
+ PVOID ReadOnlySharedMemoryBase; /* 4c */
+ PVOID ReadOnlySharedMemoryHeap; /* 50 */
+ PVOID *ReadOnlyStaticServerData; /* 54 */
+ PVOID AnsiCodePageData; /* 58 */
+ PVOID OemCodePageData; /* 5c */
+ PVOID UnicodeCaseTableData; /* 60 */
+ ULONG NumberOfProcessors; /* 64 */
+ ULONG NtGlobalFlag; /* 68 */
+ BYTE Spare2[4]; /* 6c */
+ LARGE_INTEGER CriticalSectionTimeout; /* 70 */
+ ULONG HeapSegmentReserve; /* 78 */
+ ULONG HeapSegmentCommit; /* 7c */
+ ULONG HeapDeCommitTotalFreeThreshold; /* 80 */
+ ULONG HeapDeCommitFreeBlockThreshold; /* 84 */
+ ULONG NumberOfHeaps; /* 88 */
+ ULONG MaximumNumberOfHeaps; /* 8c */
+ PVOID *ProcessHeaps; /* 90 */
+ PVOID GdiSharedHandleTable; /* 94 */
+ PVOID ProcessStarterHelper; /* 98 */
+ PVOID GdiDCAttributeList; /* 9c */
+ PVOID LoaderLock; /* a0 */
+ ULONG OSMajorVersion; /* a4 */
+ ULONG OSMinorVersion; /* a8 */
+ ULONG OSBuildNumber; /* ac */
+ ULONG OSPlatformId; /* b0 */
+ ULONG ImageSubSystem; /* b4 */
+ ULONG ImageSubSystemMajorVersion; /* b8 */
+ ULONG ImageSubSystemMinorVersion; /* bc */
+ ULONG ImageProcessAffinityMask; /* c0 */
+ ULONG GdiHandleBuffer[34]; /* c4 */
+ ULONG PostProcessInitRoutine; /* 14c */
+ PRTL_BITMAP TlsExpansionBitmap; /* 150 */
+ ULONG TlsExpansionBitmapBits[32]; /* 154 */
+ ULONG SessionId; /* 1d4 */
+} ACR_PEB, *PACR_PEB;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define LOG_MSG_DOMAIN "ApacheCommonsRuntime"
+
+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_JVM = 8, /* jvm From our own jvm.dll */
+
+ SYSDLL_defined = 9 /* must define as last idx_ + 1 */
+} acr_dlltoken_e;
+
+extern LPSYSTEM_INFO acr_osinf;
+extern LPOSVERSIONINFOEXA acr_osver;
+extern UINT64 acr_vmem;
+
+/* Define ACR_WANT_LATE_DLL before including this file */
+#ifdef ACR_WANT_LATE_DLL
+
+FARPROC acr_load_dll_func(acr_dlltoken_e, const char *, int);
+
+/* The acr_load_dll_func call WILL return def if the function cannot be loaded */
+
+#define ACR_DECLARE_LATE_DLL_FUNC(lib, rettype, def, calltype, \
+ fn, ord, args, names) \
+ typedef rettype (calltype *acr_winapi_fpt_##fn) args; \
+ static acr_winapi_fpt_##fn acr_winapi_pfn_##fn = NULL; \
+ static int acr_winapi_chk_##fn = 0; \
+ static __inline int acr_winapi_ld_##fn() \
+ { if (acr_winapi_pfn_##fn) return 1; \
+ if (acr_winapi_chk_##fn ++) return 0; \
+ if (!acr_winapi_pfn_##fn) \
+ acr_winapi_pfn_##fn = (acr_winapi_fpt_##fn) \
+ acr_load_dll_func(lib, #fn, ord); \
+ if (acr_winapi_pfn_##fn) return 1; else return 0; }; \
+ static __inline rettype acr_winapi_##fn args \
+ { if (acr_winapi_ld_##fn()) \
+ return (*(acr_winapi_pfn_##fn)) names; \
+ else { SetLastError(ERROR_INVALID_FUNCTION); return def;} \
+ } //
+
+#define ACR_DECLARE_LATE_DLL_VOID(lib, calltype, \
+ fn, ord, args, names) \
+ typedef void (calltype *acr_winapi_fpt_##fn) args; \
+ static acr_winapi_fpt_##fn acr_winapi_pfn_##fn = NULL; \
+ static int acr_winapi_chk_##fn = 0; \
+ static __inline int acr_winapi_ld_##fn() \
+ { if (acr_winapi_pfn_##fn) return 1; \
+ if (acr_winapi_chk_##fn ++) return 0; \
+ if (!acr_winapi_pfn_##fn) \
+ acr_winapi_pfn_##fn = (acr_winapi_fpt_##fn) \
+ acr_load_dll_func(lib, #fn, ord); \
+ if (acr_winapi_pfn_##fn) return 1; else return 0; }; \
+ static __inline void acr_winapi_##fn args \
+ { if (acr_winapi_ld_##fn()) \
+ (*(acr_winapi_pfn_##fn)) names; \
+ else { SetLastError(ERROR_INVALID_FUNCTION); } \
+ } //
+
+#define ACR_HAVE_LATE_DLL_FUNC(fn) acr_winapi_ld_##fn()
+
+ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_KERNEL32, BOOL, FALSE,
+ WINAPI, GetSystemTimes, 0, (
+ OUT LPFILETIME lpIdleTime,
+ OUT LPFILETIME lpKernelTime,
+ OUT LPFILETIME lpUserTime),
+ (lpIdleTime, lpKernelTime, lpUserTime));
+#undef GetSystemTimes
+#define GetSystemTimes acr_winapi_GetSystemTimes
+
+ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_KERNEL32, BOOL, FALSE,
+ WINAPI, IsWow64Process, 0, (
+ IN HANDLE hProcess,
+ OUT PBOOL Wow64Process),
+ (hProcess, Wow64Process));
+#undef IsWow64Process
+#define IsWow64Process acr_winapi_IsWow64Process
+
+ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_NTDLL, NTSTATUS, 1,
+ WINAPI, NtQuerySystemInformation, 0, (
+ IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
+ OUT PVOID SystemInformation,
+ IN ULONG SystemInformationLength,
+ OUT PULONG ReturnLength),
+ (SystemInformationClass, SystemInformation, SystemInformationLength, ReturnLength));
+#undef NtQuerySystemInformation
+#define NtQuerySystemInformation acr_winapi_NtQuerySystemInformation
+
+ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_NTDLL, NTSTATUS, 1,
+ WINAPI, NtQueryInformationProcess, 0, (
+ IN HANDLE ProcessHandle,
+ IN PROCESSINFOCLASS ProcessInformationClass,
+ OUT PVOID ProcessInformation,
+ IN ULONG ProcessInformationLength,
+ OUT PULONG ReturnLength),
+ (ProcessHandle, ProcessInformationClass, ProcessInformation, ProcessInformationLength, ReturnLength));
+#undef NtQueryInformationProcess
+#define NtQueryInformationProcess acr_winapi_NtQueryInformationProcess
+
+ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_KERNEL32, BOOL, FALSE,
+ WINAPI, GetPerformanceInfo, 0, (
+ PPERFORMACE_INFORMATION pPerformanceInformation,
+ DWORD cb),
+ (pPerformanceInformation, cb));
+#undef GetPerformanceInfo
+#define GetPerformanceInfo acr_winapi_GetPerformanceInfo
+
+ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_IPHLPAPI, DWORD, ERROR_INVALID_FUNCTION,
+ WINAPI, GetExtendedTcpTable, 0, (
+ PVOID pTcpTable,
+ PDWORD pdwSize,
+ BOOL bOrder,
+ ULONG ulAf,
+ TCP_TABLE_CLASS TableClass,
+ ULONG Reserved),
+ (pTcpTable, pdwSize, bOrder, ulAf, TableClass, Reserved));
+#undef GetExtendedTcpTable
+#define GetExtendedTcpTable acr_winapi_GetExtendedTcpTable
+
+ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_IPHLPAPI, DWORD, ERROR_INVALID_FUNCTION,
+ WINAPI, GetExtendedUdpTable, 0, (
+ PVOID pUdpTable,
+ PDWORD pdwSize,
+ BOOL bOrder,
+ ULONG ulAf,
+ UDP_TABLE_CLASS TableClass,
+ ULONG Reserved),
+ (pUdpTable, pdwSize, bOrder, ulAf, TableClass, Reserved));
+#undef GetExtendedUdpTable
+#define GetExtendedUdpTable acr_winapi_GetExtendedUdpTable
+
+#if !defined(POLLERR)
+/* Event flag definitions for WSAPoll(). */
+#define POLLRDNORM 0x0100
+#define POLLRDBAND 0x0200
+#define POLLIN (POLLRDNORM | POLLRDBAND)
+#define POLLPRI 0x0400
+
+#define POLLWRNORM 0x0010
+#define POLLOUT (POLLWRNORM)
+#define POLLWRBAND 0x0020
+
+#define POLLERR 0x0001
+#define POLLHUP 0x0002
+#define POLLNVAL 0x0004
+
+typedef struct pollfd {
+ SOCKET fd;
+ SHORT events;
+ SHORT revents;
+
+} WSAPOLLFD, *PWSAPOLLFD, FAR *LPWSAPOLLFD;
+
+#endif /* !defined(POLLERR) */
+#ifdef WSAPoll
+#undef WSAPoll
+#endif
+ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_WS2_32, int, -1,
+ WSAAPI, WSAPoll, 0, (
+ IN OUT LPWSAPOLLFD fdArray,
+ IN ULONG fds,
+ IN INT timeout),
+ (fdArray, fds, timeout));
+#define WSAPoll acr_winapi_WSAPoll
+
+#ifdef SetDllDirectoryW
+#undef SetDllDirectoryW
+#endif
+ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_KERNEL32, BOOL, FALSE,
+ WINAPI, SetDllDirectoryW, 0, (
+ IN LPCWSTR lpPathName),
+ (lpPathName));
+#define SetDllDirectoryW acr_winapi_SetDllDirectoryW
+
+ACR_DECLARE_LATE_DLL_VOID(SYSDLL_JVM, JNICALL,
+ JVM_DumpAllStacks,
+ 8, (
+ JNIEnv *lpEnv,
+ jclass jClazz),
+ (lpEnv, jClazz));
+#undef JVM_DumpAllStacks
+#define JVM_DumpAllStacks acr_winapi_JVM_DumpAllStacks
+
+#undef ACR_WANT_LATE_DLL
+#endif /* ACR_WANT_LATE_DLL */
+
+#define IS_INVALID_HANDLE(h) (((h) == NULL || (h) == INVALID_HANDLE_VALUE))
+#define ACR_REGS_CPU "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\"
+#define ACR_REGS_CPU0 ACR_REGS_CPU "0\\"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ACR_ARCH_H */
Added: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h?rev=764366&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h Mon Apr 13 07:42:50 2009
@@ -0,0 +1,47 @@
+/* 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_PRIVATE_H
+#define _ACR_ARCH_PRIVATE_H
+
+#include "acr_arch_private.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file acr_arch_private.h
+ * @brief
+ *
+ * ACR Windows platform private macros and defines
+ *
+ */
+#define ACR_ARCHIMPL_CLASS_PATH ACR_CLASS_PATH "platform/windows/"
+#define ACR_PLATFORM_CLASS_PATH ACR_CLASS_PATH "platform/windows/"
+
+#define ACR_JNI_ARCHIMPL_DECLARE(RT, CL, FN) \
+ JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_platform_windows_##CL##_##FN
+#define ACR_JNI_PLATFORM_DECLARE(RT, CL, FN) \
+ JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_platform_windows_##CL##_##FN
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ACR_ARCH_PRIVATE_H */
Propchange: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c?rev=764366&r1=764365&r2=764366&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c Mon Apr 13 07:42:50 2009
@@ -16,6 +16,7 @@
#include "acr.h"
#include "acr_private.h"
+#include "acr_arch.h"
#include <sys/utsname.h>
#define MAXSIZESYSSTRING 256
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c?rev=764366&r1=764365&r2=764366&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c Mon Apr 13 07:42:50 2009
@@ -21,12 +21,12 @@
#include "acr_arch.h"
/**
- * Posix main
+ * Windows main
*
*/
static HINSTANCE dll_instance = NULL;
-static WCHAR dll_file_name[ACR_HBUFFER_SIZ];
+static WCHAR dll_file_name[ACR_HBUFF_SIZ];
static DWORD dll_tls_index = TLS_OUT_OF_INDEXES;
static SYSTEM_INFO osinf;
@@ -51,7 +51,7 @@
*/
case DLL_PROCESS_ATTACH:
dll_instance = instance;
- GetModuleFileNameW(instance, dll_file_name, ACR_HBUFFER_LEN);
+ GetModuleFileNameW(instance, dll_file_name, ACR_HBUFF_LEN);
break;
/** The attached process creates a new thread.
*/
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/main.rc
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/main.rc?rev=764366&r1=764365&r2=764366&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/main.rc (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/main.rc Mon Apr 13 07:42:50 2009
@@ -16,6 +16,7 @@
*/
#include <windows.h>
+#include "acr_version.h"
LANGUAGE 0x9,0x1
1 11 logmessages.bin
@@ -42,9 +43,6 @@
#define STR_TRADEMARK " Apache Software Foundation"
#define STR_PRODUCT "Apache Commons Runtime"
-#define STR_VERISON "1.0.0.0"
-#define CSV_VERISON 1,0,0,0
-
#define PRIVATE_BUILD 1
#define PRERELEASE_BUILD 1
@@ -72,8 +70,8 @@
IDI_MAINICON ICON "apache.ico"
1 VERSIONINFO
- FILEVERSION CSV_VERISON
- PRODUCTVERSION CSV_VERISON
+ FILEVERSION ACR_VERSION_STRING_CSV
+ PRODUCTVERSION ACR_VERSION_STRING_CSV
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
FILEFLAGS APP_FILEFLAGS
FILEOS VOS_NT
@@ -87,13 +85,13 @@
VALUE "Comments", STR_LICENSE "\0"
VALUE "CompanyName", STR_COMPANY "\0"
VALUE "FileDescription", STR_PRODUCT "\0"
- VALUE "FileVersion", STR_VERISON "\0"
+ VALUE "FileVersion", ACR_VERSION_STRING "\0"
VALUE "InternalName", "libacr"
VALUE "LegalCopyright", STR_COPYRIGHT "\0"
VALUE "LegalTrademarks", STR_TRADEMARK "\0"
VALUE "OriginalFilename", "libacr.dll"
VALUE "ProductName", STR_PRODUCT "\0"
- VALUE "ProductVersion", STR_VERISON "\0"
+ VALUE "ProductVersion", ACR_VERSION_STRING "\0"
#if PRIVATE_BUILD
VALUE "PrivateBuild", STR_PRIVATE "\0"
VALUE "SpecialBuild", STR_SPECIAL "\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=764366&r1=764365&r2=764366&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 Mon Apr 13 07:42:50 2009
@@ -58,7 +58,7 @@
ACR_JNI_EXPORT_DECLARE(jstring, OS, getVersion)(ACR_JNISTDARGS)
{
- char buf[ACR_SBUFFER_SIZ];
+ char buf[ACR_SBUFF_SIZ];
switch (acr_osver->dwMajorVersion) {
case 4:
@@ -114,7 +114,7 @@
}
if (acr_osver->szCSDVersion[0]) {
strcat(buf, " (");
- strcat(buf, acr_osver->szCSDVersion);
+ strncat(buf, acr_osver->szCSDVersion, ACR_SBUFF_LEN - 32);
strcat(buf, ")");
}
return CSTR_TO_JSTRING(buf);
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c?rev=764366&r1=764365&r2=764366&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c Mon Apr 13 07:42:50 2009
@@ -36,7 +36,7 @@
WORD il = EVENTLOG_SUCCESS;
HANDLE source;
WCHAR *messages[2];
- WCHAR buffer[ACR_MBUFFER_SIZ];
+ WCHAR buffer[ACR_MBUFF_SIZ];
WORD nStrings = 1;
switch (level) {
@@ -71,7 +71,7 @@
err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
buffer,
- ACR_MBUFFER_SIZ, NULL);
+ ACR_MBUFF_LEN, NULL);
messages[1] = &buffer[0];
nStrings = 2;
}
Added: commons/sandbox/runtime/trunk/src/main/native/shared/buildmark.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/buildmark.c?rev=764366&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/buildmark.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/buildmark.c Mon Apr 13 07:42:50 2009
@@ -0,0 +1,29 @@
+/* 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.
+ */
+
+#include "acr.h"
+#include "acr_version.h"
+
+#if defined(__DATE__) && defined(__TIME__)
+static const char library_built[] = __DATE__ " " __TIME__;
+#else
+static const char library_built[] = "Unknown";
+#endif
+
+ACR_DECLARE(const char *) ACR_GetLibraryBuilt()
+{
+ return library_built;
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/buildmark.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/shared/buildmark.o
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/buildmark.o?rev=764366&view=auto
==============================================================================
Binary file - no diff available.
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/buildmark.o
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c?rev=764366&r1=764365&r2=764366&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c Mon Apr 13 07:42:50 2009
@@ -26,7 +26,7 @@
/**
* DirectByteBuffer utilities
*/
-ACR_JNI_EXPORT_DECLARE(jobject, DirectByteBuffer, malloc)(ACR_JNISTDARGS,
+ACR_JNI_EXPORT_DECLARE(jobject, DirectByteBuffer, alloc0)(ACR_JNISTDARGS,
jint size)
{
void *mem;
@@ -35,8 +35,8 @@
UNREFERENCED_O;
if (size < 1) {
- ACR_ThrowArgumentException(_E, THROW_FMARK,
- "allocation size must be greater then zero");
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EINVAL,
+ ACR_EINVALSIZ);
return NULL;
}
if ((mem = malloc(sz)) != NULL) {
@@ -46,29 +46,23 @@
return rv;
}
else {
- ACR_ThrowMemoryException(_E, THROW_FMARK,
- "malloc() failed");
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ENOMEM,
+ ACR_GET_OS_ERROR());
return NULL;
}
}
-ACR_JNI_EXPORT_DECLARE(jobject, DirectByteBuffer, calloc)(ACR_JNISTDARGS,
- jint num,
+ACR_JNI_EXPORT_DECLARE(jobject, DirectByteBuffer, alloc1)(ACR_JNISTDARGS,
jint size)
{
- size_t sz = (size_t)ACR_ALIGN_DEFAULT((size * num));
+ size_t sz = (size_t)ACR_ALIGN_DEFAULT((size));
void *mem;
UNREFERENCED_O;
- if (num < 1) {
- ACR_ThrowArgumentException(_E, THROW_FMARK,
- "number of elements must be greater then zero");
- return NULL;
- }
if (size < 1) {
- ACR_ThrowArgumentException(_E, THROW_FMARK,
- "size of the element must be greater then zero");
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EINVAL,
+ ACR_EINVALSIZ);
return NULL;
}
if ((mem = calloc(1, sz)) != NULL) {
@@ -78,31 +72,37 @@
return rv;
}
else {
- ACR_ThrowMemoryException(_E, THROW_FMARK,
- "calloc() failed");
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ENOMEM,
+ ACR_GET_OS_ERROR());
return NULL;
}
}
-ACR_JNI_EXPORT_DECLARE(jobject, DirectByteBuffer, create)(ACR_JNISTDARGS,
+ACR_JNI_EXPORT_DECLARE(jobject, DirectByteBuffer, attach)(ACR_JNISTDARGS,
jlong addr,
+ jint offset,
jint size)
{
void *mem = J2P(addr, void *);
UNREFERENCED_O;
-
+
if (!mem) {
- ACR_ThrowNullPointerException(_E, THROW_FMARK,
- "null address argument");
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ENULL,
+ ACR_EISNULL);
return NULL;
}
if (size < 1) {
- ACR_ThrowArgumentException(_E, THROW_FMARK,
- "allocation size must be greater then zero");
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EINVAL,
+ ACR_EINVALSIZ);
+ return NULL;
+ }
+ if (offset < 0) {
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EINVAL,
+ ACR_EINVALSIZ);
return NULL;
}
- return (*_E)->NewDirectByteBuffer(_E, mem, (jlong)size);
+ return (*_E)->NewDirectByteBuffer(_E, mem + (size_t)offset, (jlong)size);
}
ACR_JNI_EXPORT_DECLARE(void, DirectByteBuffer, free)(ACR_JNISTDARGS, jobject bb)
@@ -118,11 +118,19 @@
free(mem);
}
else {
- ACR_ThrowNullPointerException(_E, THROW_FMARK,
- "GetDirectBufferAddress is null");
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ENULL,
+ ACR_EISNULL);
}
}
+/* XXX: Do we need 32/64 bit int/long methods? */
+ACR_JNI_EXPORT_DECLARE(jniptr, DirectByteBuffer, addressN)(ACR_JNISTDARGS,
+ jobject bb)
+{
+ UNREFERENCED_O;
+ return P2N((*_E)->GetDirectBufferAddress(_E, bb));
+}
+
ACR_JNI_EXPORT_DECLARE(jlong, DirectByteBuffer, address)(ACR_JNISTDARGS,
jobject bb)
{
@@ -136,3 +144,82 @@
UNREFERENCED_O;
return (*_E)->GetDirectBufferCapacity(_E, bb);
}
+
+ACR_JNI_EXPORT_DECLARE(void, DirectByteBuffer, set)(ACR_JNISTDARGS,
+ jobject bb,
+ jint c,
+ jint count)
+{
+ void *m;
+ jlong sz;
+
+ UNREFERENCED_O;
+ sz = (*_E)->GetDirectBufferCapacity(_E, bb);
+ if (count < 1) {
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EINVAL,
+ ACR_EINVALSIZ);
+ return;
+ }
+ if ((jlong)count > sz) {
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EINDEX,
+ ACR_ERANGE);
+ return;
+ }
+ if ((m = (*_E)->GetDirectBufferAddress(_E, bb))) {
+ memset(m, c, (size_t)count);
+ }
+ else {
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ENULL,
+ ACR_EISNULL);
+ }
+}
+
+ACR_JNI_EXPORT_DECLARE(void, DirectByteBuffer, copy0)(ACR_JNISTDARGS,
+ jobject srcb,
+ jint srco,
+ jobject dstb,
+ jint dsto,
+ jint count)
+{
+ void *d;
+ void *s;
+ jlong ss;
+ jlong ds;
+
+ UNREFERENCED_O;
+ ss = (*_E)->GetDirectBufferCapacity(_E, srcb);
+ ds = (*_E)->GetDirectBufferCapacity(_E, dstb);
+ if (count < 1) {
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EINVAL,
+ ACR_EINVALSIZ);
+ return;
+ }
+ if (ss < 1 || ds < 1) {
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EINVAL,
+ ACR_EINVALSIZ);
+ return;
+ }
+ if ((jlong)(count + srco) > ss) {
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EINDEX,
+ ACR_ERANGE);
+ return;
+ }
+ if ((jlong)(count + dsto) > ds) {
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EINDEX,
+ ACR_ERANGE);
+ return;
+ }
+ if ((s = (*_E)->GetDirectBufferAddress(_E, srcb))) {
+ if ((d = (*_E)->GetDirectBufferAddress(_E, dstb))) {
+ memcpy((char *)d + dsto, (char *)s + srco, (size_t)count);
+ }
+ else {
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ENULL,
+ ACR_EISNULL);
+ }
+ }
+ else {
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ENULL,
+ ACR_EISNULL);
+ }
+}
Added: commons/sandbox/runtime/trunk/src/main/native/shared/dbb.o
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/dbb.o?rev=764366&view=auto
==============================================================================
Binary file - no diff available.
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/dbb.o
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=764366&r1=764365&r2=764366&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Mon Apr 13 07:42:50 2009
@@ -16,6 +16,23 @@
#include "acr.h"
#include "acr_private.h"
+#include "acr_error.h"
+#include "acr_string.h"
+#include "acr_vm.h"
+
+/* Has to be in sync with acr_trow_class_e */
+static const char *throw_classes[] = {
+ "java/lang/Exception",
+ "java/lang/RuntimeException",
+ "java/lang/OutOfMemoryError",
+ "java/lang/NullPointerException",
+ "java/lang/IllegalArgumentException",
+ "java/lang/IndexOutOfBoundsException",
+ "java/io/IOException",
+ "java/net/SocketException",
+ NULL
+};
+
/*
* Convenience function to help throw any class
@@ -25,9 +42,21 @@
{
jclass ec;
+ if (!env)
+ env = ACR_GetJNIEnv();
+ if (!env) {
+ fprintf(stderr, "[ERROR] Cannot allocate JNI Environment\n");
+ if (msg)
+ fprintf(stderr, " %s\n", msg);
+ fflush(stderr);
+ return;
+ }
ec = (*env)->FindClass(env, clazz);
- if (ec == NULL) {
- fprintf(stderr, "Cannot find %s class\n", clazz);
+ if (IS_JOBJECT_NULL(env, ec)) {
+ fprintf(stderr, "[ERROR] Cannot find class '%s'\n", clazz);
+ if (msg)
+ fprintf(stderr, " %s\n", msg);
+ fflush(stderr);
return;
}
(*env)->ThrowNew(env, ec, msg);
@@ -38,77 +67,367 @@
* Convenience function to help throw any class with
* file and line number from where the exception was called.
*/
- ACR_DECLARE(void) ACR_ThrowClassEx(JNIEnv *env, const char *clazz,
+ ACR_DECLARE(void) ACR_ThrowClassEx(JNIEnv *env,
const char *file, int line,
- const char *msg)
+ const char *clazz, const char *msg)
{
if (file) {
- char fmt[ACR_HBUFFER_SIZ];
- char *f = (char *)(file + strlen(file) - 1);
- while (f != file && '\\' != *f && '/' != *f) {
- f--;
- }
- if (f != file) {
- f++;
- }
+ char fmt[ACR_HBUFF_SIZ];
+ const char *fn = ACR_FilePathNameGet(file);
if (msg)
- snprintf(fmt, ACR_HBUFFER_LEN, "%s (%s)+%d", msg, f, line);
+ snprintf(fmt, ACR_HBUFF_LEN, "%s (%s)+%d", msg, fn, line);
else
- snprintf(fmt, ACR_HBUFFER_LEN, "(%s)+%d", f, line);
- ACR_ThrowClass(env, clazz, &fmt[0]);
+ snprintf(fmt, ACR_HBUFF_LEN, "(%s)+%d", fn, line);
+ ACR_ThrowClass(env, clazz, fmt);
}
else {
ACR_ThrowClass(env, clazz, msg);
}
}
-
-/*
- * Convenience function to help throw an java.lang.Exception.
- */
-ACR_DECLARE(void) ACR_ThrowException(JNIEnv *env, const char *msg)
+ACR_DECLARE(void) ACR_ThrowExceptionA(JNIEnv *env,
+ const char *file, int line,
+ acr_trowclass_e clazz, const char *msg)
{
- ACR_ThrowClass(env, "java/lang/Exception", msg);
+ ACR_ThrowClassEx(env, file, line, throw_classes[clazz], msg);
}
/*
* Convenience function to help throw an java.io.IOException.
*/
-ACR_DECLARE(void) ACR_ThrowIOException(JNIEnv *env, const char *msg)
+ACR_DECLARE(void) ACR_ThrowException(JNIEnv *env,
+ const char *file, int line,
+ acr_trowclass_e clazz, int err)
{
- ACR_ThrowClass(env, "java/io/IOException", msg);
+ char buf[ACR_MBUFF_SIZ];
+
+ ACR_ThrowExceptionA(env, file, line, clazz,
+ ACR_GetErrorString(err, buf, ACR_MBUFF_LEN));
}
/*
- * Convenience function to help throw an java.lang.OutOfMemoryError.
+ * stuffbuffer - like ACR_CopyStrn() but returns the address of the
+ * dest buffer instead of the address of the terminating '\0'
*/
-ACR_DECLARE(void) ACR_ThrowMemoryException(JNIEnv *env, const char *file,
- int line, const char *msg)
+static char *stuffbuffer(char *buf, acr_size_t bufsize, const char *s)
{
- ACR_ThrowClassEx(env, "java/lang/OutOfMemoryError", file, line, msg);
+ ACR_CopyStrn(buf,s,bufsize);
+ return buf;
}
-/*
- * Convenience function to help throw an java.lang.NullPointerException.
- */
-ACR_DECLARE(void) ACR_ThrowNullPointerException(JNIEnv *env, const char *file,
- int line, const char *msg)
+static char *stuffunknown(char *buf, acr_size_t bufsize, int statcode)
{
- ACR_ThrowClassEx(env, "java/lang/NullPointerException", file, line, msg);
+ snprintf(buf, bufsize, "Unrecognized ACR error code %d", statcode);
+ return buf;
}
-/*
- * Convenience function to help throw an java.lang.IllegalArgumentException.
+static const char *acr_error_string(int statcode)
+{
+ switch (statcode) {
+ case ACR_ENOPOOL:
+ return "A new pool could not be created.";
+ case ACR_EBADDATE:
+ return "An invalid date has been provided";
+ case ACR_EINVALSOCK:
+ return "An invalid socket was returned";
+ case ACR_ENOPROC:
+ return "No process was provided and one was required.";
+ case ACR_ENOTIME:
+ return "No time was provided and one was required.";
+ case ACR_ENODIR:
+ return "No directory was provided and one was required.";
+ case ACR_ENOLOCK:
+ return "No lock was provided and one was required.";
+ case ACR_ENOPOLL:
+ return "No poll structure was provided and one was required.";
+ case ACR_ENOSOCKET:
+ return "No socket was provided and one was required.";
+ case ACR_ENOTHREAD:
+ return "No thread was provided and one was required.";
+ case ACR_ENOTHDKEY:
+ return "No thread key structure was provided and one was required.";
+ case ACR_ENOSHMAVAIL:
+ return "No shared memory is currently available";
+ case ACR_EDSOOPEN:
+#if HAVE_DLFCN_H
+ return dlerror();
+#else
+ return "DSO load failed";
+#endif /* HAVE_DLFCN_H */
+ case ACR_EBADIP:
+ return "The specified IP address is invalid.";
+ case ACR_EBADMASK:
+ return "The specified network mask is invalid.";
+
+ case ACR_INCHILD:
+ return
+ "Your code just forked, and you are currently executing in the "
+ "child process";
+ case ACR_INPARENT:
+ return
+ "Your code just forked, and you are currently executing in the "
+ "parent process";
+ case ACR_DETACH:
+ return "The specified thread is detached";
+ case ACR_NOTDETACH:
+ return "The specified thread is not detached";
+ case ACR_CHILD_DONE:
+ return "The specified child process is done executing";
+ case ACR_CHILD_NOTDONE:
+ return "The specified child process is not done executing";
+ case ACR_TIMEUP:
+ return "The timeout specified has expired";
+ case ACR_INCOMPLETE:
+ return "Partial results are valid but processing is incomplete";
+ case ACR_BADCH:
+ return "Bad character specified on command line";
+ case ACR_BADARG:
+ return "Missing parameter for the specified command line option";
+ case ACR_EOF:
+ return "End of file found";
+ case ACR_NOTFOUND:
+ return "Could not find specified socket in poll list.";
+ case ACR_ANONYMOUS:
+ return "Shared memory is implemented anonymously";
+ case ACR_FILEBASED:
+ return "Shared memory is implemented using files";
+ case ACR_KEYBASED:
+ return "Shared memory is implemented using a key system";
+ case ACR_EINIT:
+ return
+ "There is no error, this value signifies an initialized "
+ "error code";
+ case ACR_ENOTIMPL:
+ return "This function has not been implemented on this platform";
+ case ACR_EMISMATCH:
+ return "passwords do not match";
+ case ACR_EABSOLUTE:
+ return "The given path is absolute";
+ case ACR_ERELATIVE:
+ return "The given path is relative";
+ case ACR_EINCOMPLETE:
+ return "The given path is incomplete";
+ case ACR_EABOVEROOT:
+ return "The given path was above the root path";
+ case ACR_EBADPATH:
+ return "The given path is misformatted or contained invalid characters";
+ case ACR_EPATHWILD:
+ return "The given path contained wildcard characters";
+ case ACR_EPROC_UNKNOWN:
+ return "The process is not recognized.";
+ case ACR_EGENERAL:
+ return "Internal error";
+ case ACR_EISNULL:
+ return "The given argument is null";
+ case ACR_EINVALSIZ:
+ return "The given argument size is invalid";
+ case ACR_ERANGE:
+ return "The given argument is out of range";
+ default:
+ return "Error string not specified yet";
+ }
+}
+
+#if defined(WIN32)
+
+static const struct {
+ int code;
+ const char *msg;
+} gaErrorList[] = {
+ WSAEINTR, "Interrupted system call",
+ WSAEBADF, "Bad file number",
+ WSAEACCES, "Permission denied",
+ WSAEFAULT, "Bad address",
+ WSAEINVAL, "Invalid argument",
+ WSAEMFILE, "Too many open sockets",
+ WSAEWOULDBLOCK, "Operation would block",
+ WSAEINPROGRESS, "Operation now in progress",
+ WSAEALREADY, "Operation already in progress",
+ WSAENOTSOCK, "Socket operation on non-socket",
+ WSAEDESTADDRREQ, "Destination address required",
+ WSAEMSGSIZE, "Message too long",
+ WSAEPROTOTYPE, "Protocol wrong type for socket",
+ WSAENOPROTOOPT, "Bad protocol option",
+ WSAEPROTONOSUPPORT, "Protocol not supported",
+ WSAESOCKTNOSUPPORT, "Socket type not supported",
+ WSAEOPNOTSUPP, "Operation not supported on socket",
+ WSAEPFNOSUPPORT, "Protocol family not supported",
+ WSAEAFNOSUPPORT, "Address family not supported",
+ WSAEADDRINUSE, "Address already in use",
+ WSAEADDRNOTAVAIL, "Can't assign requested address",
+ WSAENETDOWN, "Network is down",
+ WSAENETUNREACH, "Network is unreachable",
+ WSAENETRESET, "Net connection reset",
+ WSAECONNABORTED, "Software caused connection abort",
+ WSAECONNRESET, "Connection reset by peer",
+ WSAENOBUFS, "No buffer space available",
+ WSAEISCONN, "Socket is already connected",
+ WSAENOTCONN, "Socket is not connected",
+ WSAESHUTDOWN, "Can't send after socket shutdown",
+ WSAETOOMANYREFS, "Too many references, can't splice",
+ WSAETIMEDOUT, "Connection timed out",
+ WSAECONNREFUSED, "Connection refused",
+ WSAELOOP, "Too many levels of symbolic links",
+ WSAENAMETOOLONG, "File name too long",
+ WSAEHOSTDOWN, "Host is down",
+ WSAEHOSTUNREACH, "No route to host",
+ WSAENOTEMPTY, "Directory not empty",
+ WSAEPROCLIM, "Too many processes",
+ WSAEUSERS, "Too many users",
+ WSAEDQUOT, "Disc quota exceeded",
+ WSAESTALE, "Stale NFS file handle",
+ WSAEREMOTE, "Too many levels of remote in path",
+ WSASYSNOTREADY, "Network system is unavailable",
+ WSAVERNOTSUPPORTED, "Winsock version out of range",
+ WSANOTINITIALISED, "WSAStartup not yet called",
+ WSAEDISCON, "Graceful shutdown in progress",
+ WSAHOST_NOT_FOUND, "Host not found",
+ WSANO_DATA, "No host data of that type was found",
+ 0, NULL
+};
+
+
+static char *acr_os_strerror(char *buf, acr_size_t bufsize, int errcode)
+{
+ acr_size_t len = 0, i;
+
+ len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ errcode,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
+ buf,
+ (DWORD)bufsize,
+ NULL);
+ if (!len) {
+ for (i = 0; gaErrorList[i].msg; i++) {
+ if (gaErrorList[i].code == errcode) {
+ ACR_CopyStrn(buf, gaErrorList[i].msg, bufsize);
+ len = strlen(buf);
+ break;
+ }
+ }
+ }
+
+ if (len) {
+ /* FormatMessage put the message in the buffer, but it may
+ * have embedded a newline (\r\n), and possible more than one.
+ * Remove the newlines replacing them with a space. This is not
+ * as visually perfect as moving all the remaining message over,
+ * but more efficient.
+ */
+ i = len;
+ while (i) {
+ i--;
+ if ((buf[i] == '\r') || (buf[i] == '\n'))
+ buf[i] = ' ';
+ }
+ }
+ else {
+ /* Windows didn't provide us with a message. Even stuff like
+ * WSAECONNREFUSED won't get a message.
+ */
+ snprintf(buf, bufsize, "Unrecognized Win32 error code %d", errcode);
+ }
+
+ return buf;
+}
+
+#else
+/* On Unix, apr_os_strerror() handles error codes from the resolver
+ * (h_errno).
*/
-ACR_DECLARE(void) ACR_ThrowArgumentException(JNIEnv *env, const char *file,
- int line, const char *msg)
+static char *acr_os_strerror(char* buf, acr_size_t bufsize, int err)
{
- ACR_ThrowClassEx(env, "java/lang/IllegalArgumentException", file, line, msg);
+#if !defined(WIN32)
+ return stuffbuffer(buf, bufsize, hstrerror(err));
+#else /* WIN32 */
+ const char *msg;
+
+ switch(err) {
+ case HOST_NOT_FOUND:
+ msg = "Unknown host";
+ break;
+#if defined(NO_DATA)
+ case NO_DATA:
+#if defined(NO_ADDRESS) && (NO_DATA != NO_ADDRESS)
+ case NO_ADDRESS:
+#endif
+ msg = "No address for host";
+ break;
+#elif defined(NO_ADDRESS)
+ case NO_ADDRESS:
+ msg = "No address for host";
+ break;
+#endif /* NO_DATA */
+ default:
+ msg = "Unrecognized resolver error";
+ }
+ return stuffbuffer(buf, bufsize, msg);
+#endif /* HAVE_STRERROR */
}
+#endif
+#if !defined(WIN32)
+/* glibc style */
+static char *native_strerror(int statcode, char *buf,
+ acr_size_t bufsize)
+{
+ const char *msg;
-ACR_DECLARE(void) ACR_ThrowOSException(JNIEnv *env, const char *msg)
+ buf[0] = '\0';
+ msg = strerror_r(statcode, buf, bufsize);
+ if (buf[0] == '\0') { /* libc didn't use our buffer */
+ return stuffbuffer(buf, bufsize, msg);
+ }
+ else {
+ return buf;
+ }
+}
+#else
+/* plain old strerror();
+ * thread-safe on some platforms (e.g., Solaris, OS/390)
+ */
+static char *native_strerror(int statcode, char *buf,
+ acr_size_t bufsize)
{
- ACR_ThrowClass(env, ACR_CLASS_PATH "exception/OperatingSystemException", msg);
+ const char *err = strerror(statcode);
+ if (err) {
+ return stuffbuffer(buf, bufsize, err);
+ } else {
+ return stuffunknown(buf, bufsize, statcode);
+ }
}
+#endif
+ACR_DECLARE(char *) ACR_GetErrorString(int statcode, char *buf,
+ acr_size_t bufsize)
+{
+ if (statcode < ACR_OS_START_ERROR) {
+ return native_strerror(statcode, buf, bufsize);
+ }
+ else if (statcode < ACR_OS_START_USERERR) {
+ return stuffbuffer(buf, bufsize, acr_error_string(statcode));
+ }
+ else if (statcode < ACR_OS_START_EAIERR) {
+ return stuffunknown(buf, bufsize, statcode);
+ }
+ else if (statcode < ACR_OS_START_SYSERR) {
+#if HAVE_NETDB_H
+ statcode -= ACR_OS_START_EAIERR;
+#if defined(NEGATIVE_EAI)
+ statcode = -statcode;
+#endif
+ return stuffbuffer(buf, bufsize, gai_strerror(statcode));
+#else
+ return stuffunknown(buf, bufsize, statcode);
+#endif
+ }
+ else {
+ if ((statcode - ACR_OS_START_SYSERR) < ACR_OS_ERRSPACE_SIZE)
+ return acr_os_strerror(buf, bufsize, statcode - ACR_OS_START_SYSERR);
+ else {
+ return stuffunknown(buf, bufsize, statcode);
+ }
+ }
+}
Added: commons/sandbox/runtime/trunk/src/main/native/shared/error.o
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.o?rev=764366&view=auto
==============================================================================
Binary file - no diff available.
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/error.o
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/memory.c?rev=764366&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/memory.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/memory.c Mon Apr 13 07:42:50 2009
@@ -0,0 +1,220 @@
+/* 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.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_memory.h"
+#include "acr_error.h"
+#include "acr_vm.h"
+
+struct acr_sbh_t {
+ acr_size_t owns;
+ acr_size_t size;
+ acr_size_t ppos;
+ char *buff;
+ acr_size_t dyn_size;
+ acr_size_t dyn_ppos;
+ void **dyn_buff;
+};
+
+ACR_DECLARE(void *) ACR_Malloc(JNIEnv *_E, const char *file, int line,
+ acr_size_t size)
+{
+ void *mem = malloc(size);
+
+ if (!mem) {
+ if (_E == NULL)
+ _E = ACR_GetJNIEnv();
+ if (_E != NULL)
+ ACR_ThrowException(_E, file, line, ACR_EX_ENOMEM,
+ ACR_GET_OS_ERROR());
+ }
+ return mem;
+}
+
+ACR_DECLARE(void *) ACR_Calloc(JNIEnv *_E, const char *file, int line,
+ acr_size_t size)
+{
+ void *mem = calloc(1, size);
+
+ if (!mem) {
+ if (_E == NULL)
+ _E = ACR_GetJNIEnv();
+ if (_E != NULL)
+ ACR_ThrowException(_E, file, line, ACR_EX_ENOMEM,
+ ACR_GET_OS_ERROR());
+ }
+ return mem;
+}
+
+ACR_DECLARE(void) ACR_Free(JNIEnv *_E, const char *file, int line,
+ void *mem)
+{
+ if (!mem) {
+ if (_E == NULL)
+ _E = ACR_GetJNIEnv();
+ if (_E != NULL)
+ ACR_ThrowException(_E, file, line, ACR_EX_ENULL,
+ ACR_EISNULL);
+ }
+ else
+ free(mem);
+}
+
+ACR_DECLARE(acr_sbh_t *) ACR_SbhCreate(JNIEnv *_E,
+ const char *file, int line,
+ void *buff, acr_size_t size)
+{
+ static acr_size_t sbhs = ACR_ALIGN_DEFAULT(sizeof(acr_sbh_t));
+ char *base;
+ acr_sbh_t *sbh;
+
+ if (buff && (size > sbhs)) {
+ base = (char *)buff;
+ sbh = (acr_sbh_t *)base;
+ memset(sbh, 0, sbhs);
+ }
+ else {
+ if (!size) {
+#if (CC_SIZEOF_VOIDP == 8)
+ size = 2048;
+#else
+ size = 1024;
+#endif
+ }
+ else
+ size = ACR_ALIGN_DEFAULT(sbhs + size);
+ if (!(base = ACR_Calloc(_E, file, line, size)))
+ return NULL;
+ sbh = (acr_sbh_t *)base;
+ sbh->owns = size;
+ }
+ sbh->buff = base + sbhs;
+ sbh->size = size - sbhs;
+
+ return sbh;
+}
+
+/* This is mod_jk pool that works well
+ * both for small allocations together
+ * with few big ones
+ */
+static void *sbh_dyn_alloc(JNIEnv *_E,
+ const char *file, int line,
+ acr_sbh_t *sbh, acr_size_t size)
+{
+ void *mem;
+
+ if (sbh->dyn_size == sbh->dyn_ppos) {
+ /* Extend dynamic slot array */
+ size_t ns = sbh->dyn_size ? (sbh->dyn_size << 1) : 16;
+ void **nd = (void **)ACR_Malloc(_E, file, line, ns * sizeof(void *));
+ if (nd) {
+ if (sbh->dyn_buff) {
+ /* Copy old dynamic slots */
+ memcpy(nd, sbh->dyn_buff, sbh->dyn_size * sizeof(void *));
+ free(sbh->dyn_buff);
+ }
+
+ sbh->dyn_buff = nd;
+ sbh->dyn_size = ns;
+ }
+ else
+ return NULL;
+ }
+ /* Allocate the real memory */
+ mem = sbh->dyn_buff[sbh->dyn_ppos] = ACR_Malloc(_E, file, line, size);
+ if (sbh->dyn_buff[sbh->dyn_ppos])
+ sbh->dyn_ppos++;
+
+ return mem;
+}
+
+ACR_DECLARE(void *) ACR_SbhMalloc(JNIEnv *_E, const char *file, int line,
+ acr_sbh_t *sbh, acr_size_t size)
+{
+ void *mem;
+ if (!sbh) {
+ if (_E == NULL)
+ _E = ACR_GetJNIEnv();
+ if (_E != NULL)
+ ACR_ThrowException(_E, file, line, ACR_EX_ENULL,
+ ACR_EISNULL);
+ return NULL;
+ }
+
+ size = ACR_ALIGN_DEFAULT(size);
+ if ((sbh->size - sbh->ppos) >= size) {
+ mem = &(sbh->buff[sbh->ppos]);
+ sbh->ppos += size;
+ }
+ else {
+ mem = sbh_dyn_alloc(_E, file, line, sbh, size);
+ }
+
+ return mem;
+}
+
+ACR_DECLARE(void *) ACR_SbhCalloc(JNIEnv *_E, const char *file, int line,
+ acr_sbh_t *sbh, acr_size_t size)
+{
+ void *mem = ACR_SbhMalloc(_E, file, line, sbh, size);
+
+ if (mem) {
+ memset(mem, 0, size);
+ }
+ return mem;
+}
+
+ACR_DECLARE(void ) ACR_SbhReset(JNIEnv *_E, const char *file, int line,
+ acr_sbh_t *sbh)
+{
+ if (!sbh) {
+ if (_E == NULL)
+ _E = ACR_GetJNIEnv();
+ if (_E != NULL)
+ ACR_ThrowException(_E, file, line, ACR_EX_ENULL,
+ ACR_EISNULL);
+ return;
+ }
+ if (sbh->dyn_ppos && sbh->dyn_buff) {
+ size_t i;
+ for (i = 0; i < sbh->dyn_ppos; i++) {
+ free(sbh->dyn_buff[i]);
+ }
+ }
+
+ sbh->dyn_ppos = 0;
+ sbh->ppos = 0;
+}
+
+ACR_DECLARE(void ) ACR_SbhDestroy(JNIEnv *_E, const char *file, int line,
+ acr_sbh_t *sbh)
+{
+ if (!sbh) {
+ if (_E == NULL)
+ _E = ACR_GetJNIEnv();
+ if (_E != NULL)
+ ACR_ThrowException(_E, file, line, ACR_EX_ENULL,
+ ACR_EISNULL);
+ return;
+ }
+ ACR_SbhReset(_E, file, line, sbh);
+ if (sbh->dyn_buff)
+ free(sbh->dyn_buff);
+ if (sbh->owns)
+ free(sbh);
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/shared/memory.o
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/memory.o?rev=764366&view=auto
==============================================================================
Binary file - no diff available.
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/memory.o
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
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=764366&r1=764365&r2=764366&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Mon Apr 13 07:42:50 2009
@@ -16,6 +16,9 @@
#include "acr.h"
#include "acr_private.h"
+#include "acr_string.h"
+#include "acr_memory.h"
+#include "acr_error.h"
/*
* Apache's "replacement" for the strncpy() function. We roll our
@@ -61,7 +64,7 @@
*
* Corrected Win32 to accept "a/b\\stuff", "a:stuff"
*/
-ACR_DECLARE(const char *) ACR_FilepathNameGet(const char *pathname)
+ACR_DECLARE(const char *) ACR_FilePathNameGet(const char *pathname)
{
const char path_separator = '/';
const char *s = strrchr(pathname, path_separator);
@@ -80,12 +83,12 @@
return s ? ++s : pathname;
}
-ACR_DECLARE(char *) ACR_Itoa(jint n)
+ACR_DECLARE(char *) ACR_Itoa(acr_int_t n)
{
const int BUFFER_SIZE = sizeof(jint) * 3 + 2;
char *start;
int negative;
- char *buf = malloc(BUFFER_SIZE);
+ char *buf = ACR_Malloc(NULL, THROW_FMARK, BUFFER_SIZE);
if (!buf)
return NULL;
@@ -108,12 +111,12 @@
return start;
}
-ACR_DECLARE(char *) ACR_Ltoa(jlong n)
+ACR_DECLARE(char *) ACR_Ltoa(acr_long_t n)
{
const int BUFFER_SIZE = sizeof(jlong) * 3 + 2;
char *start;
int negative;
- char *buf = malloc(BUFFER_SIZE);
+ char *buf = ACR_Malloc(NULL, THROW_FMARK, BUFFER_SIZE);
if (!buf)
return NULL;
Added: commons/sandbox/runtime/trunk/src/main/native/shared/string.o
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.o?rev=764366&view=auto
==============================================================================
Binary file - no diff available.
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/string.o
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java?rev=764366&r1=764365&r2=764366&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java Mon Apr 13 07:42:50 2009
@@ -33,6 +33,8 @@
// Fundamentals
suite.addTest(TestProperties.suite());
suite.addTest(TestOS.suite());
+ suite.addTest(TestDirectByteBuffer.suite());
+ suite.addTest(TestPrivate.suite());
return suite;
}
Added: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java?rev=764366&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java (added)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java Mon Apr 13 07:42:50 2009
@@ -0,0 +1,111 @@
+/* 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.
+ */
+
+package org.apache.commons.runtime;
+
+import java.lang.System;
+import java.util.Properties;
+import java.nio.ByteBuffer;
+import junit.framework.*;
+
+/**
+ * DirectByteBuffer tests
+ */
+public class TestDirectByteBuffer extends TestCase
+{
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(TestDirectByteBuffer.class);
+ return suite;
+ }
+
+ protected void setUp()
+ throws Exception
+ {
+ System.loadLibrary("acr");
+ }
+
+
+ public void testMalloc()
+ throws Exception
+ {
+ ByteBuffer bb = DirectByteBuffer.allocate(1000);
+ assertTrue("Direct", bb.isDirect());
+ assertEquals("Capacity", 1000, bb.capacity());
+ DirectByteBuffer.free(bb);
+ }
+
+ public void testCalloc()
+ throws Exception
+ {
+ ByteBuffer bb = DirectByteBuffer.allocateAndInitToZero(1000);
+ assertTrue("Direct", bb.isDirect());
+ assertEquals("Capacity", 1000, bb.capacity());
+ DirectByteBuffer.free(bb);
+ }
+
+ public void testAddress()
+ throws Exception
+ {
+ // bb1 and bb2 share the same memory
+ ByteBuffer bb1 = DirectByteBuffer.allocate(1000);
+ long a = DirectByteBuffer.address(bb1);
+ ByteBuffer bb2 = DirectByteBuffer.allocate(a, 0, 1000);
+ bb1.putInt(0xcafebabe);
+ assertTrue("Direct", bb2.isDirect());
+ assertEquals("Capacity", 1000, bb2.capacity());
+ assertEquals("Value", 0xcafebabe, bb2.getInt());
+ DirectByteBuffer.free(bb1);
+ /*
+ * Call to the second free crashes the JVM !
+ * Also call to the any operation on any
+ * Byte buffer will probably crash the JVM after the
+ * memory is free'd
+ * bb2.putInt(0xcafebabe); might write to something else
+ * DirectByteBuffer.free(bb2); will free already free'd memory
+ * causing core.
+ */
+ }
+
+ public void testMemset()
+ throws Exception
+ {
+ ByteBuffer bb = DirectByteBuffer.allocate(1000);
+ assertTrue("Direct", bb.isDirect());
+ bb.putInt(0xcafebabe);
+ bb.rewind();
+ assertEquals("Value put", 0xcafebabe, bb.getInt());
+ DirectByteBuffer.set(bb, 0x55, 1000);
+ assertEquals("Value set", 0x55555555, bb.getInt());
+ DirectByteBuffer.free(bb);
+ }
+
+ public void testCopy()
+ throws Exception
+ {
+ ByteBuffer sb = DirectByteBuffer.allocate(1000);
+ ByteBuffer db = DirectByteBuffer.allocateAndInitToZero(1000);
+ assertTrue("Direct", sb.isDirect());
+ assertTrue("Direct", db.isDirect());
+ sb.putInt(0xcafebabe);
+ DirectByteBuffer.copy(sb, 0, db, 4, 996);
+ assertEquals("Zero", 0, db.getInt());
+ assertEquals("Value", 0xcafebabe, db.getInt());
+ DirectByteBuffer.free(sb);
+ DirectByteBuffer.free(db);
+ }
+
+}
Propchange: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java?rev=764366&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java (added)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Mon Apr 13 07:42:50 2009
@@ -0,0 +1,141 @@
+/* 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.
+ */
+
+package org.apache.commons.runtime;
+
+import java.lang.System;
+import java.util.Properties;
+import java.nio.ByteBuffer;
+import junit.framework.*;
+
+/**
+ * Native Test.
+ * The native methods are compiled only when
+ * configure --enable-test is called before making the
+ * native library.
+ * This is usually not part of standard distribution
+ * so enable it only when running the test suite.
+ */
+public class TestPrivate extends TestCase
+{
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(TestPrivate.class);
+ return suite;
+ }
+
+ private char longChar[] = new char[32768];
+ private String longString;
+ private static native void test000(int err);
+ private static native void test001(String msg);
+ private static native void test002(int err);
+ private static native void test003(int d);
+ private static native int test004(int d);
+ private static native int test005(String msg);
+ private static native int test006(String msg);
+
+
+ protected void setUp()
+ throws Exception
+ {
+ System.loadLibrary("acr");
+ for (int i = 0; i < 32768; i++) {
+ longChar[i] = (char)('A' + (i % 20));
+ }
+ longString = new String(longChar);
+ }
+
+ public void testExInt()
+ throws Exception
+ {
+ try {
+ test000(0);
+ fail("Exception not thrown");
+ } catch (Throwable t) {
+ assertSame("Wrong Exception class",
+ java.lang.Exception.class, t.getClass());
+ }
+
+ }
+
+ public void testExStr()
+ throws Exception
+ {
+ try {
+ test001(null);
+ fail("Exception not thrown");
+ } catch (Throwable t) {
+ assertSame("Wrong Exception class",
+ java.lang.IllegalArgumentException.class, t.getClass());
+ }
+ }
+
+ public void testExNullJNIEnv()
+ throws Exception
+ {
+ try {
+ // Call to ACR_Thow has NULL JNIEnv and call to
+ // ACR_GetJNIEnv is performed.
+ test002(0);
+ fail("Exception not thrown");
+ } catch (Throwable t) {
+ assertSame("Wrong Exception class",
+ java.lang.OutOfMemoryError.class, t.getClass());
+ }
+ }
+
+ public void testFreeNull()
+ throws Exception
+ {
+ try {
+ test003(0);
+ fail("Exception not thrown");
+ } catch (Throwable t) {
+ assertSame("Wrong Exception class",
+ java.lang.NullPointerException.class, t.getClass());
+ }
+ }
+
+ public void testSbh()
+ throws Exception
+ {
+ int i = test004(1024);
+ assertEquals("Count", 10, i);
+ }
+
+ public void testWStrlen()
+ throws Exception
+ {
+ int i = test005(longString);
+ assertEquals("Length", longString.length(), i);
+ }
+
+ public void testCStrlen()
+ throws Exception
+ {
+ int i = test006(longString);
+ assertEquals("Length", longString.length(), i);
+ }
+
+ public void testUtf8Strlen()
+ throws Exception
+ {
+ String s = new String("\u2297\u2297");
+ int i = test006(s);
+ assertEquals("Length", 6, i);
+ }
+
+}
Propchange: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
------------------------------------------------------------------------------
svn:eol-style = native