21.02.2013 Views

System i: Programming i5/OS PASE - IBM

System i: Programming i5/OS PASE - IBM

System i: Programming i5/OS PASE - IBM

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

* data type that is passed as a by-value argument.<br />

*/<br />

typedef struct {<br />

char filler[5];<br />

} aggregate;<br />

/*<br />

* "result_type" and "signature" define the function<br />

* result type and the sequence and type of all<br />

* arguments needed for the ILE procedure identified<br />

* by ILEtarget<br />

*<br />

* NOTE: The fact that this argument list contains<br />

* fixed-point arguments shorter than 4 bytes or<br />

* floating-point arguments shorter than 8 bytes<br />

* implies that the target ILE C procedure is compiled<br />

* with #pragma argument(ileProcedureName, nowiden)<br />

*<br />

* Without this pragma, standard C linkage for ILE<br />

* requires 1-byte and 2-byte integer arguments to be<br />

* widened to 4-bytes and requires 4-byte floating-point<br />

* arguments to be widened to 8-bytes<br />

*/<br />

static result_type_t result_type = RESULT_INT32;<br />

static arg_type_t signature[] =<br />

{<br />

ARG_INT32,<br />

ARG_MEMPTR,<br />

ARG_FLOAT64,<br />

ARG_UINT8, /* requires #pragma nowiden in ILE code */<br />

sizeof(aggregate),<br />

ARG_INT16,<br />

ARG_END<br />

};<br />

/*<br />

* simple_wrapper accepts the same arguments and returns<br />

* the same result as the ILE procedure it calls. This<br />

* example does not require a customized or declared structure<br />

* for the ILE argument list. This wrapper uses malloc<br />

* to obtain storage. If an exception or signal occurs,<br />

* the storage may not be freed. If your program needs<br />

* to prevent such a storage leak, a signal handler<br />

* must be built to handle it, or you can use the methods<br />

* in best_wrapper.<br />

*/<br />

int simple_wrapper(int arg1, void *arg2, double arg3,<br />

char arg4, aggregate arg5, short arg6)<br />

{<br />

int result;<br />

/*<br />

* xlc does not guarantee 16-byte alignment for<br />

* automatic (stack) variables of any type, but<br />

* <strong>PASE</strong> malloc() always returns 16-byte aligned storage.<br />

* size_ILEarglist() determines how much storage is<br />

* needed, based on entries in the signature array<br />

*/<br />

ILEarglist_base *ILEarglist;<br />

ILEarglist = (ILEarglist_base*)malloc( size_ILEarglist(signature) );<br />

/*<br />

* build_ILEarglist() copies argument values into the ILE<br />

* argument list buffer, based on entries in the signature<br />

* array.<br />

*/<br />

build_ILEarglist(ILEarglist, &arg1, signature);<br />

<strong>i5</strong>/<strong>OS</strong> <strong>PASE</strong> 33

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!