0
votes

Caché provides the $COMPILE function to convert an array of of source code strings into object code. The object parameter allows you to save the binary object data into a local array variable without affecting any global arrays.

The documentation explains that you can replace the data in ^rOBJ(routine) for the routine with the lines returned in the object parameter and that will change the program that runs for routine.

My question is, can I run the object array directly without modifying any globals (e.g. saving the lines in ^rOBJ first)? My code strings are generated dynamically by external applications and cannot be pre-loaded into routines.

I want to limit the access the calling program has to the overall system. Having access to modify ^rOBJ means being able to change application routines that control the system. It also means that I would have to maintain a bunch of temporary routines, making sure that they get cleaned up in an external process even if the job terminates unexpectedly.

Currently, I am using XECUTE to just run the code lines directly, but I would rather use compiled code as it is faster.

1

1 Answers

1
votes

I couldn't find a way to run $COMPILE code directly. I did find a workaround though:

From XECUTE you can ZLOAD a common, empty template routine and then ZINSERT your code to be compiled but not ZSAVE so the changes stay private to the current process. It is then possible to DO into the local "routine buffer" version of the routine (apparently compiled and everything) that you inserted just now and run the uploaded code.

From my testing, I found that if I return from the XECUTE, $ZNAME reverts to the calling routine and the changes uploaded in ZINSERT are reverted. Therefore, it is important to do the ZLOAD, ZINSERT and DO all in the same XECUTE line.