next up previous contents
Next: 6.9 Unix Interrupts Up: 6 UNIX Interface Previous: 6.7 File Descriptor Streams

6.8 Making Sense of Mach Return Codes

Whenever a remote procedure call returns a Unix error code (such as kern_return_t), it is usually prudent to check that code to see if the call was successful. To relieve the programmer of the hassle of testing this value himself, and to centralize the information about the meaning of non-success return codes, CMU Common Lisp provides a number of macros and functions. See also  get-unix-error-msg (page gif).

[Function]
system:gr-error function gr &optional context

Signals a Lisp error, printing a message indicating that the call to the specified function failed, with the return code gr. If supplied, the context string is printed after the function name and before the string associated with the gr. For example:

* (gr-error 'nukegarbage 3 "lost big")

Error in function GR-ERROR: NUKEGARBAGE lost big, no space. Proceed cases: 0: Return to Top-Level. Debug (type H for help) (Signal #<Conditions:Simple-Error.5FDE0>) 0]

[Macro]
system:gr-call function &rest args
system:gr-call* function &rest args

These macros can be used to call a function and automatically check the GeneralReturn code and signal an appropriate error in case of non-successful return. gr-call returns nil if no error occurs, while gr-call* returns the second value of the function called.

* (gr-call mach:port_allocate *task-self*)
NIL
* 

[Macro]
system:gr-bind (tex2html_wrap_inline17166vartex2html_wrap_inline17172) (function tex2html_wrap_inline17166argtex2html_wrap_inline17172) tex2html_wrap_inline17166formtex2html_wrap_inline17172

This macro can be used much like multiple-value-bind to bind the vars to return values resulting from calling the function with the given args. The first return value is not bound to a variable, but is checked as a GeneralReturn code, as in gr-call.

* (gr-bind (port_list port_list_cnt)
           (mach:port_select *task-self*)
    (format t "The port count is  S." port_list_cnt)
    port_list)
The port count is 0.
#<Alien value>
* 


Raymond Toy
Mon Jul 14 09:11:27 EDT 1997