Structural Informatics Group (SIG) logo
Home | Projects | Demos | Downloads | Publications | Local Info | About Us | New site
Go to the first, previous, next, last section, table of contents.

Creating New Primitives

Not done. For now look at Xlisp Internals:"How do I add a new primitive fn to xlisp?" , xcore/doc/mymodule.h, and of course source code in the various modules.

One important point when adding new primitives. It is essential that LVALS be protected with xlsave or xlprotect. If not the garbage collector may try to collect them at inopportune times, with the result that you will get very obscure bugs, often causing your program to hang. Similarly it is essential to pop all saved variables off the evaluation stack when exiting your function (except when you call xlfail for an error, since the stack is cleared for you). Otherwise the garbage collector will later try to access a NULL pointer, often causing a segmentation fault. Based on our experience, if you get strange, almost untraceable bugs, they are almost certainly due to improperly protecting or releasing LVALS. Worse yet these bugs can happen in your own application even if your module is ok but someone elses module doesn't properly protect LVALS.

The section on Xlisp Internals mentioned above discusses this in more detail.


Go to the first, previous, next, last section, table of contents.