On Sun, Oct 17, 2021 at 7:57 AM Rony G. Flatscher <rony.flatsc...@wu.ac.at>
wrote:

> While it is possible to compile the wpipe1 example on Unix, there is one
> irregularity: when displaying the variable "result", upon return of
> registering the external functions it will show garbage instead of "0"
> (return code of the loader function).
>
> Here the code snippet from "rexxasp1.c":
>
> /*********************************************************************/
> /* Numeric Return calls                                              */
> /*********************************************************************/
>
> #define  INVALID_ROUTINE 10            /* Raise Rexx error           */
> #define  VALID_ROUTINE    0            /* Successful completion      */
>
> #ifdef __cplusplus
> extern "C" {
> #endif
>
> /*********************************************************************/
> /* AspiFncTable                                                      */
> /*   Array of names of the REXXASP1 functions.                       */
> /*   This list is used for registration and deregistration.          */
> /*********************************************************************/
> static const char *AspiFncTable[] =
>    {
>       "Aspi_Output_From_C",
>       "Aspi_Output_From_REXX",
>       "Aspi_Exchange_Data",
>       "AspiDeregFunc"
>    };
>
>
> /*************************************************************************
> * Function:  AspiLoadFuncs                                               *
> *                                                                        *
> * Syntax:    call AspiLoadFuncs                                          *
> *                                                                        *
> * Params:    none                                                        *
> *                                                                        *
> * Return:    null string                                                 *
> *************************************************************************/
>
> RexxReturnCode REXXENTRY AspiLoadFuncs(
>     const char *name,                    /* Function name              */
>     size_t numargs,                      /* Number of arguments        */
>     CONSTRXSTRING args[],                /* Argument array             */
>     const char * queuename,              /* Current queue              */
>     PRXSTRING retstr )                   /* Return RXSTRING            */
> {
>   int    entries;                      /* Num of entries             */
>   int    j;                            /* Counter                    */
>
>
>   entries = sizeof(AspiFncTable)/sizeof(const char *);
>
>   for (j = 0; j < entries; j++)
>   {
>       fprintf(stderr,"AspiLoadFuncs: registering # %d: 
> [%s]\n",j,AspiFncTable[j]);
>
>     RexxRegisterFunctionDll(AspiFncTable[j], "rexxasp1", AspiFncTable[j]);
>   }
>
>   fprintf(stderr,"AspiLoadFuncs: VALID_ROUTINE=%d\n",VALID_ROUTINE);
>
>   return VALID_ROUTINE;
> }
>
>
> Here the Linux Makefile:
>
> DLL_LFLAGS = -shared
> OOREXX_CFLAGS =  -fPIC
>
> all: librexxasp1.so
>
> rexxasp1.o: rexxasp1.c
>       gcc -c rexxasp1.c $(OOREXX_CFLAGS) -o rexxasp1.o
>
> librexxasp1.so: rexxasp1.o
>       gcc rexxasp1.o ${DLL_LFLAGS} -o librexxasp1.so
>
> clean:
>       rm -f *.so *.o libwpipe1.so  librexxasp1.so
>
>
> Here the Rexx script using the library (note on Linux one needs to prefix
> the command with LD_LIBRARY_PATH pointing to the directory where the
> library resides):
>
> all RxFuncAdd "AspiLoadFuncs", "rexxasp1", "AspiLoadFuncs"
> -- Call RxFuncAdd "AspiLoadFuncs", "wpipe1", "AspiLoadFuncs"
> say "1) rc:" rc "result="result
> Call AspiLoadFuncs
> say "2) rc:" rc "result="result
>
> call Aspi_Output_From_C
>
> call Aspi_Output_From_REXX
> say RESULT
>
> a = 'This is a String'
>
> Say Aspi_Exchange_Data(23456,888, a)
>
> call AspiDeregFunc
>
> Here the output on Linux (the same problem exists on Mac, just different
> garbage gets displayed):
>
>  It looks as if a stray pointer gets returned for "result" instead of "0".
>
> After a while it occurred to me that this is the 32-bit SAA version of the
> Rexx API which supposedly has problems with 64-bit with ooRexx. Could this
> be the reason/cause?
>
The return value is the value set into retstr. Since this is left unchanged
on return, the return value is 256 bytes of whatever garbage was in the
retstr buffer when it was passed to the external routine. Something like

strcpy(retstr->strptr, "0");
retstr->strlength = 1;

Should be added.

Rick


> ---rony
>
>
> _______________________________________________
> Oorexx-devel mailing list
> Oorexx-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/oorexx-devel
>
_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to