From 2f2dc484a87fca451bf2d035d9ac0ef820960c98 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Sat, 20 Sep 2008 03:37:41 +0000 Subject: [PATCH] 2008-09-20 05:37 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/common.mak * harbour/source/rdd/Makefile ! restored dbdetach.* in makefiles + harbour/source/rdd/dbdetach.c + added file I forgot to add in previous commit * harbour/source/vm/thread.c + added support for using function name as string in HB_THREADSTART() + added support for thread attributes. They will be used in the future. --- harbour/ChangeLog | 12 +++ harbour/common.mak | 1 + harbour/source/rdd/Makefile | 1 + harbour/source/rdd/dbdetach.c | 141 ++++++++++++++++++++++++++++++++++ harbour/source/vm/thread.c | 76 ++++++++++++++++-- 5 files changed, 225 insertions(+), 6 deletions(-) create mode 100644 harbour/source/rdd/dbdetach.c diff --git a/harbour/ChangeLog b/harbour/ChangeLog index aaf422109d..b006f7accd 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-09-20 05:37 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/common.mak + * harbour/source/rdd/Makefile + ! restored dbdetach.* in makefiles + + + harbour/source/rdd/dbdetach.c + + added file I forgot to add in previous commit + + * harbour/source/vm/thread.c + + added support for using function name as string in HB_THREADSTART() + + added support for thread attributes. They will be used in the future. + 2008-09-19 21:28 UTC-0500 Teo Fonrouge (teo/at/windtelsoft/dot/com) * common.mak * source/rdd/Makefile diff --git a/harbour/common.mak b/harbour/common.mak index f7e406309b..7a637ad11a 100644 --- a/harbour/common.mak +++ b/harbour/common.mak @@ -890,6 +890,7 @@ RDD_LIB_OBJS = \ $(OBJ_DIR)\dbcmd53$(OBJEXT) \ $(OBJ_DIR)\dbcmdhb$(OBJEXT) \ $(OBJ_DIR)\dbcmdx$(OBJEXT) \ + $(OBJ_DIR)\dbdetach$(OBJEXT) \ $(OBJ_DIR)\dbdrop$(OBJEXT) \ $(OBJ_DIR)\dbexists$(OBJEXT) \ $(OBJ_DIR)\fieldhb$(OBJEXT) \ diff --git a/harbour/source/rdd/Makefile b/harbour/source/rdd/Makefile index d2b23a5323..b31ad75b9b 100644 --- a/harbour/source/rdd/Makefile +++ b/harbour/source/rdd/Makefile @@ -9,6 +9,7 @@ C_SOURCES=\ dbcmd53.c \ dbcmdhb.c \ dbcmdx.c \ + dbdetach.c \ dbdrop.c \ dbexists.c \ fieldhb.c \ diff --git a/harbour/source/rdd/dbdetach.c b/harbour/source/rdd/dbdetach.c new file mode 100644 index 0000000000..b938af3e09 --- /dev/null +++ b/harbour/source/rdd/dbdetach.c @@ -0,0 +1,141 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * .prg functions for workarea detaching + * + * Copyright 2008 Przemyslaw Czerpak + * 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" +#include "hbapirdd.h" +#include "hbapiitm.h" +#include "hbapierr.h" + +/* + * hb_dbDetach( [|], [] ) -> + */ +HB_FUNC( HB_DBDETACH ) +{ + PHB_ITEM pAlias = hb_param( 1, HB_IT_ANY ); + PHB_ITEM pCargo = hb_param( 2, HB_IT_ANY ); /* HB_IT_BLOCK in xBase++ */ + AREAP pArea = NULL; + int iArea; + + if( !pAlias || HB_IS_NIL( pAlias ) ) + { + pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); + } + else if( HB_IS_STRING( pAlias ) ) + { + char * szAlias = hb_itemGetCPtr( pAlias ); + hb_rddGetAliasNumber( szAlias, &iArea ); + if( iArea > 0 ) + pArea = ( AREAP ) hb_rddGetWorkAreaPointer( iArea ); + } + else if( HB_IS_NUMBER( pAlias ) ) + { + iArea = hb_itemGetNI( pAlias ); + if( iArea > 0 ) + pArea = ( AREAP ) hb_rddGetWorkAreaPointer( iArea ); + } + else + { + hb_errRT_DBCMD( EG_ARG, EDBCMD_BADPARAMETER, NULL, HB_ERR_FUNCNAME ); + return; + } + + if( pArea ) + hb_retl( hb_rddDetachArea( pArea, pCargo ) == SUCCESS ); + else + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, HB_ERR_FUNCNAME ); +} + +/* + * DbRequest( [], [], [<@xCargo>], [] ) + * -> + */ +HB_FUNC( HB_DBREQUEST ) +{ + char * szAlias; + PHB_ITEM pCargo; + BOOL fNewArea, fWait; + AREAP pArea; + + if( ISNIL( 1 ) || ISCHAR( 1 ) ) + { + szAlias = hb_parc( 1 ); + fNewArea = ISLOG( 2 ) && hb_parl( 2 ); + fWait = ISLOG( 4 ) && hb_parl( 4 ); + pCargo = ISBYREF( 3 ) ? hb_itemNew( NULL ) : NULL; + + pArea = hb_rddRequestArea( szAlias, pCargo, fNewArea, fWait ); + if( pArea ) + hb_rddSelectWorkAreaNumber( pArea->uiArea ); + + if( pCargo ) + { + hb_itemParamStoreForward( 3, pCargo ); + hb_itemRelease( pCargo ); + } + + hb_retl( pArea != NULL ); + } + else + hb_errRT_DBCMD( EG_ARG, EDBCMD_BADPARAMETER, NULL, HB_ERR_FUNCNAME ); +} + +#ifdef HB_COMPAT_XPP +HB_FUNC( DBRELEASE ) +{ + HB_FUNC_EXEC( HB_DBDETACH ); +} + +HB_FUNC( DBREQUEST ) +{ + HB_FUNC_EXEC( HB_DBREQUEST ); +} +#endif diff --git a/harbour/source/vm/thread.c b/harbour/source/vm/thread.c index 0b2b1e63f9..9bc08dc436 100644 --- a/harbour/source/vm/thread.c +++ b/harbour/source/vm/thread.c @@ -458,6 +458,11 @@ static HB_THREAD_STARTFUNC( hb_threadStartVM ) hb_vmPushSymbol( hb_itemGetSymbol( pStart ) ); hb_vmPushNil(); } + else if( HB_IS_STRING( pStart ) ) + { + hb_vmPushDynSym( hb_dynsymGet( hb_itemGetCPtr( pStart ) ) ); + hb_vmPushNil(); + } else ulPCount = 0; } @@ -506,8 +511,44 @@ static PHB_THREADSTATE hb_thParam( int iParam ) HB_FUNC( HB_THREADSTART ) { - PHB_ITEM pStart = hb_param( 1, HB_IT_ANY ); - if( pStart && ( HB_IS_BLOCK( pStart ) || HB_IS_SYMBOL( pStart ) ) ) + ULONG ulAttr = 0, ulStart = 1; + const char * szFuncName = NULL; + PHB_SYMB pSymbol = NULL; + PHB_ITEM pStart; + + pStart = hb_param( ulStart, HB_IT_ANY ); + while( pStart && HB_IS_NUMERIC( pStart ) ) + { + ulAttr |= ( ULONG ) hb_itemGetNL( pStart ); + pStart = hb_param( ++ulStart, HB_IT_ANY ); + } + + if( pStart ) + { + if( HB_IS_STRING( pStart ) ) + { + PHB_DYNS pDynSym; + szFuncName = hb_itemGetCPtr( pStart ); + pDynSym = hb_dynsymFindName( szFuncName ); + if( pDynSym ) + pSymbol = pDynSym->pSymbol; + if( !pSymbol || !pSymbol->value.pFunPtr ) + pStart = NULL; + } + else if( HB_IS_SYMBOL( pStart ) ) + { + pSymbol = hb_itemGetSymbol( pStart ); + if( !pSymbol->value.pFunPtr ) + { + szFuncName = pSymbol->szName; + pStart = NULL; + } + } + else if( !HB_IS_BLOCK( pStart ) ) + pStart = NULL; + } + + if( pStart ) { PHB_ITEM pReturn; PHB_THREADSTATE pThread; @@ -525,14 +566,32 @@ HB_FUNC( HB_THREADSTART ) pThread->pSet = hb_setClone( hb_stackSetStruct() ); pThread->pParams = hb_arrayBaseParams(); - /* detach LOCAL variables passed by reference */ ulPCount = hb_arrayLen( pThread->pParams ); - for( ulParam = 2; ulParam <= ulPCount; ++ulParam ) + /* remove thread attributes */ + if( ulStart > 1 ) + { + for( ulParam = 1; ulParam < ulStart; ++ulParam ) + hb_arrayDel( pThread->pParams, 1 ); + ulPCount -= ulStart - 1; + hb_arraySize( pThread->pParams, ulPCount ); + } + if( HB_IS_STRING( pStart ) && pSymbol ) + hb_itemPutSymbol( hb_arrayGetItemPtr( pThread->pParams, 1 ), pSymbol ); + /* detach LOCAL variables passed by reference */ + for( ulParam = 1; ulParam <= ulPCount; ++ulParam ) { PHB_ITEM pParam = hb_arrayGetItemPtr( pThread->pParams, ulParam ); if( HB_IS_BYREF( pParam ) ) - hb_memvarDetachLocal( pParam ); + { + if( ulParam == 1 ) + hb_itemCopy( pParam, hb_itemUnRef( pParam ) ); + else + hb_memvarDetachLocal( pParam ); + } } + /* TODO: use thread attributes in thread initialization, + * f.e. to copy visible memvars if user request about it. + */ /* make copy of thread pointer item before we pass it to new thread * to avoid race condition @@ -549,7 +608,12 @@ HB_FUNC( HB_THREADSTART ) } } else - hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); + { + if( szFuncName ) + hb_errRT_BASE_SubstR( EG_NOFUNC, 1001, NULL, szFuncName, 0 ); + else + hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); + } } HB_FUNC( HB_THREADJOIN )