From 9f7ca8edd33128fbf9293b549df47e16d2684b00 Mon Sep 17 00:00:00 2001 From: ahodgkinson Date: Wed, 14 Jun 2006 19:41:55 +0000 Subject: [PATCH] XFLAIM changes for building ring 0 NLMs. git-svn-id: https://svn.code.sf.net/p/flaim/code/trunk@574 0109f412-320b-0410-ab79-c3e0c5ffbbe6 --- xflaim/Makefile | 233 ++++++++++++++++++++++++++++++++-- xflaim/sample/sample.cpp | 56 ++++---- xflaim/src/flaimsys.h | 8 +- xflaim/src/fsysdata.cpp | 63 +++++++-- xflaim/util/checkdb.cpp | 2 +- xflaim/util/dbdiff.cpp | 1 - xflaim/util/diffbackups.cpp | 1 - xflaim/util/domedit.cpp | 1 - xflaim/util/fdomedt.cpp | 74 +++++++++-- xflaim/util/flm_lutl.cpp | 42 ++++-- xflaim/util/flmunittest.cpp | 73 +++++++---- xflaim/util/flmunittest.h | 2 +- xflaim/util/fshell.cpp | 147 +++++++++++++++++---- xflaim/util/indextest1srv.cpp | 29 ++--- xflaim/util/indextest2srv.cpp | 25 ++-- xflaim/util/view.cpp | 6 +- xflaim/util/xshell.cpp | 8 +- 17 files changed, 603 insertions(+), 168 deletions(-) diff --git a/xflaim/Makefile b/xflaim/Makefile index 109a437..d3e199e 100644 --- a/xflaim/Makefile +++ b/xflaim/Makefile @@ -52,6 +52,7 @@ win_target = unix_target = netware_target = submake_targets = +netware_ring_0_target = # -- Enable command echoing -- @@ -221,6 +222,11 @@ ifneq (,$(findstring nlm,$(MAKECMDGOALS))) netware_target = yes target_os_family = netware host_os_family = win + + ifneq (,$(findstring ring0,$(MAKECMDGOALS))) + submake_targets += ring0 + netware_ring_0_target = yes + endif endif ifndef target_os_family @@ -1112,11 +1118,13 @@ ifdef netware_target wc_dir := $(call normpath,$(wc_dir)) - ifndef ndk_dir - $(error Netware SDK could not be found. Please define ndk_dir.) + ifndef netware_ring_0_target + ifndef ndk_dir + $(error Netware SDK could not be found. Please define ndk_dir) + endif + + ndk_dir := $(call normpath,$(ndk_dir)) endif - - ndk_dir := $(call normpath,$(ndk_dir)) libr = "$(call normpath,$(strip $(wc_dir)))/binnt/wlib.exe" exe_linker = "$(call normpath,$(strip $(wc_dir)))/binnt/wlink.exe" @@ -1127,6 +1135,10 @@ ifdef netware_target ccdefs += FLM_DEBUG endif + ifdef netware_ring_0_target + ccdefs += FLM_RING_ZERO_NLM + endif + ccflags += /ez /6s /w4 /za /zp1 /zq /zm /s /ei /of+ /we /bt=NETWARE ifeq ($(build),release) @@ -1146,10 +1158,45 @@ ifdef netware_target export wpp386 = /d$(subst $(sp), /d,$(strip $(ccdefs))) $(ccflags) export wcc386 = /d$(subst $(sp), /d,$(strip $(ccdefs))) $(ccflags) - define make_lis_file_cmd + define make_ring_0_lis_file_cmd + $(ec)$(gprintf) "option verbose\n" > $(4) + $(ec)$(gprintf) "option stack=32k\n" >> $(4) + $(ec)$(gprintf) "option nod\n" >> $(4) + $(ec)$(gprintf) "option map\n" >> $(4) + $(ec)$(gprintf) "option nodefaultlibs\n" >> $(4) + $(ec)$(gprintf) "option screenname 'NONE'\n" >> $(4) + $(ec)$(gprintf) "option threadname '$(2)'\n" >> $(4) + $(ec)$(gprintf) "option start = f_nlmEntryPoint\n" >> $(4) + $(ec)$(gprintf) "option exit = f_nlmExitPoint\n" >> $(4) + $(ec)$(gprintf) "option nodefaultlibs\n" >> $(4) + $(ec)$(gprintf) "option xdcdata=nlm.xdc\n" >> $(4) + $(ec)$(gprintf) "option pseudopreemption\n" >> $(4) + $(ec)$(gprintf) "debug all debug novell\n" >> $(4) + $(ec)$(gprintf) "form novell nlm '$(2)'\n" >> $(4) + $(ec)$(gprintf) "name $(call ppath,$(1)/$(2)$(exe_suffix))\n" >> $(4) + $(ec)$(gprintf) "file $(subst $(sp),\nfile ,$(call ppath,$(3)))\n" >> $(4) + $(ec)$(gprintf) "library $(call ppath,$(xflaim_static_lib))\n" >> $(4) + $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib)(ctorarst)\n" >> $(4) + $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib)(dtorarst)\n" >> $(4) + $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib)(undefed)\n" >> $(4) + $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib)(undefmbd)\n" >> $(4) + $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib)(pure_err)\n" >> $(4) + $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib)(stablcl)\n" >> $(4) + $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib)(stabact)\n" >> $(4) + $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib)(stabactv)\n" >> $(4) + $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib)(stabmod)\n" >> $(4) + $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib)(prwdata)\n" >> $(4) + $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib)(moddtorr)\n" >> $(4) + $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib)(stabadt)\n" >> $(4) + $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/netware/clib3s.lib)(i8d)\n" >> $(4) + $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/netware/clib3s.lib)(i8m)\n" >> $(4) + $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/netware/clib3s.lib)(i8s)\n" >> $(4) + $(ec)$(gprintf) "alias __wcpp_4_fatal_runtime_error_=f_fatalRuntimeError\n" >> $(4) + endef + + define make_libc_lis_file_cmd $(ec)$(gprintf) "option verbose\n" > $(4) $(ec)$(gprintf) "option stack=32k\n" >> $(4) - $(ec)$(gprintf) "option synchronize\n" >> $(4) $(ec)$(gprintf) "option nod\n" >> $(4) $(ec)$(gprintf) "option map\n" >> $(4) $(ec)$(gprintf) "option nodefaultlibs\n" >> $(4) @@ -1157,26 +1204,180 @@ ifdef netware_target $(ec)$(gprintf) "option threadname '$(2)'\n" >> $(4) $(ec)$(gprintf) "option start = _LibCPrelude\n" >> $(4) $(ec)$(gprintf) "option exit = _LibCPostlude\n" >> $(4) + $(ec)$(gprintf) "option nodefaultlibs\n" >> $(4) + $(ec)$(gprintf) "option xdcdata=nlm.xdc\n" >> $(4) $(ec)$(gprintf) "option pseudopreemption\n" >> $(4) $(ec)$(gprintf) "debug all debug novell\n" >> $(4) $(ec)$(gprintf) "form novell nlm '$(2)'\n" >> $(4) $(ec)$(gprintf) "name $(call ppath,$(1)/$(2)$(exe_suffix))\n" >> $(4) - $(ec)$(gprintf) "file $(subst $(sp),\nfile ,$(call ppath,$(3)))\n" >> $(4) $(ec)$(gprintf) "file $(call ppath,$(ndk_dir)/libc/imports/libcpre.obj)\n" >> $(4) $(ec)$(gprintf) "library $(call ppath,$(xflaim_static_lib))\n" >> $(4) $(ec)$(gprintf) "library $(call ppath,$(wc_dir)/lib386/plib3s.lib)\n" >> $(4) $(ec)$(gprintf) "library $(call ppath,$(wc_dir)/lib386/netware/libc3s.lib)\n" >> $(4) - $(ec)$(gprintf) "import CurrentProcess\n" >> $(4) - $(ec)$(gprintf) "import @$(call ppath,$(ndk_dir)/libc/imports/libc.imp)\n" >> $(4) - $(ec)$(gprintf) "import @$(call ppath,$(ndk_dir)/libc/imports/netware.imp)\n" >> $(4) - $(ec)$(gprintf) "import @$(call ppath,$(ndk_dir)/libc/imports/ws2nlm.imp)\n" >> $(4) endef - + + define make_ring_0_imp_file_cmd + $(ec)$(gprintf) "import __WSAFDIsSet\n" > $(1) + $(ec)$(gprintf) "import ActivateScreen\n" >> $(1) + $(ec)$(gprintf) "import Alloc\n" >> $(1) + $(ec)$(gprintf) "import AllocateResourceTag\n" >> $(1) + $(ec)$(gprintf) "import atomic_dec\n" >> $(1) + $(ec)$(gprintf) "import atomic_inc\n" >> $(1) + $(ec)$(gprintf) "import atomic_xchg\n" >> $(1) + $(ec)$(gprintf) "import BitTest\n" >> $(1) + $(ec)$(gprintf) "import CEvaluateExpression\n" >> $(1) + $(ec)$(gprintf) "import CFindLoadModuleHandle\n" >> $(1) + $(ec)$(gprintf) "import CheckKeyStatus\n" >> $(1) + $(ec)$(gprintf) "import ClearScreen\n" >> $(1) + $(ec)$(gprintf) "import CloseFile\n" >> $(1) + $(ec)$(gprintf) "import CloseScreen\n" >> $(1) + $(ec)$(gprintf) "import CMovB\n" >> $(1) + $(ec)$(gprintf) "import CMoveFast\n" >> $(1) + $(ec)$(gprintf) "import ConvertPathString\n" >> $(1) + $(ec)$(gprintf) "import ConvertSecondsToTicks\n" >> $(1) + $(ec)$(gprintf) "import ConvertTicksToSeconds\n" >> $(1) + $(ec)$(gprintf) "import CpuCurrentProcessor\n" >> $(1) + $(ec)$(gprintf) "import CreateDirectory\n" >> $(1) + $(ec)$(gprintf) "import CreateFile\n" >> $(1) + $(ec)$(gprintf) "import CSetD\n" >> $(1) + $(ec)$(gprintf) "import DebuggerSymbolList\n" >> $(1) + $(ec)$(gprintf) "import DeleteDirectory\n" >> $(1) + $(ec)$(gprintf) "import DirectorySearch\n" >> $(1) + $(ec)$(gprintf) "import DirectReadFile\n" >> $(1) + $(ec)$(gprintf) "import DirectReadFile\n" >> $(1) + $(ec)$(gprintf) "import DirectWriteFile\n" >> $(1) + $(ec)$(gprintf) "import DirectWriteFile\n" >> $(1) + $(ec)$(gprintf) "import DirectWriteFileNoWait\n" >> $(1) + $(ec)$(gprintf) "import DirectWriteFileNoWait\n" >> $(1) + $(ec)$(gprintf) "import DisableInputCursor\n" >> $(1) + $(ec)$(gprintf) "import DisplayScreenTextWithAttribute\n" >> $(1) + $(ec)$(gprintf) "import DOSFirstByteBitMap\n" >> $(1) + $(ec)$(gprintf) "import EnableInputCursor\n" >> $(1) + $(ec)$(gprintf) "import EnterDebugger\n" >> $(1) + $(ec)$(gprintf) "import EraseFile\n" >> $(1) + $(ec)$(gprintf) "import ExpandFileInContiguousBlocks\n" >> $(1) + $(ec)$(gprintf) "import ExpandFileInContiguousBlocks\n" >> $(1) + $(ec)$(gprintf) "import ExportPublicSymbol\n" >> $(1) + $(ec)$(gprintf) "import FindAndLoadNLM\n" >> $(1) + $(ec)$(gprintf) "import Free\n" >> $(1) + $(ec)$(gprintf) "import FreeLimboVolumeSpace\n" >> $(1) + $(ec)$(gprintf) "import FreeLimboVolumeSpace\n" >> $(1) + $(ec)$(gprintf) "import GetCacheBufferSize\n" >> $(1) + $(ec)$(gprintf) "import GetClosestSymbol\n" >> $(1) + $(ec)$(gprintf) "import GetCurrentClock\n" >> $(1) + $(ec)$(gprintf) "import GetCurrentNumberOfCacheBuffers\n" >> $(1) + $(ec)$(gprintf) "import GetCurrentTime\n" >> $(1) + $(ec)$(gprintf) "import GetEntryFromPathStringBase\n" >> $(1) + $(ec)$(gprintf) "import GetEntryFromPathStringBase\n" >> $(1) + $(ec)$(gprintf) "import GetFileSize\n" >> $(1) + $(ec)$(gprintf) "import GetKey\n" >> $(1) + $(ec)$(gprintf) "import GetNLMAllocMemoryCounts\n" >> $(1) + $(ec)$(gprintf) "import GetOriginalNumberOfCacheBuffers\n" >> $(1) + $(ec)$(gprintf) "import GetProductMajorVersionNumber\n" >> $(1) + $(ec)$(gprintf) "import GetRunningProcess\n" >> $(1) + $(ec)$(gprintf) "import GetScreenSize\n" >> $(1) + $(ec)$(gprintf) "import GetSyncClockFields\n" >> $(1) + $(ec)$(gprintf) "import GetSystemConsoleScreen\n" >> $(1) + $(ec)$(gprintf) "import ImportPublicSymbol\n" >> $(1) + $(ec)$(gprintf) "import kCreateThread\n" >> $(1) + $(ec)$(gprintf) "import kCurrentThread\n" >> $(1) + $(ec)$(gprintf) "import kDelayThread\n" >> $(1) + $(ec)$(gprintf) "import kDestroyThread\n" >> $(1) + $(ec)$(gprintf) "import kExitThread\n" >> $(1) + $(ec)$(gprintf) "import kGetThreadName\n" >> $(1) + $(ec)$(gprintf) "import kGetThreadName\n" >> $(1) + $(ec)$(gprintf) "import KillMe\n" >> $(1) + $(ec)$(gprintf) "import kMutexAlloc\n" >> $(1) + $(ec)$(gprintf) "import kMutexFree\n" >> $(1) + $(ec)$(gprintf) "import kMutexLock\n" >> $(1) + $(ec)$(gprintf) "import kMutexUnlock\n" >> $(1) + $(ec)$(gprintf) "import kReturnCurrentProcessorID\n" >> $(1) + $(ec)$(gprintf) "import kScheduleThread\n" >> $(1) + $(ec)$(gprintf) "import kSemaphoreAlloc\n" >> $(1) + $(ec)$(gprintf) "import kSemaphoreExamineCount\n" >> $(1) + $(ec)$(gprintf) "import kSemaphoreFree\n" >> $(1) + $(ec)$(gprintf) "import kSemaphoreSignal\n" >> $(1) + $(ec)$(gprintf) "import kSemaphoreTimedWait\n" >> $(1) + $(ec)$(gprintf) "import kSemaphoreWait\n" >> $(1) + $(ec)$(gprintf) "import kSetThreadLoadHandle\n" >> $(1) + $(ec)$(gprintf) "import kSetThreadName\n" >> $(1) + $(ec)$(gprintf) "import kYieldIfTimeSliceUp\n" >> $(1) + $(ec)$(gprintf) "import kYieldThread\n" >> $(1) + $(ec)$(gprintf) "import LoadModule\n" >> $(1) + $(ec)$(gprintf) "import LoadRules\n" >> $(1) + $(ec)$(gprintf) "import MapFileHandleToFCB\n" >> $(1) + $(ec)$(gprintf) "import MapPathToDirectoryNumber\n" >> $(1) + $(ec)$(gprintf) "import MapPathToDirectoryNumber\n" >> $(1) + $(ec)$(gprintf) "import MapVolumeNameToNumber\n" >> $(1) + $(ec)$(gprintf) "import ModifyDirectoryEntry\n" >> $(1) + $(ec)$(gprintf) "import ModifyDirectoryEntry\n" >> $(1) + $(ec)$(gprintf) "import MountVolume\n" >> $(1) + $(ec)$(gprintf) "import NDSCreateStreamFile\n" >> $(1) + $(ec)$(gprintf) "import NDSDeleteStreamFile\n" >> $(1) + $(ec)$(gprintf) "import NDSOpenStreamFile\n" >> $(1) + $(ec)$(gprintf) "import NWLocalToUnicode\n" >> $(1) + $(ec)$(gprintf) "import NWUnicodeToLocal\n" >> $(1) + $(ec)$(gprintf) "import OpenFile\n" >> $(1) + $(ec)$(gprintf) "import OpenScreen\n" >> $(1) + $(ec)$(gprintf) "import OutputToScreen\n" >> $(1) + $(ec)$(gprintf) "import PositionInputCursor\n" >> $(1) + $(ec)$(gprintf) "import PositionOutputCursor\n" >> $(1) + $(ec)$(gprintf) "import ReadFile\n" >> $(1) + $(ec)$(gprintf) "import RenameEntry\n" >> $(1) + $(ec)$(gprintf) "import RestartServer\n" >> $(1) + $(ec)$(gprintf) "import ReturnResourceTag\n" >> $(1) + $(ec)$(gprintf) "import ReturnVolumeMappingInformation\n" >> $(1) + $(ec)$(gprintf) "import ReturnVolumeMappingInformation\n" >> $(1) + $(ec)$(gprintf) "import RevokeFileHandleRights\n" >> $(1) + $(ec)$(gprintf) "import SetCursorStyle\n" >> $(1) + $(ec)$(gprintf) "import SetFileSize\n" >> $(1) + $(ec)$(gprintf) "import SetFileSize\n" >> $(1) + $(ec)$(gprintf) "import SGUIDCreate\n" >> $(1) + $(ec)$(gprintf) "import SizeOfAllocBlock\n" >> $(1) + $(ec)$(gprintf) "import SwitchToDirectFileMode\n" >> $(1) + $(ec)$(gprintf) "import SwitchToDirectFileMode\n" >> $(1) + $(ec)$(gprintf) "import UngetKey\n" >> $(1) + $(ec)$(gprintf) "import UnImportPublicSymbol\n" >> $(1) + $(ec)$(gprintf) "import UnloadRules\n" >> $(1) + $(ec)$(gprintf) "import VMGetDirectoryEntry\n" >> $(1) + $(ec)$(gprintf) "import WriteFile\n" >> $(1) + $(ec)$(gprintf) "import WS2_32_bind\n" >> $(1) + $(ec)$(gprintf) "import WS2_32_closesocket\n" >> $(1) + $(ec)$(gprintf) "import WS2_32_gethostbyaddr\n" >> $(1) + $(ec)$(gprintf) "import WS2_32_gethostbyname\n" >> $(1) + $(ec)$(gprintf) "import WS2_32_gethostname\n" >> $(1) + $(ec)$(gprintf) "import WS2_32_htonl\n" >> $(1) + $(ec)$(gprintf) "import WS2_32_htons\n" >> $(1) + $(ec)$(gprintf) "import WS2_32_inet_addr\n" >> $(1) + $(ec)$(gprintf) "import WS2_32_inet_ntoa\n" >> $(1) + $(ec)$(gprintf) "import WS2_32_listen\n" >> $(1) + $(ec)$(gprintf) "import WS2_32_recv\n" >> $(1) + $(ec)$(gprintf) "import WS2_32_select\n" >> $(1) + $(ec)$(gprintf) "import WS2_32_send\n" >> $(1) + $(ec)$(gprintf) "import WS2_32_setsockopt\n" >> $(1) + $(ec)$(gprintf) "import WS2_32_shutdown\n" >> $(1) + $(ec)$(gprintf) "import WS2_32_socket\n" >> $(1) + $(ec)$(gprintf) "import WSAAccept\n" >> $(1) + $(ec)$(gprintf) "import WSACleanup\n" >> $(1) + $(ec)$(gprintf) "import WSAConnect\n" >> $(1) + $(ec)$(gprintf) "import WSAGetLastError\n" >> $(1) + $(ec)$(gprintf) "import WSAStartup\n" >> $(1) + endef + + define make_libc_imp_file_cmd + $(ec)$(gprintf) "import CurrentProcess\n" > $(1) + $(ec)$(gprintf) "import @$(call ppath,$(ndk_dir)/libc/imports/libc.imp)\n" >> $(1) + $(ec)$(gprintf) "import @$(call ppath,$(ndk_dir)/libc/imports/netware.imp)\n" >> $(1) + $(ec)$(gprintf) "import @$(call ppath,$(ndk_dir)/libc/imports/ws2nlm.imp)\n" >> $(1) + endef + define flm_exe_link_cmd - $(call make_lis_file_cmd,$(1),$(2),$(3),$(call hostpath,$(1)/$(2).lis)) - $(ec)$(call hostpath,$(exe_linker)) @$(call hostpath,$(1)/$(2).lis) + $(call $(if $(netware_ring_0_target),make_ring_0_imp_file_cmd,make_libc_imp_file_cmd),$(call hostpath,$(1)/$(2).imp)) + $(call $(if $(netware_ring_0_target),make_ring_0_lis_file_cmd,make_libc_lis_file_cmd),$(1),$(2),$(3),$(call hostpath,$(1)/$(2).lis)) + $(ec)$(call hostpath,$(exe_linker)) @$(call hostpath,$(1)/$(2).lis) @$(call hostpath,$(1)/$(2).imp) $(ec)$(call rmcmd,$(target_path)/$(1).lis) + $(ec)$(call rmcmd,$(target_path)/$(1).imp) endef endif @@ -2047,6 +2248,10 @@ osx: nlm: $(ec)$(gprintf) "" +.PHONY : ring0 +ring0: + $(ec)$(gprintf) "" + .PHONY : verbose verbose: $(ec)$(gprintf) "" diff --git a/xflaim/sample/sample.cpp b/xflaim/sample/sample.cpp index b3ad1b7..263079b 100644 --- a/xflaim/sample/sample.cpp +++ b/xflaim/sample/sample.cpp @@ -58,10 +58,14 @@ RCODE processAttributes( IF_DOMNode * pNode, FLMBYTE ** ppszLine); +#ifdef FLM_RING_ZERO_NLM + #define main nlm_main +#endif + /*************************************************************************** Desc: Program entry point (main) ****************************************************************************/ -int main( +extern "C" int main( int, // iArgC, char ** // ppucArgV ) @@ -138,7 +142,7 @@ int main( RetryCreate: - memset( &createOpts, 0, sizeof( XFLM_CREATE_OPTS)); + f_memset( &createOpts, 0, sizeof( XFLM_CREATE_OPTS)); if( RC_BAD( rc = pDbSystem->dbCreate( DB_NAME_STR, NULL, NULL, NULL, NULL, &createOpts, &pDb))) @@ -506,8 +510,8 @@ RetryCreate: } bTranStarted = TRUE; - if ( RC_BAD( rc = pDbSystem->openBufferIStream( pszIndex, strlen( pszIndex), - &pPosIStream))) + if ( RC_BAD( rc = pDbSystem->openBufferIStream( pszIndex, + f_strlen( pszIndex), &pPosIStream))) { goto Exit; } @@ -551,7 +555,7 @@ RetryCreate: // We will first need an input file stream. uiLoop = 0; - while( strlen( ppszPath[ uiLoop])) + while( f_strlen( ppszPath[ uiLoop])) { if( RC_BAD( rc = pDbSystem->openFileIStream( ppszPath[ uiLoop], &pIStream))) @@ -630,7 +634,7 @@ RetryCreate: goto Exit; } - sprintf( (char *)&ucMsgBuf[0], "DocId: %"UI64FormatStr"\n%s\n", + f_sprintf( (char *)&ucMsgBuf[0], "DocId: %"UI64FormatStr"\n%s\n", ui64DocId, ucTitle); printMessage( (char *)&ucMsgBuf[0]); @@ -644,7 +648,7 @@ RetryCreate: if (uiCurrentKeyLen == uiUntilKeyLen) { - if (memcmp( ucCurrentKeyBuf, ucUntilKeyBuf, uiCurrentKeyLen) == 0) + if( f_memcmp( ucCurrentKeyBuf, ucUntilKeyBuf, uiCurrentKeyLen) == 0) { // We are done! @@ -833,7 +837,7 @@ Exit: if( RC_BAD( rc)) { - sprintf( (char *)ucMsgBuf, "Error 0x%04X\n", + f_sprintf( (char *)ucMsgBuf, "Error 0x%04X\n", (unsigned)rc); printMessage( (char *)ucMsgBuf); } @@ -857,10 +861,10 @@ void printMessage( for (uiLoop = 0; uiLoop < uiLevel; uiLoop++) { - printf( " "); + f_printf( " "); } - printf( "%s\n", pszMessage); + f_printf( "%s\n", pszMessage); } /*============================================================================= @@ -912,13 +916,13 @@ RCODE printDocument( { if (!bUnwinding) { - sprintf( (char *)pszLine, ""); + f_sprintf( (char *)pszLine, ""); } - pszLine += strlen( (char *)pszLine); + pszLine += f_strlen( (char *)pszLine); } else if( eNodeType == ELEMENT_NODE) { @@ -930,13 +934,13 @@ RCODE printDocument( if (!bUnwinding) { - sprintf( (char *)pszLine, "<%s", szName); + f_sprintf( (char *)pszLine, "<%s", szName); } else { - sprintf( (char *)pszLine, "", szName); + f_sprintf( (char *)pszLine, "", szName); } - pszLine += strlen( (char *)pszLine); + pszLine += f_strlen( (char *)pszLine); } if (!bUnwinding) @@ -963,7 +967,7 @@ RCODE printDocument( if( eNodeType == COMMENT_NODE) { - sprintf( (char *)pszLine, ""); + f_sprintf( (char *)pszLine, "-->"); pszLine += 3; } } @@ -1002,12 +1006,12 @@ RCODE printDocument( { if ( !bHasChildren) { - sprintf( (char *)pszLine, "/>"); + f_sprintf( (char *)pszLine, "/>"); pszLine += 2; } else { - sprintf( (char *)pszLine, ">"); + f_sprintf( (char *)pszLine, ">"); pszLine++; } } @@ -1120,7 +1124,7 @@ RCODE processAttributes( goto Exit; } - sprintf( (char *)pszLine, " %s", szName); + f_sprintf( (char *)pszLine, " %s", szName); pszLine += (uiNameLen + 1); if (RC_BAD( rc = pAttrNode->getDataType( pDb, &uiDataType))) @@ -1137,7 +1141,7 @@ RCODE processAttributes( { goto Exit; } - sprintf( (char *)pszLine, "=\"%s\"", szTemp); + f_sprintf( (char *)pszLine, "=\"%s\"", szTemp); pszLine += (uiTemp + 3); break; } @@ -1149,9 +1153,9 @@ RCODE processAttributes( goto Exit; } - sprintf( (char *)szTemp, "%u", (unsigned)uiTemp); - sprintf( (char *)pszLine, "=\"%s\"", szTemp); - pszLine += (strlen( (char *)szTemp) + 3); + f_sprintf( (char *)szTemp, "%u", (unsigned)uiTemp); + f_sprintf( (char *)pszLine, "=\"%s\"", szTemp); + pszLine += (f_strlen( (char *)szTemp) + 3); break; } // Could also get binary data, but we won't handle it here. diff --git a/xflaim/src/flaimsys.h b/xflaim/src/flaimsys.h index 53c870a..7c792d1 100644 --- a/xflaim/src/flaimsys.h +++ b/xflaim/src/flaimsys.h @@ -4712,7 +4712,13 @@ public: virtual ~F_DbSystem(); - virtual FLMINT FLMAPI AddRef( void); + virtual FLMINT FLMAPI AddRef( + FLMBOOL bSysDataLocked); + + virtual FLMINT FLMAPI AddRef( void) + { + return( AddRef( FALSE)); + } virtual FLMINT FLMAPI Release( void); diff --git a/xflaim/src/fsysdata.cpp b/xflaim/src/fsysdata.cpp index 1680dfe..4f0b495 100644 --- a/xflaim/src/fsysdata.cpp +++ b/xflaim/src/fsysdata.cpp @@ -1763,14 +1763,6 @@ RCODE F_DbSystem::init( void) flmAssert( !gv_bFlmStarted); - // Start the toolkit - - if( RC_BAD( rc = ftkStartup())) - { - goto Exit; - } - gv_bToolkitStarted = TRUE; - // The memset needs to be first. f_memset( &gv_XFlmSysData, 0, sizeof( FLMSYSDATA)); @@ -1875,15 +1867,18 @@ RCODE F_DbSystem::init( void) rc = RC_SET( NE_XFLM_MEM); goto Exit; } + if (RC_BAD( rc = gv_XFlmSysData.pBlockCacheMgr->initCache())) { goto Exit; } + if ((gv_XFlmSysData.pNodeCacheMgr = f_new F_NodeCacheMgr) == NULL) { rc = RC_SET( NE_XFLM_MEM); goto Exit; } + if (RC_BAD( rc = gv_XFlmSysData.pNodeCacheMgr->initCache())) { goto Exit; @@ -2240,10 +2235,12 @@ void F_DbSystem::cleanup( void) { f_mutexDestroy( &gv_XFlmSysData.hNodeCacheMutex); } + if (gv_XFlmSysData.hBlockCacheMutex != F_MUTEX_NULL) { f_mutexDestroy( &gv_XFlmSysData.hBlockCacheMutex); } + if (gv_XFlmSysData.hShareMutex != F_MUTEX_NULL) { f_mutexDestroy( &gv_XFlmSysData.hShareMutex); @@ -3115,13 +3112,24 @@ FLMBOOL FLMAPI F_DbSystem::errorIsFileCorrupt( /**************************************************************************** Desc: Increment the database system use count ****************************************************************************/ -FLMINT FLMAPI F_DbSystem::AddRef(void) +FLMINT FLMAPI F_DbSystem::AddRef( + FLMBOOL bSysDataLocked) { FLMINT iRefCnt; + + if( !bSysDataLocked) + { + lockSysData(); + } + + iRefCnt = ++m_refCnt; + + if( !bSysDataLocked) + { + unlockSysData(); + } - iRefCnt = f_atomicInc( &m_refCnt); LockModule(); - return( iRefCnt); } @@ -3132,13 +3140,32 @@ FLMINT FLMAPI F_DbSystem::Release(void) { FLMINT iRefCnt; - iRefCnt = f_atomicDec( &m_refCnt); + lockSysData(); + iRefCnt = --m_refCnt; - if (iRefCnt == 0) + if( iRefCnt == 0) { + flmAssert( !gv_pXFlmDbSystem); + unlockSysData(); delete this; } + else if( iRefCnt == 1) + { + flmAssert( this == gv_pXFlmDbSystem); + iRefCnt = 0; + m_refCnt = 0; + gv_pXFlmDbSystem = NULL; + unlockSysData(); + + delete this; + UnlockModule(); + } + else + { + unlockSysData(); + } + UnlockModule(); return( iRefCnt); } @@ -3157,6 +3184,14 @@ FLMEXP RCODE FLMAPI FlmAllocDbSystem( if( !gv_pXFlmDbSystem) { + flmAssert( !gv_bToolkitStarted); + + if( RC_BAD( rc = ftkStartup())) + { + goto Exit; + } + gv_bToolkitStarted = TRUE; + if( (pDbSystem = f_new F_DbSystem) == NULL) { rc = RC_SET( NE_XFLM_MEM); @@ -3172,8 +3207,8 @@ FLMEXP RCODE FLMAPI FlmAllocDbSystem( pDbSystem = NULL; } + gv_pXFlmDbSystem->AddRef( TRUE); *ppDbSystem = gv_pXFlmDbSystem; - (*ppDbSystem)->AddRef(); Exit: diff --git a/xflaim/util/checkdb.cpp b/xflaim/util/checkdb.cpp index f2cb4b1..890e5c3 100644 --- a/xflaim/util/checkdb.cpp +++ b/xflaim/util/checkdb.cpp @@ -230,7 +230,7 @@ static FLMBOOL gv_bSkipDomLinkVerify = FALSE; static char gv_szPassword[256]; static IF_DbSystem * gv_pDbSystem = NULL; -#ifdef FLM_WATCOM_NLM +#ifdef FLM_RING_ZERO_NLM #define main nlm_main #endif diff --git a/xflaim/util/dbdiff.cpp b/xflaim/util/dbdiff.cpp index 86ce855..8560605 100644 --- a/xflaim/util/dbdiff.cpp +++ b/xflaim/util/dbdiff.cpp @@ -229,7 +229,6 @@ RCODE F_DbDiff::diff( FlmStringAcc acc; FlmVector IndexVec1; FlmVector IndexVec2; - F_DbSystem dbSystem; //try to unlock any files currently open if ( RC_BAD( rc = dbSystem.closeUnusedFiles(0))) diff --git a/xflaim/util/diffbackups.cpp b/xflaim/util/diffbackups.cpp index 9d2aaeb..6731900 100644 --- a/xflaim/util/diffbackups.cpp +++ b/xflaim/util/diffbackups.cpp @@ -89,7 +89,6 @@ int __cdecl main( { RCODE rc = NE_XFLM_OK; int iResCode = 0; - F_DbSystem dbSystem; gv_bShutdown = FALSE; diff --git a/xflaim/util/domedit.cpp b/xflaim/util/domedit.cpp index dfcce85..a61e75c 100644 --- a/xflaim/util/domedit.cpp +++ b/xflaim/util/domedit.cpp @@ -185,7 +185,6 @@ void UIMain( void * pData) FLMUINT Rows; RCODE rc; int iResCode = 0; - F_DbSystem dbSystem; F_UNREFERENCED_PARM( pData); diff --git a/xflaim/util/fdomedt.cpp b/xflaim/util/fdomedt.cpp index ad527f3..79a13a8 100644 --- a/xflaim/util/fdomedt.cpp +++ b/xflaim/util/fdomedt.cpp @@ -1169,8 +1169,8 @@ RCODE F_DomEditor::interactiveEdit( IF_Thread * pMemManagerThrd = NULL; char * pszQuery = NULL; FLMUINT uiSzQueryBufSize; - F_DbSystem dbSystem; IF_ThreadMgr * pThreadMgr = NULL; + IF_DbSystem * pDbSystem = NULL; flmAssert( m_bSetupCalled == TRUE); flmAssert( m_pScreen != NULL); @@ -1191,6 +1191,11 @@ RCODE F_DomEditor::interactiveEdit( { goto Exit; } + + if( RC_BAD( rc = FlmAllocDbSystem( &pDbSystem))) + { + goto Exit; + } if( !m_pNameTable) { @@ -2337,7 +2342,7 @@ RCODE F_DomEditor::interactiveEdit( (void)m_pDb->getDbControlFileName( szDbPath, sizeof( szDbPath)); - if (RC_OK( tmpRc = dbSystem.dbOpen( szDbPath, + if (RC_OK( tmpRc = pDbSystem->dbOpen( szDbPath, NULL, NULL, NULL, TRUE, (IF_Db **)&pTmpDb))) @@ -2431,6 +2436,11 @@ Exit: { pThreadMgr->Release(); } + + if( pDbSystem) + { + pDbSystem->Release(); + } if( m_pEditWindow) { @@ -2873,13 +2883,19 @@ Desc: *****************************************************************************/ RCODE F_DomEditor::openNewDb( void) { - RCODE rc = NE_XFLM_OK; - char szResponse [100]; - FLMUINT uiChar; - F_DbSystem dbSystem; + RCODE rc = NE_XFLM_OK; + char szResponse [100]; + FLMUINT uiChar; + IF_DbSystem * pDbSystem = NULL; + + if( RC_BAD( rc = FlmAllocDbSystem( &pDbSystem))) + { + goto Exit; + } szResponse [0] = 0; flmAssert( m_pDb == NULL); + for (;;) { if (RC_BAD( rc = requestInput( "Enter name of DB to open", @@ -2892,7 +2908,8 @@ RCODE F_DomEditor::openNewDb( void) { break; } - if (RC_BAD( rc = dbSystem.dbOpen( szResponse, NULL, NULL, NULL, TRUE, + + if (RC_BAD( rc = pDbSystem->dbOpen( szResponse, NULL, NULL, NULL, TRUE, (IF_Db **)&m_pDb))) { displayMessage( "Unable to open database", rc, @@ -2906,6 +2923,11 @@ RCODE F_DomEditor::openNewDb( void) Exit: + if( pDbSystem) + { + pDbSystem->Release(); + } + return( rc); } @@ -5232,7 +5254,12 @@ RCODE F_DomEditor::exportNode( char szFileName [80]; eExportFormatType eFormat = XFLM_EXPORT_INDENT; IF_OStream * pFileOStream = NULL; - F_DbSystem dbSystem; + IF_DbSystem * pDbSystem = NULL; + + if( RC_BAD( rc = FlmAllocDbSystem( &pDbSystem))) + { + goto Exit; + } if (RC_BAD( rc = createStatusWindow( "Export Node Subtree", @@ -5259,9 +5286,11 @@ RCODE F_DomEditor::exportNode( { goto Exit; } - if (RC_BAD( rc = dbSystem.openFileOStream( szFileName, TRUE, &pFileOStream))) + if (RC_BAD( rc = pDbSystem->openFileOStream( szFileName, + TRUE, &pFileOStream))) { - displayMessage( "Error creating export file", rc, NULL, FLM_RED, FLM_WHITE); + displayMessage( "Error creating export file", + rc, NULL, FLM_RED, FLM_WHITE); } else { @@ -5356,6 +5385,11 @@ Exit: { FTXWinFree( &pWindow); } + + if( pDbSystem) + { + pDbSystem->Release(); + } return rc; } @@ -12661,7 +12695,7 @@ void F_DomEditor::doQuery( F_DomEditor * pQueryEditor = NULL; QUERY_DATA QueryData; FLMUINT uiQueryStrLen; - F_DbSystem dbSystem; + IF_DbSystem * pDbSystem = NULL; f_memset( &QueryData, 0, sizeof( QueryData)); @@ -12673,12 +12707,17 @@ void F_DomEditor::doQuery( goto Exit; } + if( RC_BAD( rc = FlmAllocDbSystem( &pDbSystem))) + { + goto Exit; + } + // Create a window for displaying query progress. queryStatus.createQueryStatusWindow( m_pScreen, FLM_GREEN, FLM_WHITE, pszQuery); - if (RC_BAD( rc = dbSystem.createIFQuery( &pQuery))) + if (RC_BAD( rc = pDbSystem->createIFQuery( &pQuery))) { goto Exit; } @@ -12823,8 +12862,10 @@ void F_DomEditor::doQuery( break; } } - dbSystem.freeMem( (void **)&pOptInfo); + + pDbSystem->freeMem( (void **)&pOptInfo); } + if (!QueryData.uiNodeCount) { goto Exit; @@ -12901,14 +12942,21 @@ Exit: { f_free( &QueryData.pui64Nodes); } + if (QueryData.puiAttrNameIds) { f_free( &QueryData.puiAttrNameIds); } + if (QueryData.pszQuery) { f_free( &QueryData.pszQuery); } + + if( pDbSystem) + { + pDbSystem->Release(); + } } /**************************************************************************** diff --git a/xflaim/util/flm_lutl.cpp b/xflaim/util/flm_lutl.cpp index 196e60c..db2fd80 100644 --- a/xflaim/util/flm_lutl.cpp +++ b/xflaim/util/flm_lutl.cpp @@ -227,7 +227,7 @@ RCODE flstIndexManagerThread( FLMBOOL bScreenLocked = FALSE; IX_Event event; FLMBOOL bRegisteredForEvent = FALSE; - F_DbSystem dbSystem; + IF_DbSystem * pDbSystem = NULL; event.setDispInfo( &IxDispInfo); @@ -304,8 +304,13 @@ RCODE flstIndexManagerThread( FTXWinSetScroll( IxDispInfo.pLogWin, TRUE); FTXWinSetLineWrap( IxDispInfo.pLogWin, FALSE); FTXWinOpen( IxDispInfo.pLogWin); + + if( RC_BAD( rc = FlmAllocDbSystem( &pDbSystem))) + { + goto Exit; + } - if (RC_BAD( rc = dbSystem.registerForEvent( + if (RC_BAD( rc = pDbSystem->registerForEvent( XFLM_EVENT_UPDATES, &event))) { goto Exit; @@ -799,7 +804,7 @@ Exit: if (bRegisteredForEvent) { - dbSystem.deregisterForEvent( XFLM_EVENT_UPDATES, &event); + pDbSystem->deregisterForEvent( XFLM_EVENT_UPDATES, &event); } if( IxDispInfo.pScreen) @@ -811,16 +816,16 @@ Exit: { f_mutexDestroy( &IxDispInfo.hScreenMutex); } -#if 0 - if( pRec) - { - pRec->release( &pRec); - } -#endif + if( pDb != NULL) { pDb->Release(); } + + if( pDbSystem) + { + pDbSystem->Release(); + } return( rc); } @@ -834,6 +839,7 @@ Note: The caller must pass a valid share handle to the thread on startup. RCODE flstMemoryManagerThread( IF_Thread * pThread) { + RCODE rc = NE_XFLM_OK; F_DynamicList * pList = f_new F_DynamicList; FTX_SCREEN * pScreen; FTX_WINDOW * pTitleWin; @@ -845,7 +851,7 @@ RCODE flstMemoryManagerThread( FLMUINT uiScreenCols; FLMUINT uiScreenRows; XFLM_CACHE_INFO CacheInfo; - F_DbSystem dbSystem; + IF_DbSystem * pDbSystem = NULL; #define FMMT_TITLE_HEIGHT 1 #define FMMT_HEADER_HEIGHT 3 @@ -893,6 +899,11 @@ RCODE flstMemoryManagerThread( FTXWinMove( pListWin, 0, FMMT_TITLE_HEIGHT + FMMT_HEADER_HEIGHT); FTXWinOpen( pListWin); pList->setup( pListWin); + + if( RC_BAD( rc = FlmAllocDbSystem( &pDbSystem))) + { + goto Exit; + } uiLoop = 0; while( !gv_bShutdown) @@ -903,7 +914,7 @@ RCODE flstMemoryManagerThread( XFLM_CACHE_USAGE * pBlkCacheUse = &CacheInfo.BlockCache; XFLM_CACHE_USAGE * pNodeCacheUse = &CacheInfo.NodeCache; - dbSystem.getCacheInfo( &CacheInfo); + pDbSystem->getCacheInfo( &CacheInfo); f_sprintf( szTmpBuf, " Maximum Cache Bytes............... %10u", (unsigned)CacheInfo.uiMaxBytes); @@ -1068,7 +1079,7 @@ RCODE flstMemoryManagerThread( { case 'R': case 'r': - dbSystem.resetStats(); + pDbSystem->resetStats(); break; case FKB_UP: pList->cursorUp(); @@ -1114,6 +1125,11 @@ Exit: { FTXScreenFree( &pScreen); } + + if( pDbSystem) + { + pDbSystem->Release(); + } - return( NE_XFLM_OK); + return( rc); } diff --git a/xflaim/util/flmunittest.cpp b/xflaim/util/flmunittest.cpp index efd1147..e3301a0 100644 --- a/xflaim/util/flmunittest.cpp +++ b/xflaim/util/flmunittest.cpp @@ -44,6 +44,10 @@ FLMBOOL gv_bShutdown = FALSE; extern RCODE getTest( IFlmTest ** ppTest); +#ifdef FLM_RING_ZERO_NLM + #define main nlm_main +#endif + struct TEST_INFO { bool bLog; @@ -202,7 +206,9 @@ void printHelp() /**************************************************************************** Desc: ****************************************************************************/ -int main( int argc, char ** argv) +extern "C" int main( + int argc, + char ** argv) { RCODE rc = NE_XFLM_OK; IFlmTest * pTest = NULL; @@ -415,13 +421,15 @@ FLMBOOL FlagSet::removeElem( FLMBYTE * pElem) bElemExisted = TRUE; if ( uiLoop < m_uiNumElems - 1) { - delete[] m_ppucElemArray[ uiLoop]; + f_free( &m_ppucElemArray[ uiLoop]); + f_memmove( &m_ppucElemArray[ uiLoop], &m_ppucElemArray[ uiLoop + 1], - ( m_uiNumElems - ( uiLoop + 1)) * sizeof( FLMBYTE *)); + (m_uiNumElems - ( uiLoop + 1)) * sizeof( FLMBYTE *)); + f_memmove( &m_pbFlagArray[ uiLoop], &m_pbFlagArray[ uiLoop + 1], - ( m_uiNumElems - ( uiLoop + 1)) * sizeof( FLMBYTE *)); + (m_uiNumElems - ( uiLoop + 1)) * sizeof( FLMBYTE *)); } // Otherwise, we're at the end and decrementing to counter will suffice @@ -492,17 +500,21 @@ FlagSet FlagSet::crossProduct( FlagSet& fs2) FlagSet fsCross; FLMUINT uiLoop1; FLMUINT uiCrossProductElems = this->getNumElements() * fs2.getNumElements(); - FLMBYTE ** ppszCross = new FLMBYTE*[ uiCrossProductElems]; + FLMBYTE ** ppszCross; + + + f_alloc( sizeof( FLMBYTE *) * uiCrossProductElems, &ppszCross); for ( uiLoop1 = 0; uiLoop1 < this->getNumElements(); uiLoop1++) { for ( FLMUINT uiLoop2 = 0; uiLoop2 < fs2.getNumElements(); uiLoop2++) { - FLMUINT uiIndex = uiLoop1 * fs2.getNumElements() + uiLoop2; - ppszCross[ uiIndex] = new FLMBYTE[ + FLMUINT uiIndex = uiLoop1 * fs2.getNumElements() + uiLoop2; + f_alloc( f_strlen( (char *)this->m_ppucElemArray[ uiLoop1]) + - f_strlen( (char *)fs2.m_ppucElemArray[ uiLoop2]) + 1]; - + f_strlen( (char *)fs2.m_ppucElemArray[ uiLoop2]) + 1, + &ppszCross[ uiIndex]); + f_strcpy( (char *)ppszCross[ uiIndex], (char *)this->m_ppucElemArray[ uiLoop1]); f_strcat( (char *)ppszCross[ uiIndex], (char *)fs2.m_ppucElemArray[ uiLoop2]); } @@ -511,11 +523,11 @@ FlagSet FlagSet::crossProduct( FlagSet& fs2) for( uiLoop1 = 0; uiLoop1 < uiCrossProductElems; uiLoop1++) { - delete[] ppszCross[ uiLoop1]; + f_free( &ppszCross[ uiLoop1]); } - delete[] ppszCross; - - return fsCross; + + f_free( &ppszCross); + return( fsCross); } /**************************************************************************** @@ -539,12 +551,14 @@ Desc: ****************************************************************************/ FlagSet::FlagSet( const FlagSet& fs) { - m_ppucElemArray = new FLMBYTE*[ fs.m_uiNumElems]; - m_pbFlagArray = new FLMBOOL[ fs.m_uiNumElems]; + f_alloc( sizeof( FLMBYTE *) * fs.m_uiNumElems, &m_ppucElemArray); + f_alloc( sizeof( FLMBOOL) * fs.m_uiNumElems, &m_pbFlagArray); + f_memset( m_pbFlagArray, 0, sizeof( FLMBOOL) * fs.m_uiNumElems); for ( FLMUINT uiLoop = 0; uiLoop < fs.m_uiNumElems; uiLoop++) { - m_ppucElemArray[uiLoop] = new FLMBYTE[ f_strlen( (char *)fs.m_ppucElemArray[uiLoop]) + 1]; + f_alloc( f_strlen( (char *)fs.m_ppucElemArray[uiLoop]) + 1, + &m_ppucElemArray[ uiLoop]); f_strcpy( (char *)m_ppucElemArray[uiLoop], (char *)fs.m_ppucElemArray[uiLoop]); } m_uiNumElems = fs.m_uiNumElems; @@ -557,10 +571,11 @@ void FlagSet::reset() { for( FLMUINT uiLoop = 0; uiLoop < m_uiNumElems; uiLoop++) { - delete [] m_ppucElemArray[ uiLoop]; + f_free( &m_ppucElemArray[ uiLoop]); } - delete[] m_ppucElemArray; - delete[] m_pbFlagArray; + + f_free( &m_ppucElemArray); + f_free( &m_pbFlagArray); m_uiNumElems = 0; m_ppucElemArray = NULL; @@ -573,14 +588,18 @@ Desc: void FlagSet::init( FLMBYTE ** ppucElemArray, FLMUINT uiNumElems) { reset(); - m_ppucElemArray = new FLMBYTE*[ uiNumElems]; - m_pbFlagArray = new FLMBOOL[ uiNumElems]; + + f_alloc( sizeof( FLMBYTE *) * uiNumElems, &m_ppucElemArray); + f_alloc( sizeof( FLMBOOL) * uiNumElems, &m_pbFlagArray); + f_memset( m_pbFlagArray, 0, sizeof( FLMBOOL) * uiNumElems); for ( FLMUINT uiLoop = 0; uiLoop < uiNumElems; uiLoop++) { - m_ppucElemArray[uiLoop] = new FLMBYTE[ f_strlen( (char *)ppucElemArray[uiLoop]) + 1]; + f_alloc( f_strlen( (char *)ppucElemArray[uiLoop]) + 1, + &m_ppucElemArray[ uiLoop]); f_strcpy( (char *)m_ppucElemArray[uiLoop], (char *)ppucElemArray[uiLoop]); } + m_uiNumElems = uiNumElems; } @@ -667,9 +686,13 @@ RCODE createUnitTest( #ifdef FLM_WIN { - char * temp = new char[ size]; + char * temp; + f_alloc( size, &temp); + char * tempbegin = temp; size_t newsize = size; + + for( unsigned int i = 0; i < size; i++) { @@ -1016,12 +1039,12 @@ void TestBase::displayTime( if( pszIntro) { - pszTempBuf = new char[ f_strlen( pszIntro) + sizeof( szTimeBuf)]; + f_alloc( f_strlen( pszIntro) + sizeof( szTimeBuf), &pszTempBuf); f_strcpy( pszTempBuf, pszIntro); } else { - pszTempBuf = new char[ f_strlen( pszDefault) + sizeof( szTimeBuf)]; + f_alloc( f_strlen( pszDefault) + sizeof( szTimeBuf), &pszTempBuf); f_strcpy( pszTempBuf, pszDefault); } diff --git a/xflaim/util/flmunittest.h b/xflaim/util/flmunittest.h index de3c1d4..d56fff6 100644 --- a/xflaim/util/flmunittest.h +++ b/xflaim/util/flmunittest.h @@ -223,7 +223,7 @@ public: /****************************************************************************** Desc: Makes iterating through the keys of an index more convenient ******************************************************************************/ -class KeyIterator +class KeyIterator : public F_Object { public: diff --git a/xflaim/util/fshell.cpp b/xflaim/util/fshell.cpp index b7baa7c..236eee3 100644 --- a/xflaim/util/fshell.cpp +++ b/xflaim/util/fshell.cpp @@ -1869,12 +1869,12 @@ FLMINT FlmDbOpenCommand::execute( IF_Db * pDb = NULL; FLMUINT uiDbId; RCODE rc = NE_XFLM_OK; - F_DbSystem dbSystem; char * pszRflDir = NULL; char * pszPassword = NULL; char * pszAllowLimited; FLMBOOL bAllowLimited = FALSE; - + IF_DbSystem * pDbSystem = NULL; + if( iArgC < 2) { pShell->con_printf( "Wrong number of parameters.\n"); @@ -1902,7 +1902,12 @@ FLMINT FlmDbOpenCommand::execute( } } - if( RC_BAD( rc = dbSystem.dbOpen( ppszArgV[ 1], + if( RC_BAD( rc = FlmAllocDbSystem( &pDbSystem))) + { + goto Exit; + } + + if( RC_BAD( rc = pDbSystem->dbOpen( ppszArgV[ 1], NULL, pszRflDir, pszPassword, bAllowLimited, &pDb))) { if( rc != NE_FLM_IO_PATH_NOT_FOUND) @@ -1910,7 +1915,7 @@ FLMINT FlmDbOpenCommand::execute( goto Exit; } - if( RC_BAD( rc = dbSystem.dbCreate( + if( RC_BAD( rc = pDbSystem->dbCreate( ppszArgV[ 1], NULL, pszRflDir, NULL, NULL, NULL, &pDb))) { goto Exit; @@ -1931,6 +1936,11 @@ Exit: { pDb->Release(); } + + if( pDbSystem) + { + pDbSystem->Release(); + } if( RC_BAD( rc)) { @@ -1979,11 +1989,11 @@ FLMINT FlmDbCloseCommand::execute( char ** ppszArgV, FlmShell * pShell) { + RCODE rc = NE_XFLM_OK; FLMINT iExitCode = 0; FLMUINT uiDbId; - IF_Db * pDb; - RCODE rc = NE_XFLM_OK; - F_DbSystem dbSystem; + IF_Db * pDb = NULL; + IF_DbSystem * pDbSystem = NULL; if( iArgC != 2) { @@ -1992,9 +2002,14 @@ FLMINT FlmDbCloseCommand::execute( goto Exit; } + if( RC_BAD( rc = FlmAllocDbSystem( &pDbSystem))) + { + goto Exit; + } + if( !f_stricmp( ppszArgV[ 1], "kill")) { - dbSystem.deactivateOpenDb( NULL, NULL); + pDbSystem->deactivateOpenDb( NULL, NULL); pShell->con_printf( "All handles killed, but not necessarily closed.\n"); } else if( !f_stricmp( ppszArgV[ 1], "all")) @@ -2017,7 +2032,7 @@ FLMINT FlmDbCloseCommand::execute( } } - dbSystem.closeUnusedFiles( 0); + pDbSystem->closeUnusedFiles( 0); } else { @@ -2044,6 +2059,11 @@ FLMINT FlmDbCloseCommand::execute( Exit: + if( pDbSystem) + { + pDbSystem->Release(); + } + if( RC_BAD( rc)) { pShell->con_printf( "Error closing database: %e\n", rc); @@ -2361,9 +2381,9 @@ FLMINT FlmDbManageCommand::execute( char ** ppszArgV, FlmShell * pShell) { - FLMINT iExitCode = 0; RCODE rc = NE_XFLM_OK; - F_DbSystem dbSystem; + FLMINT iExitCode = 0; + IF_DbSystem * pDbSystem = NULL; if( iArgC < 2) { @@ -2372,9 +2392,14 @@ FLMINT FlmDbManageCommand::execute( goto Exit; } + if( RC_BAD( rc = FlmAllocDbSystem( &pDbSystem))) + { + goto Exit; + } + if (f_stricmp( ppszArgV [0], "dbremove") == 0) { - if (RC_BAD( rc = dbSystem.dbRemove( ppszArgV[ 1], NULL, NULL, TRUE))) + if (RC_BAD( rc = pDbSystem->dbRemove( ppszArgV[ 1], NULL, NULL, TRUE))) { goto Exit; } @@ -2391,7 +2416,7 @@ FLMINT FlmDbManageCommand::execute( { FSHELL_CopyStatus copyStatus( pShell); - if (RC_BAD( rc = dbSystem.dbCopy( ppszArgV [1], NULL, NULL, + if (RC_BAD( rc = pDbSystem->dbCopy( ppszArgV [1], NULL, NULL, ppszArgV [2], NULL, NULL, ©Status))) { goto Exit; @@ -2402,7 +2427,7 @@ FLMINT FlmDbManageCommand::execute( { FSHELL_RenameStatus renameStatus( pShell); - if (RC_BAD( rc = dbSystem.dbRename( ppszArgV [1], NULL, NULL, + if (RC_BAD( rc = pDbSystem->dbRename( ppszArgV [1], NULL, NULL, ppszArgV [2], TRUE, &renameStatus))) { goto Exit; @@ -2413,6 +2438,11 @@ FLMINT FlmDbManageCommand::execute( Exit: + if( pDbSystem) + { + pDbSystem->Release(); + } + if( RC_BAD( rc)) { pShell->con_printf( "\nError: %e\n", rc); @@ -2708,8 +2738,8 @@ FLMINT FlmRestoreCommand::execute( F_LocalRestore * pRestore = NULL; F_LocalRestoreStatus restoreStatus( pShell); RCODE rc = NE_XFLM_OK; - F_DbSystem dbSystem; FLMBOOL bUsePasswd = FALSE; + IF_DbSystem * pDbSystem = NULL; if( iArgC < 3) { @@ -2717,15 +2747,22 @@ FLMINT FlmRestoreCommand::execute( iExitCode = -1; goto Exit; } + if( iArgC > 3) { bUsePasswd = TRUE; } + if( iArgC > 4) { pszRflDir = ppszArgV[ 4]; } + if( RC_BAD( rc = FlmAllocDbSystem( &pDbSystem))) + { + goto Exit; + } + if( (pRestore = f_new F_LocalRestore) == NULL) { rc = RC_SET( NE_XFLM_MEM); @@ -2738,7 +2775,7 @@ FLMINT FlmRestoreCommand::execute( goto Exit; } - if( RC_BAD( rc = dbSystem.dbRestore( ppszArgV[ 1], NULL, NULL, NULL, + if( RC_BAD( rc = pDbSystem->dbRestore( ppszArgV[ 1], NULL, NULL, NULL, bUsePasswd?ppszArgV[3]:NULL, pRestore, &restoreStatus))) { goto Exit; @@ -2761,6 +2798,11 @@ Exit: { pRestore->Release(); } + + if( pDbSystem) + { + pDbSystem->Release(); + } return( iExitCode); } @@ -3514,7 +3556,12 @@ FLMINT FlmSysInfoCommand::execute( FTX_WINDOW * pWin = pShell->getWindow(); FLMUINT uiLoop; IF_ThreadInfo * pThreadInfo = NULL; - F_DbSystem dbSystem; + IF_DbSystem * pDbSystem = NULL; + + if( RC_BAD( rc = FlmAllocDbSystem( &pDbSystem))) + { + goto Exit; + } if( iArgC < 2) { @@ -3658,7 +3705,7 @@ FLMINT FlmSysInfoCommand::execute( pThreadInfo->Release(); pThreadInfo = NULL; } - if( RC_BAD( rc = dbSystem.getThreadInfo( &pThreadInfo))) + if( RC_BAD( rc = pDbSystem->getThreadInfo( &pThreadInfo))) { goto Exit; } @@ -3716,6 +3763,11 @@ Exit: { pThreadInfo->Release(); } + + if( pDbSystem) + { + pDbSystem->Release(); + } return( iExitCode); } @@ -5499,12 +5551,12 @@ FLMINT FlmDomEditCommand::execute( char szTitle[ 80]; FLMUINT Cols; FLMUINT Rows; - F_DbSystem dbSystem; IF_Db * pNewDb = NULL; char * pszRflDir = NULL; char * pszPassword = NULL; char * pszAllowLimited; FLMBOOL bAllowLimited = FALSE; + IF_DbSystem * pDbSystem = NULL; if( iArgC < 1) { @@ -5513,6 +5565,11 @@ FLMINT FlmDomEditCommand::execute( goto Exit; } + if( RC_BAD( rc = FlmAllocDbSystem( &pDbSystem))) + { + goto Exit; + } + if( iArgC >= 2) { char * pszName = ppszArgV [1]; @@ -5548,7 +5605,7 @@ FLMINT FlmDomEditCommand::execute( } } - if( RC_BAD( rc = dbSystem.dbOpen( ppszArgV[ 1], + if( RC_BAD( rc = pDbSystem->dbOpen( ppszArgV[ 1], NULL, pszRflDir, pszPassword, bAllowLimited, &pNewDb))) { pShell->con_printf( "Error opening database: %e.\n", rc); @@ -5649,9 +5706,13 @@ Exit: pDomEditor->Release(); pDomEditor = NULL; } + + if( pDbSystem) + { + pDbSystem->Release(); + } FTXScreenFree( &pScreen); - return( iExitCode); } @@ -5706,8 +5767,8 @@ FLMINT FlmExportCommand::execute( FLMUINT uiDocNum = 0; FLMUINT uiCollection = XFLM_DATA_COLLECTION; FLMBOOL bAllDocs = TRUE; - F_DbSystem dbSystem; eExportFormatType eFormat = XFLM_EXPORT_INDENT; + IF_DbSystem * pDbSystem = NULL; if( iArgC < 2) { @@ -5716,7 +5777,12 @@ FLMINT FlmExportCommand::execute( goto Exit; } - if( RC_BAD( rc = dbSystem.openFileOStream( ppszArgV[ 1], + if( RC_BAD( rc = FlmAllocDbSystem( &pDbSystem))) + { + goto Exit; + } + + if( RC_BAD( rc = pDbSystem->openFileOStream( ppszArgV[ 1], TRUE, &pFileOStream))) { pShell->con_printf( "Unable to create file: %s.\n", ppszArgV[1]); @@ -5856,6 +5922,11 @@ Exit: { pFileOStream->Release(); } + + if( pDbSystem) + { + pDbSystem->Release(); + } return( iExitCode); } @@ -6108,7 +6179,6 @@ FLMBOOL domDisplayNodeInfo( { RCODE rc = NE_XFLM_OK; FLMBOOL bOk = FALSE; - F_DbSystem dbSystem; IF_NodeInfo * pNodeInfo = NULL; XFLM_NODE_INFO nodeInfo; IF_DOMNode * pNode = NULL; @@ -6119,6 +6189,12 @@ FLMBOOL domDisplayNodeInfo( FLMUINT uiChar; IF_FileHdl * pFileHdl = NULL; FLMUINT uiLineCount; + IF_DbSystem * pDbSystem = NULL; + + if( RC_BAD( rc = FlmAllocDbSystem( &pDbSystem))) + { + goto Exit; + } // If there is a file name, attempt to create it @@ -6141,7 +6217,7 @@ FLMBOOL domDisplayNodeInfo( } } - if (RC_BAD( rc = dbSystem.createIFNodeInfo( &pNodeInfo))) + if (RC_BAD( rc = pDbSystem->createIFNodeInfo( &pNodeInfo))) { domDisplayError( pWindow, "Error calling createIFNodeInfo", rc); goto Exit; @@ -6394,6 +6470,12 @@ Exit: { pFileHdl->Release(); } + + if( pDbSystem) + { + pDbSystem->Release(); + } + return( bOk); } @@ -8025,7 +8107,6 @@ FLMBOOL domDisplayBTreeInfo( { RCODE rc = NE_XFLM_OK; FLMBOOL bOk = FALSE; - F_DbSystem dbSystem; IF_BTreeInfo * pBTreeInfo = NULL; SH_BTreeInfoStatus infoStatus( pWindow); FLMUINT uiIndexCount; @@ -8043,6 +8124,12 @@ FLMBOOL domDisplayBTreeInfo( FLMUINT uiLineCount; char szBuf [100]; XFLM_BTREE_LEVEL_INFO levelInfo; + IF_DbSystem * pDbSystem = NULL; + + if( RC_BAD( rc = FlmAllocDbSystem( &pDbSystem))) + { + goto Exit; + } // If there is a file name, attempt to create it @@ -8065,7 +8152,7 @@ FLMBOOL domDisplayBTreeInfo( } } - if (RC_BAD( rc = dbSystem.createIFBTreeInfo( &pBTreeInfo))) + if (RC_BAD( rc = pDbSystem->createIFBTreeInfo( &pBTreeInfo))) { domDisplayError( pWindow, "Error calling createIFNodeInfo", rc); goto Exit; @@ -8391,6 +8478,12 @@ Exit: { pFileHdl->Release(); } + + if( pDbSystem) + { + pDbSystem->Release(); + } + return( bOk); } diff --git a/xflaim/util/indextest1srv.cpp b/xflaim/util/indextest1srv.cpp index 8da9990..164a473 100644 --- a/xflaim/util/indextest1srv.cpp +++ b/xflaim/util/indextest1srv.cpp @@ -148,7 +148,7 @@ RCODE IIndexTest1Impl::execute( void) FLMUINT64 ui64LennonId = 0; FLMUINT64 ui64NodeId; FLMBYTE szBuf[ 128]; - KeyIterator * pKeyIter = new KeyIterator; + KeyIterator * pKeyIter = f_new KeyIterator; FlagSet beatlesFNFlags; FlagSet beatlesLNFlags; FlagSet FNPlusLNFlags; @@ -574,8 +574,8 @@ RCODE IIndexTest1Impl::execute( void) // cross product of pszFirstNames1 and pszLastNames1. pKeyIter->reset(); - - pucTemp = new FLMBYTE[ sizeof( szBuf) * 2 + 1]; + f_alloc( sizeof( szBuf) * 2 + 1, &pucTemp); + while( RC_OK( rc = pKeyIter->next())) { if ( RC_BAD( rc = pKeyIter->getCurrentKeyVal( 0, szBuf, @@ -604,8 +604,7 @@ RCODE IIndexTest1Impl::execute( void) } } - delete[] pucTemp; - pucTemp = NULL; + f_free( &pucTemp); if( rc != NE_XFLM_EOF_HIT) { @@ -659,7 +658,8 @@ RCODE IIndexTest1Impl::execute( void) // in the flag set, we'll get an error. pKeyIter->reset(); - pucTemp = new FLMBYTE[ sizeof( szBuf) * 2 + 1]; + f_alloc( sizeof( szBuf) * 2 + 1, &pucTemp); + while( RC_OK( rc = pKeyIter->next())) { if ( RC_BAD( rc = pKeyIter->getCurrentKeyVal( @@ -690,8 +690,7 @@ RCODE IIndexTest1Impl::execute( void) } } - delete [] pucTemp; - pucTemp = NULL; + f_free( &pucTemp); if( rc != NE_XFLM_EOF_HIT) { @@ -737,7 +736,7 @@ RCODE IIndexTest1Impl::execute( void) // in the flag set, we'll get an error. pKeyIter->reset(); - pucTemp = new FLMBYTE[ sizeof( szBuf) * 2 + 1]; + f_alloc( sizeof( szBuf) * 2 + 1, &pucTemp); while( RC_OK( rc = pKeyIter->next())) { if( RC_BAD( rc = pKeyIter->getCurrentKeyVal( 0, szBuf, sizeof( szBuf), @@ -765,8 +764,7 @@ RCODE IIndexTest1Impl::execute( void) } } - delete [] pucTemp; - pucTemp = NULL; + f_free( &pucTemp); if( rc != NE_XFLM_EOF_HIT) { @@ -839,7 +837,7 @@ RCODE IIndexTest1Impl::execute( void) pKeyIter->setIndexNum( 77); contextFlags.init( (FLMBYTE **)ppszLegalKeys, sizeof( ppszLegalKeys)/sizeof( ppszLegalKeys[0])); - pucTemp = new FLMBYTE[ sizeof( szBuf) * 3 + 1]; + f_alloc( sizeof( szBuf) * 3 + 1, &pucTemp); while( RC_OK( rc = pKeyIter->next())) { @@ -877,8 +875,7 @@ RCODE IIndexTest1Impl::execute( void) } } - delete [] pucTemp; - pucTemp = NULL; + f_free( &pucTemp); if( rc != NE_XFLM_EOF_HIT) { @@ -911,7 +908,7 @@ Exit: if( pucTemp) { - delete [] pucTemp; + f_free( &pucTemp); } if( pNode) @@ -944,7 +941,7 @@ Exit: if( pKeyIter) { - delete pKeyIter; + pKeyIter->Release(); } shutdownTestState( DB_NAME_STR, !bDibCreated); diff --git a/xflaim/util/indextest2srv.cpp b/xflaim/util/indextest2srv.cpp index 86429a7..db7bc5a 100644 --- a/xflaim/util/indextest2srv.cpp +++ b/xflaim/util/indextest2srv.cpp @@ -118,7 +118,7 @@ RCODE IIndexTest2Impl::runSuite1( void) FLMUINT i = 0; FlagSet firstNamePlusLastNameFlags; IF_Query * pQuery = NULL; - KeyIterator * pKeyIter = new KeyIterator(); + KeyIterator * pKeyIter = f_new KeyIterator(); const char * pszIndexDef1 = "Release(); } shutdownTestState( DB_NAME_STR, bDibCreated); diff --git a/xflaim/util/view.cpp b/xflaim/util/view.cpp index baacdf8..359bac7 100644 --- a/xflaim/util/view.cpp +++ b/xflaim/util/view.cpp @@ -61,10 +61,14 @@ static FLMBOOL bPauseBeforeExiting = FALSE; FLMUINT gv_uiTopLine = 0; FLMUINT gv_uiBottomLine = 0; +#ifdef FLM_RING_ZERO_NLM + #define main nlm_main +#endif + /******************************************************************** Desc: ? *********************************************************************/ -int main( +extern "C" int main( int iArgC, char ** ppszArgV) { diff --git a/xflaim/util/xshell.cpp b/xflaim/util/xshell.cpp index 6988722..6fdaf72 100644 --- a/xflaim/util/xshell.cpp +++ b/xflaim/util/xshell.cpp @@ -30,17 +30,21 @@ static FlmSharedContext * gv_pSharedContext = NULL; FLMBOOL gv_bShutdown = FALSE; FLMBOOL gv_bRunning = TRUE; +#ifdef FLM_RING_ZERO_NLM + #define main nlm_main +#endif + /*************************************************************************** Desc: Program entry point (main) ****************************************************************************/ -int main( +extern "C" int main( int, // iArgC, char **) // ppucArgV { RCODE rc = NE_XFLM_OK; FlmShell * pShell = NULL; IF_DbSystem * pDbSystem = NULL; - + if( RC_BAD( rc = FlmAllocDbSystem( &pDbSystem))) { goto Exit;