Block the execution of selected functions in a macro.

127 views
Skip to first unread message

Adam Lubszczyk

unread,
Nov 3, 2022, 7:20:56 AM11/3/22
to Harbour Developers
Is it possible to block the execution of selected functions in a macro?

Sample in my app I call:
FERASE("temp.dbf")
x:=SIN(2)

So functions FERASE() and SIN() is add to SYMBOLS table and now is possible to execute:
x:="5+SIN(0.2)"
? &(x)   // OK
x:="5+MyStaticFun()"
? &(x)   // RTE unknown function MYSTATICFUN() - OK
but
x:="5+FERASE('baza.dbf')"
? &(x)   // OK - but I want RTE unknown function FERASE()

May be like STATIC FINCTION ...

STATIC REQUEST ferase,run,dbcreate,...

Adam

Antonio Linares

unread,
Nov 4, 2022, 2:50:07 AM11/4/22
to Harbour Developers
Adam,

You can replace the pcode pointers of those functions and redirect them to a dummy function

regards

Lailton Fernando Mariano

unread,
Nov 4, 2022, 4:14:56 AM11/4/22
to Harbour Developers
REQUEST FERASE, RUN, DBCREATE

It?

Adam Lubszczyk

unread,
Nov 4, 2022, 5:27:18 AM11/4/22
to Harbour Developers
piątek, 4 listopada 2022 o 09:14:56 UTC+1 lai...@paysoft.com.br napisał(a):
REQUEST FERASE, RUN, DBCREATE
It?
Maybe like command STATIC MyFun()
I can use MyFun() in source prg but not in macro

You add command like:
STATIC REQUEST FERASE, __RUN, DBCREATE
Now I can use FERASE() , __RUN(), DBCREATE() in source prg but not in macro.

Adam

Adam Lubszczyk

unread,
Nov 4, 2022, 5:30:47 AM11/4/22
to Harbour Developers
piątek, 4 listopada 2022 o 07:50:07 UTC+1 Antonio Linares napisał(a):
Adam,

You can replace the pcode pointers of those functions and redirect them to a dummy function

How? An example please.

 Adam

Antonio Linares

unread,
Nov 5, 2022, 4:12:50 AM11/5/22
to Harbour Developers
dummy.c
#define _HB_API_INTERNAL_
#include <hbapi.h>

HB_FUNC( REPLACEPCODE )
{
   PHB_DYNS pDynSymOne = hb_dynsymFind( "ONE" );
   PHB_DYNS pDynSymTwo = hb_dynsymFind( "TWO" );
   PHB_DYNS pDynSymDummy = hb_dynsymFind( "DUMMY" );

   pDynSymOne->pSymbol->value.pCodeFunc = pDynSymDummy->pSymbol->value.pCodeFunc;
   pDynSymTwo->pSymbol->value.pCodeFunc = pDynSymDummy->pSymbol->value.pCodeFunc;
}

example of use:
function Main()

   One()
   Two()

   ReplacePcode()

   One()
   Two()

return nil
   
function One()

   ? "one"

return nil

function Two()

   ? "two"

return nil

function Dummy()

   ? "this is a dummy function"

return nil

output:
one
two
this is a dummy function
this is a dummy function

regards

Antonio Linares

unread,
Nov 5, 2022, 5:22:21 AM11/5/22
to Harbour Developers
For Harbour function that don't use pcode, then you have to do it this way:

dummy.c
#define _HB_API_INTERNAL_
#include <hbapi.h>

void dummy( void )
{
   hb_retc( "I am a dummy function" );
}

HB_FUNC( CHANGEDATE )
{
   PHB_DYNS pDynSymDate = hb_dynsymFind( "DATE" );

   pDynSymDate->pSymbol->value.pFunPtr = dummy;
}

example of use:
function Main()

   ? Date()
 
   ChangeDate()

   ? Date()

return nil

output:
11/05/22
I am a dummy function

So before you allow the user to write a macro, you can modify the Harbour functions that you don't want the user to use, and after that you can restore the original values.
You can save the pFunPtr old values in C static values, and reload them

regards

Antonio Linares

unread,
Nov 5, 2022, 5:35:23 AM11/5/22
to Harbour Developers
Better this way:

dummy.c
#define _HB_API_INTERNAL_
#include <hbapi.h>

HB_FUNC( DUMMY )
{
   hb_retc( "I am a dummy function" );
}

HB_FUNC( CHANGEDATE )
{
   PHB_DYNS pDynSymDate = hb_dynsymFind( "DATE" );

   pDynSymDate->pSymbol->value.pFunPtr = HB_FUN_DUMMY;
}

regards

Adam Lubszczyk

unread,
Nov 7, 2022, 6:08:10 AM11/7/22
to Harbour Developers

sobota, 5 listopada 2022 o 10:35:23 UTC+1 Antonio Linares napisał(a):
[...]
Thank you for the hint.
I try set function scope to HB_FS_STATIC  but now work.
In the end, I chose this:
dummy.c
#define _HB_API_INTERNAL_
#include <hbapi.h>

static char * dummy = "*" ;


HB_FUNC( CHANGEDATE )
{
   PHB_DYNS pDynSymDate = hb_dynsymFind( "DATE" );
   if (  pDynSymDate )
     pDynSymDate->pSymbol->szName = dummy  ;
}

example of use:
function Main()
  a := "Date()"
   ? Date()
   ? &(a)
   ? "CHANGE"  
   ChangeDate()
   ? Date()
   ? &(a)
return

Output:
11/07/22
11/07/22
CHANGE
11/07/22
Error BASE/1001  Undefined function: DATE


Adam

Francesco Perillo

unread,
Nov 7, 2022, 7:01:15 AM11/7/22
to harbou...@googlegroups.com
What about scanning the macro text for function names?


Reply all
Reply to author
Forward
0 new messages