From 388ee249950934e887d57a6c8142fd5f3e541396 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 4 Nov 2008 22:05:57 +0000 Subject: [PATCH] 2008-11-04 23:03 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * common.mak * source/vm/Makefile * source/vm/vmmt/Makefile * source/vm/fm.c + source/vm/fmhb.c + source/vm/hbmem.c + Moved functions not depending on FM_STATISTICS setting, to separate files. ; NOTE: MEMORY() function should IMO move to rtl, and hb_xmem*() functions to common lib. --- harbour/ChangeLog | 12 +++ harbour/common.mak | 2 + harbour/source/vm/Makefile | 2 + harbour/source/vm/fm.c | 113 ++++----------------------- harbour/source/vm/fmhb.c | 58 ++++++++++++++ harbour/source/vm/hbmem.c | 133 ++++++++++++++++++++++++++++++++ harbour/source/vm/vmmt/Makefile | 2 + 7 files changed, 223 insertions(+), 99 deletions(-) create mode 100644 harbour/source/vm/fmhb.c create mode 100644 harbour/source/vm/hbmem.c diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f0b84c5741..36b9da8225 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,18 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-11-04 23:03 UTC+0200 Viktor Szakats (harbour.01 syenar hu) + * common.mak + * source/vm/Makefile + * source/vm/vmmt/Makefile + * source/vm/fm.c + + source/vm/fmhb.c + + source/vm/hbmem.c + + Moved functions not depending on FM_STATISTICS setting, + to separate files. + ; NOTE: MEMORY() function should IMO move to rtl, and + hb_xmem*() functions to common lib. + 2008-11-04 22:53 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * include/hbextern.ch + Added new HB_H*() functions. diff --git a/harbour/common.mak b/harbour/common.mak index 0483c09702..0b8f405de9 100644 --- a/harbour/common.mak +++ b/harbour/common.mak @@ -421,9 +421,11 @@ VM_COMMON_LIB_OBJS = \ $(OBJ_DIR)\extend$(OBJEXT) \ $(OBJ_DIR)\extrap$(OBJEXT) \ $(OBJ_DIR)\fm$(OBJEXT) \ + $(OBJ_DIR)\fmhb$(OBJEXT) \ $(OBJ_DIR)\garbage$(OBJEXT) \ $(OBJ_DIR)\hashes$(OBJEXT) \ $(OBJ_DIR)\hashfunc$(OBJEXT) \ + $(OBJ_DIR)\hbmem$(OBJEXT) \ $(OBJ_DIR)\hvm$(OBJEXT) \ $(OBJ_DIR)\initexit$(OBJEXT) \ $(OBJ_DIR)\initsymb$(OBJEXT) \ diff --git a/harbour/source/vm/Makefile b/harbour/source/vm/Makefile index 112f017c60..66c76ef15f 100644 --- a/harbour/source/vm/Makefile +++ b/harbour/source/vm/Makefile @@ -42,9 +42,11 @@ C_SOURCES=\ extend.c \ extrap.c \ fm.c \ + fmhb.c \ garbage.c \ hashes.c \ hashfunc.c \ + hbmem.c \ hvm.c \ initexit.c \ initsymb.c \ diff --git a/harbour/source/vm/fm.c b/harbour/source/vm/fm.c index 9a5eedc0d9..ea410f1ca1 100644 --- a/harbour/source/vm/fm.c +++ b/harbour/source/vm/fm.c @@ -54,13 +54,8 @@ * The following parts are Copyright of the individual authors. * www - http://www.harbour-project.org * - * Copyright 1999 David G. Holm - * hb_xmemcpy() - * hb_xmemset() - * * Copyright 1999-2001 Viktor Szakats * hb_xquery() - * MEMORY() * * See doc/license.txt for licensing terms. * @@ -837,86 +832,6 @@ HB_EXPORT void hb_xexit( void ) /* Deinitialize fixed memory subsystem */ #endif -/* hb_xmemcpy and hb_xmemset are only needed when - unsigned int and unsigned long differ in length */ - -/* unfortunately it's not true - on 64bit platforms int is 32 bit - and long is 64. - we need these functions only when max(size_t) < max(long) - what could be detected and set in header files. Here check - only for hb_xmem* macro definition - - #if UINT_MAX != ULONG_MAX -*/ -#ifndef hb_xmemcpy -void * hb_xmemcpy( void * pDestArg, void * pSourceArg, ULONG ulLen ) -{ - BYTE * pDest; - BYTE * pSource; - ULONG ulRemaining; - int iCopySize; - - HB_TRACE(HB_TR_DEBUG, ("hb_xmemcpy(%p, %p, %lu)", pDestArg, pSourceArg, ulLen)); - - pDest = ( BYTE * ) pDestArg; - pSource = ( BYTE * ) pSourceArg; - ulRemaining = ulLen; - - while( ulRemaining ) - { - /* Overcome the memcpy() size_t limitation */ - if( ulRemaining > UINT_MAX ) - { - iCopySize = UINT_MAX; - ulRemaining -= ( ULONG ) iCopySize; - } - else - { - iCopySize = ( int ) ulRemaining; - ulRemaining = 0; - } - memcpy( pDest, pSource, iCopySize ); - pDest += iCopySize; - pSource += iCopySize; - } - - return pDestArg; -} -#endif - -#ifndef hb_xmemset -void * hb_xmemset( void * pDestArg, int iFill, ULONG ulLen ) -{ - BYTE * pDest; - ULONG ulRemaining; - int iSetSize; - - HB_TRACE(HB_TR_DEBUG, ("hb_xmemset(%p, %d, %lu)", pDestArg, iFill, ulLen)); - - pDest = ( BYTE * ) pDestArg; - ulRemaining = ulLen; - - while( ulRemaining ) - { - /* Overcome the memset() size_t limitation */ - if( ulRemaining > UINT_MAX ) - { - iSetSize = UINT_MAX; - ulRemaining -= ( ULONG ) iSetSize; - } - else - { - iSetSize = ( int ) ulRemaining; - ulRemaining = 0; - } - memset( pDest, iFill, iSetSize ); - pDest += iSetSize; - } - - return pDestArg; -} -#endif - ULONG hb_xquery( USHORT uiMode ) { ULONG ulResult; @@ -927,7 +842,7 @@ ULONG hb_xquery( USHORT uiMode ) switch( uiMode ) { - case HB_MEM_CHAR: /* (Free Variable Space [KB]) */ + case HB_MEM_CHAR: /* (Free Variable Space [KB]) */ #if defined(HB_OS_WIN_32) { MEMORYSTATUS memorystatus; @@ -948,7 +863,7 @@ ULONG hb_xquery( USHORT uiMode ) #endif break; - case HB_MEM_BLOCK: /* (Largest String [KB]) */ + case HB_MEM_BLOCK: /* (Largest String [KB]) */ #if defined(HB_OS_WIN_32) { MEMORYSTATUS memorystatus; @@ -969,7 +884,7 @@ ULONG hb_xquery( USHORT uiMode ) #endif break; - case HB_MEM_RUN: /* (RUN Memory [KB]) */ + case HB_MEM_RUN: /* (RUN Memory [KB]) */ #if defined(HB_OS_WIN_32) { MEMORYSTATUS memorystatus; @@ -990,7 +905,7 @@ ULONG hb_xquery( USHORT uiMode ) #endif break; - case HB_MEM_VM: /* UNDOCUMENTED! (Virtual Memory [KB]) */ + case HB_MEM_VM: /* UNDOCUMENTED! (Virtual Memory [KB]) */ #if defined(HB_OS_WIN_32) { MEMORYSTATUS memorystatus; @@ -1011,7 +926,7 @@ ULONG hb_xquery( USHORT uiMode ) #endif break; - case HB_MEM_EMS: /* UNDOCUMENTED! (Free Expanded Memory [KB]) (?) */ + case HB_MEM_EMS: /* UNDOCUMENTED! (Free Expanded Memory [KB]) (?) */ #if defined(HB_OS_WIN_32) || defined(HB_OS_OS2) ulResult = 0; #else @@ -1019,7 +934,7 @@ ULONG hb_xquery( USHORT uiMode ) #endif break; - case HB_MEM_FM: /* UNDOCUMENTED! (Fixed Memory/Heap [KB]) (?) */ + case HB_MEM_FM: /* UNDOCUMENTED! (Fixed Memory/Heap [KB]) (?) */ #if defined(HB_OS_WIN_32) { MEMORYSTATUS memorystatus; @@ -1048,7 +963,7 @@ ULONG hb_xquery( USHORT uiMode ) #endif break; - case HB_MEM_SWAP: /* UNDOCUMENTED! (Free Swap Memory [KB]) */ + case HB_MEM_SWAP: /* UNDOCUMENTED! (Free Swap Memory [KB]) */ #if defined(HB_OS_WIN_32) { MEMORYSTATUS memorystatus; @@ -1067,7 +982,7 @@ ULONG hb_xquery( USHORT uiMode ) #endif break; - case HB_MEM_CONV: /* UNDOCUMENTED! (Free Conventional [KB]) */ + case HB_MEM_CONV: /* UNDOCUMENTED! (Free Conventional [KB]) */ #if defined(HB_OS_WIN_32) || defined(HB_OS_OS2) ulResult = 0; #else @@ -1075,11 +990,11 @@ ULONG hb_xquery( USHORT uiMode ) #endif break; - case HB_MEM_EMSUSED: /* UNDOCUMENTED! (Used Expanded Memory [KB]) (?) */ + case HB_MEM_EMSUSED: /* UNDOCUMENTED! (Used Expanded Memory [KB]) (?) */ ulResult = 0; break; - case HB_MEM_USED: /* Harbour extension (Memory used [bytes]) */ + case HB_MEM_USED: /* Harbour extension (Memory used [bytes]) */ #ifdef HB_FM_STATISTICS ulResult = s_lMemoryConsumed; #else @@ -1087,7 +1002,7 @@ ULONG hb_xquery( USHORT uiMode ) #endif break; - case HB_MEM_BLOCKS: /* Harbour extension (Memory blocks used) */ + case HB_MEM_BLOCKS: /* Harbour extension (Memory blocks used) */ #ifdef HB_FM_STATISTICS ulResult = s_lMemoryBlocks; #else @@ -1095,7 +1010,7 @@ ULONG hb_xquery( USHORT uiMode ) #endif break; - case HB_MEM_USEDMAX: /* Harbour extension (Maximum memory used [bytes]) */ + case HB_MEM_USEDMAX: /* Harbour extension (Maximum memory used [bytes]) */ #ifdef HB_FM_STATISTICS ulResult = s_lMemoryMaxConsumed; #else @@ -1103,7 +1018,7 @@ ULONG hb_xquery( USHORT uiMode ) #endif break; - case HB_MEM_STACKITEMS: /* Harbour extension (Total items allocated for the stack) */ + case HB_MEM_STACKITEMS: /* Harbour extension (Total items allocated for the stack) */ ulResult = hb_stackTotalItems(); break; @@ -1111,7 +1026,7 @@ ULONG hb_xquery( USHORT uiMode ) ulResult = hb_stackTotalItems() * sizeof( HB_ITEM ); break; - case HB_MEM_STACK_TOP : /* Harbour extension (Total items currently on the stack) */ + case HB_MEM_STACK_TOP : /* Harbour extension (Total items currently on the stack) */ ulResult = hb_stackTopOffset( ); break; diff --git a/harbour/source/vm/fmhb.c b/harbour/source/vm/fmhb.c new file mode 100644 index 0000000000..d45af64492 --- /dev/null +++ b/harbour/source/vm/fmhb.c @@ -0,0 +1,58 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * MEMORY() function. + * + * Copyright 1999-2001 Viktor Szakats + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbapi.h" + +HB_FUNC( MEMORY ) +{ + hb_retnint( hb_xquery( ( USHORT ) hb_parni( 1 ) ) ); +} diff --git a/harbour/source/vm/hbmem.c b/harbour/source/vm/hbmem.c new file mode 100644 index 0000000000..a15342f95c --- /dev/null +++ b/harbour/source/vm/hbmem.c @@ -0,0 +1,133 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * hb_xmemcpy(), hb_xmemset() + * + * Copyright 1999 David G. Holm + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbapi.h" + +/* hb_xmemcpy() and hb_xmemset() are only needed when + unsigned int and unsigned long differ in length */ + +/* unfortunately it's not true - on 64bit platforms int is 32 bit + and long is 64. + we need these functions only when max(size_t) < max(long) + what could be detected and set in header files. Here check + only for hb_xmem* macro definition + + #if UINT_MAX != ULONG_MAX +*/ +#ifndef hb_xmemcpy +void * hb_xmemcpy( void * pDestArg, void * pSourceArg, ULONG ulLen ) +{ + BYTE * pDest; + BYTE * pSource; + ULONG ulRemaining; + int iCopySize; + + HB_TRACE(HB_TR_DEBUG, ("hb_xmemcpy(%p, %p, %lu)", pDestArg, pSourceArg, ulLen)); + + pDest = ( BYTE * ) pDestArg; + pSource = ( BYTE * ) pSourceArg; + ulRemaining = ulLen; + + while( ulRemaining ) + { + /* Overcome the memcpy() size_t limitation */ + if( ulRemaining > UINT_MAX ) + { + iCopySize = UINT_MAX; + ulRemaining -= ( ULONG ) iCopySize; + } + else + { + iCopySize = ( int ) ulRemaining; + ulRemaining = 0; + } + memcpy( pDest, pSource, iCopySize ); + pDest += iCopySize; + pSource += iCopySize; + } + + return pDestArg; +} +#endif + +#ifndef hb_xmemset +void * hb_xmemset( void * pDestArg, int iFill, ULONG ulLen ) +{ + BYTE * pDest; + ULONG ulRemaining; + int iSetSize; + + HB_TRACE(HB_TR_DEBUG, ("hb_xmemset(%p, %d, %lu)", pDestArg, iFill, ulLen)); + + pDest = ( BYTE * ) pDestArg; + ulRemaining = ulLen; + + while( ulRemaining ) + { + /* Overcome the memset() size_t limitation */ + if( ulRemaining > UINT_MAX ) + { + iSetSize = UINT_MAX; + ulRemaining -= ( ULONG ) iSetSize; + } + else + { + iSetSize = ( int ) ulRemaining; + ulRemaining = 0; + } + memset( pDest, iFill, iSetSize ); + pDest += iSetSize; + } + + return pDestArg; +} +#endif diff --git a/harbour/source/vm/vmmt/Makefile b/harbour/source/vm/vmmt/Makefile index 0d16e1af5f..d471e101df 100644 --- a/harbour/source/vm/vmmt/Makefile +++ b/harbour/source/vm/vmmt/Makefile @@ -43,9 +43,11 @@ C_SOURCES=\ extend.c \ extrap.c \ fm.c \ + fmhb.c \ garbage.c \ hashes.c \ hashfunc.c \ + hbmem.c \ hvm.c \ initexit.c \ initsymb.c \