2017-09-08 16:00 UTC Viktor Szakats (vszakats users.noreply.github.com)
* *
* partial sync with the 3.4 fork codebase. These are the things
synces for the most part:
- copyright headers
- grammar/typos in comments and some readmes
- comment/whitespace/decorations
- variable scoping in C files
- DO CASE/SWITCH and some other alternate syntax usage
- minimal amount of human readable text in strings
- minor code updates
- HB_TRACE() void * casts for pointers and few other changes to
avoid C compiler warnings
- various other, minor code cleanups
- only Harbour/C code/headers were touched in src, utils, contrib,
include. No 3rd party code, no make files, and with just a few
exceptions, no 'tests' code was touched.
- certain components were not touched were 3.4 diverged too much
already, like f.e. hbmk2, hbssl, hbcurl, hbexpat
- the goal was that no actual program logic should be altered by
these changes. Except some possible minor exceptions, any such
change is probably a bug in this patch.
It's a massive patch, if you find anything broken after it, please
open an Issue with the details. Build test was done on macOS.
The goal is make it easier to see what actual code/logic was changed
in 3.4 compared to 3.2 and to make patches easier to apply in both
ways.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
* Harbour Portable Object (.hrb) file runner
|
||||
*
|
||||
* Copyright 1999 Eddie Runia <eddie@runia.com>
|
||||
* Copyright 2002 Alexander Kresin <alex@belacy.belgorod.su>
|
||||
* (hb_hrbLoad(), hb_hrbDo(), hb_hrbUnload(), hb_hrbGetFunSym())
|
||||
*
|
||||
* 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
|
||||
@@ -44,19 +46,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* The following parts are Copyright of the individual authors.
|
||||
*
|
||||
* Copyright 2002 Alexander Kresin <alex@belacy.belgorod.su>
|
||||
* hb_hrbLoad()
|
||||
* hb_hrbDo()
|
||||
* hb_hrbUnload()
|
||||
* hb_hrbGetFunSym()
|
||||
*
|
||||
* See COPYING.txt for licensing terms.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "hbvmint.h"
|
||||
#include "hbapi.h"
|
||||
#include "hbstack.h"
|
||||
@@ -71,20 +60,20 @@
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char * szName; /* Name of the function */
|
||||
HB_PCODEFUNC pcodeFunc; /* Dynamic function info */
|
||||
HB_BYTE * pCode; /* P-code */
|
||||
char * szName; /* Name of the function */
|
||||
HB_PCODEFUNC pcodeFunc; /* Dynamic function info */
|
||||
HB_BYTE * pCode; /* P-code */
|
||||
} HB_DYNF, * PHB_DYNF;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
HB_ULONG ulSymbols; /* Number of symbols */
|
||||
HB_ULONG ulFuncs; /* Number of functions */
|
||||
HB_ULONG ulSymbols; /* Number of symbols */
|
||||
HB_ULONG ulFuncs; /* Number of functions */
|
||||
HB_BOOL fInit; /* should be INIT functions executed */
|
||||
HB_BOOL fExit; /* should be EXIT functions executed */
|
||||
HB_LONG lSymStart; /* Startup Symbol */
|
||||
PHB_SYMB pSymRead; /* Symbols read */
|
||||
PHB_DYNF pDynFunc; /* Functions read */
|
||||
HB_LONG lSymStart; /* Startup Symbol */
|
||||
PHB_SYMB pSymRead; /* Symbols read */
|
||||
PHB_DYNF pDynFunc; /* Functions read */
|
||||
PHB_SYMBOLS pModuleSymbols;
|
||||
} HRB_BODY, * PHRB_BODY;
|
||||
|
||||
@@ -92,10 +81,10 @@ static const char s_szHead[ 4 ] = { '\xC0', 'H', 'R', 'B' };
|
||||
|
||||
|
||||
#define SYM_NOLINK 0 /* symbol does not have to be linked */
|
||||
#define SYM_FUNC 1 /* function defined in this module */
|
||||
#define SYM_EXTERN 2 /* function defined in other module */
|
||||
#define SYM_DEFERRED 3 /* lately bound function */
|
||||
#define SYM_NOT_FOUND 0xFFFFFFFFUL /* Symbol not found. */
|
||||
#define SYM_FUNC 1 /* function defined in this module */
|
||||
#define SYM_EXTERN 2 /* function defined in other module */
|
||||
#define SYM_DEFERRED 3 /* lately bound function */
|
||||
#define SYM_NOT_FOUND 0xFFFFFFFFUL /* Symbol not found. */
|
||||
|
||||
static HB_SIZE hb_hrbCheckSig( const char * szBody, HB_SIZE nBodySize )
|
||||
{
|
||||
@@ -109,7 +98,7 @@ static int hb_hrbReadHead( const char * szBody, HB_SIZE nBodySize, HB_SIZE * pnB
|
||||
const char * pVersion;
|
||||
HB_SIZE nSigSize;
|
||||
|
||||
HB_TRACE( HB_TR_DEBUG, ( "hb_hrbReadHead(%p,%" HB_PFS "u,%p)", szBody, nBodySize, pnBodyOffset ) );
|
||||
HB_TRACE( HB_TR_DEBUG, ( "hb_hrbReadHead(%p,%" HB_PFS "u,%p)", ( const void * ) szBody, nBodySize, ( void * ) pnBodyOffset ) );
|
||||
|
||||
nSigSize = hb_hrbCheckSig( szBody, nBodySize );
|
||||
|
||||
@@ -124,7 +113,7 @@ static int hb_hrbReadHead( const char * szBody, HB_SIZE nBodySize, HB_SIZE * pnB
|
||||
|
||||
static HB_BOOL hb_hrbReadValue( const char * szBody, HB_SIZE nBodySize, HB_SIZE * pnBodyOffset, HB_ULONG * pulValue )
|
||||
{
|
||||
HB_TRACE( HB_TR_DEBUG, ( "hb_hrbReadValue(%p,%" HB_PFS "u,%p,%p)", szBody, nBodySize, pnBodyOffset, pulValue ) );
|
||||
HB_TRACE( HB_TR_DEBUG, ( "hb_hrbReadValue(%p,%" HB_PFS "u,%p,%p)", ( const void * ) szBody, nBodySize, ( void * ) pnBodyOffset, ( void * ) pulValue ) );
|
||||
|
||||
if( *pnBodyOffset + 4 < nBodySize )
|
||||
{
|
||||
@@ -144,7 +133,7 @@ static char * hb_hrbReadId( const char * szBody, HB_SIZE nBodySize, HB_SIZE * pn
|
||||
{
|
||||
const char * szIdx;
|
||||
|
||||
HB_TRACE( HB_TR_DEBUG, ( "hb_hrbReadId(%p,%" HB_PFS "u,%p)", szBody, nBodySize, pnBodyOffset ) );
|
||||
HB_TRACE( HB_TR_DEBUG, ( "hb_hrbReadId(%p,%" HB_PFS "u,%p)", ( const void * ) szBody, nBodySize, ( void * ) pnBodyOffset ) );
|
||||
|
||||
szIdx = &szBody[ *pnBodyOffset ];
|
||||
|
||||
@@ -162,7 +151,7 @@ static HB_ULONG hb_hrbFindSymbol( const char * szName, PHB_DYNF pDynFunc, HB_ULO
|
||||
{
|
||||
HB_ULONG ulRet;
|
||||
|
||||
HB_TRACE( HB_TR_DEBUG, ( "hb_hrbFindSymbol(%s, %p, %lu)", szName, pDynFunc, ulLoaded ) );
|
||||
HB_TRACE( HB_TR_DEBUG, ( "hb_hrbFindSymbol(%s, %p, %lu)", szName, ( void * ) pDynFunc, ulLoaded ) );
|
||||
|
||||
for( ulRet = 0; ulRet < ulLoaded; ++ulRet )
|
||||
{
|
||||
@@ -210,15 +199,14 @@ static void hb_hrbInit( PHRB_BODY pHrbBody, int iPCount, PHB_ITEM * pParams )
|
||||
{
|
||||
if( hb_vmRequestReenter() )
|
||||
{
|
||||
HB_ULONG ul;
|
||||
HB_BOOL fRepeat, fClipInit = HB_TRUE;
|
||||
int i;
|
||||
|
||||
pHrbBody->fInit = HB_FALSE;
|
||||
pHrbBody->fExit = HB_TRUE;
|
||||
|
||||
do
|
||||
{
|
||||
HB_ULONG ul;
|
||||
fRepeat = HB_FALSE;
|
||||
ul = pHrbBody->ulSymbols;
|
||||
while( ul-- )
|
||||
@@ -229,6 +217,7 @@ static void hb_hrbInit( PHRB_BODY pHrbBody, int iPCount, PHB_ITEM * pParams )
|
||||
if( strcmp( pHrbBody->pSymRead[ ul ].szName, "CLIPINIT$" ) ?
|
||||
! fClipInit : fClipInit )
|
||||
{
|
||||
int i;
|
||||
hb_vmPushSymbol( pHrbBody->pSymRead + ul );
|
||||
hb_vmPushNil();
|
||||
for( i = 0; i < iPCount; i++ )
|
||||
@@ -280,25 +269,21 @@ static void hb_hrbExit( PHRB_BODY pHrbBody )
|
||||
|
||||
static void hb_hrbUnLoad( PHRB_BODY pHrbBody )
|
||||
{
|
||||
HB_ULONG ul;
|
||||
|
||||
hb_hrbExit( pHrbBody );
|
||||
|
||||
if( pHrbBody->pModuleSymbols )
|
||||
{
|
||||
hb_vmFreeSymbols( pHrbBody->pModuleSymbols );
|
||||
}
|
||||
|
||||
if( pHrbBody->pDynFunc )
|
||||
{
|
||||
HB_ULONG ul;
|
||||
|
||||
for( ul = 0; ul < pHrbBody->ulFuncs; ul++ )
|
||||
{
|
||||
PHB_DYNS pDyn;
|
||||
|
||||
if( pHrbBody->pDynFunc[ ul ].szName &&
|
||||
pHrbBody->pDynFunc[ ul ].pcodeFunc.pCode )
|
||||
{
|
||||
pDyn = hb_dynsymFind( pHrbBody->pDynFunc[ ul ].szName );
|
||||
PHB_DYNS pDyn = hb_dynsymFind( pHrbBody->pDynFunc[ ul ].szName );
|
||||
if( pDyn && pDyn->pSymbol->value.pCodeFunc ==
|
||||
&pHrbBody->pDynFunc[ ul ].pcodeFunc )
|
||||
{
|
||||
@@ -317,8 +302,6 @@ static void hb_hrbUnLoad( PHRB_BODY pHrbBody )
|
||||
hb_xfree( pHrbBody );
|
||||
}
|
||||
|
||||
|
||||
|
||||
static PHRB_BODY hb_hrbLoad( const char * szHrbBody, HB_SIZE nBodySize, HB_USHORT usMode, const char * szFileName )
|
||||
{
|
||||
PHRB_BODY pHrbBody = NULL;
|
||||
@@ -326,14 +309,14 @@ static PHRB_BODY hb_hrbLoad( const char * szHrbBody, HB_SIZE nBodySize, HB_USHOR
|
||||
if( szHrbBody )
|
||||
{
|
||||
HB_SIZE nBodyOffset = 0;
|
||||
HB_SIZE nSize; /* Size of function */
|
||||
HB_SIZE nSize; /* Size of function */
|
||||
HB_SIZE nPos;
|
||||
HB_ULONG ul;
|
||||
char * buffer, ch;
|
||||
HB_USHORT usBind = ( usMode & HB_HRB_BIND_MODEMASK );
|
||||
|
||||
PHB_SYMB pSymRead; /* Symbols read */
|
||||
PHB_DYNF pDynFunc; /* Functions read */
|
||||
PHB_SYMB pSymRead; /* Symbols read */
|
||||
PHB_DYNF pDynFunc; /* Functions read */
|
||||
PHB_DYNS pDynSym;
|
||||
|
||||
int iVersion = hb_hrbReadHead( szHrbBody, nBodySize, &nBodyOffset );
|
||||
@@ -544,7 +527,7 @@ static PHRB_BODY hb_hrbLoad( const char * szHrbBody, HB_SIZE nBodySize, HB_USHOR
|
||||
{
|
||||
/*
|
||||
* Old unused symbol table has been recycled - free the one
|
||||
* we allocated and disactivate static initialization [druzus]
|
||||
* we allocated and deactivate static initialization [druzus]
|
||||
*/
|
||||
pHrbBody->pSymRead = pHrbBody->pModuleSymbols->pModuleSymbols;
|
||||
hb_xfree( pSymRead );
|
||||
@@ -619,13 +602,14 @@ static PHRB_BODY hb_hrbLoadFromFile( const char * szHrb, HB_USHORT usMode )
|
||||
static void hb_hrbDo( PHRB_BODY pHrbBody, int iPCount, PHB_ITEM * pParams )
|
||||
{
|
||||
PHB_ITEM pRetVal = NULL;
|
||||
int i;
|
||||
|
||||
hb_hrbInit( pHrbBody, iPCount, pParams );
|
||||
|
||||
/* May not have a startup symbol, if first symbol was an INIT Symbol (was executed already). */
|
||||
if( pHrbBody->lSymStart >= 0 && hb_vmRequestQuery() == 0 )
|
||||
{
|
||||
int i;
|
||||
|
||||
hb_vmPushSymbol( &pHrbBody->pSymRead[ pHrbBody->lSymStart ] );
|
||||
hb_vmPushNil();
|
||||
|
||||
@@ -677,7 +661,7 @@ static void hb_hrbReturn( PHRB_BODY pHrbBody )
|
||||
}
|
||||
|
||||
/*
|
||||
hb_hrbRun( [ <nOptions>, ] <cHrb> [, <xparams,...> ] ) -> <retVal>
|
||||
hb_hrbRun( [ <nOptions>, ] <cHrb> [, <xparams,...> ] ) --> <retVal>
|
||||
|
||||
This program will get the data from the .hrb file and run the p-code
|
||||
contained in it.
|
||||
@@ -711,11 +695,12 @@ HB_FUNC( HB_HRBRUN )
|
||||
|
||||
if( pHrbBody )
|
||||
{
|
||||
int iPCount = hb_pcount() - nParam, i;
|
||||
int iPCount = hb_pcount() - nParam;
|
||||
PHB_ITEM * pParams = NULL;
|
||||
|
||||
if( iPCount > 0 )
|
||||
{
|
||||
int i;
|
||||
pParams = ( PHB_ITEM * ) hb_xgrab( sizeof( PHB_ITEM ) * iPCount );
|
||||
for( i = 0; i < iPCount; i++ )
|
||||
pParams[ i ] = hb_stackItemFromBase( i + 1 + nParam );
|
||||
@@ -763,12 +748,11 @@ HB_FUNC( HB_HRBLOAD )
|
||||
{
|
||||
int iPCount = hb_pcount() - nParam;
|
||||
PHB_ITEM * pParams = NULL;
|
||||
int i;
|
||||
|
||||
if( iPCount > 0 )
|
||||
{
|
||||
int i;
|
||||
pParams = ( PHB_ITEM * ) hb_xgrab( sizeof( PHB_ITEM ) * iPCount );
|
||||
|
||||
for( i = 0; i < iPCount; i++ )
|
||||
pParams[ i ] = hb_stackItemFromBase( i + 1 + nParam );
|
||||
}
|
||||
@@ -792,12 +776,11 @@ HB_FUNC( HB_HRBDO )
|
||||
{
|
||||
int iPCount = hb_pcount() - 1;
|
||||
PHB_ITEM * pParams = NULL;
|
||||
int i;
|
||||
|
||||
if( iPCount > 0 )
|
||||
{
|
||||
int i;
|
||||
pParams = ( PHB_ITEM * ) hb_xgrab( sizeof( PHB_ITEM ) * iPCount );
|
||||
|
||||
for( i = 0; i < iPCount; i++ )
|
||||
pParams[ i ] = hb_stackItemFromBase( i + 2 );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user