The functions in this section are similar to the ones in the previous
section except with regard to error handling. Whereas the other ones
cause an error message to be printed and the process to exit in the
event of an overflow, these return to the caller, whose responsibility
it is to take appropriate action. The functions in both sections are
declared in lists.h, and should be preceded by a call to
avm_initialize_lists
.
This function is similar to
avm_join
, but will return aNULL
pointer if memory that was needed can not be allocated. ANULL
pointer would never be the result of a join under normal circumstances, so the overflow can be detected by the caller. Regardless of whether overflow occurs, the arguments are deallocated by this function and should not be referenced thereafter.
This version of the enqueue function will dispose of the operand if there isn't room to append another item and set
*
fault to a non-zero value. Other than that, it does the same asavm_enqueue
.
This function checks for arithmetic overflow when calculating the length of a list, and returns a zero value if overflow occurs. The caller can detect the error by noting that zero is not the length of any list other than
NULL
. This kind of overflow is impossible unless the host does not have long enough integers for its address space.
This function is similar to
avm_area
, except that it reacts differently to arithmetic overflow. Thefault
parameter should be the address of an integer known to the caller, which will be set to a non-zero value if overflow occurs. In that event, the value of zero will also be returned for the area. Note that it is possible for non-empty lists to have an area of zero, so this condition alone is not indicative of an error.
This function returns the
list
representation of a native unsigned long integer, provided that there is enough memory, similarly to theavm_natural
function. Unlike that function, this one will return a value ofNULL
rather than exiting the program in the event of a memory overflow. The overflow can be detected by the caller insofar as aNULL
list
does not represent any number other than zero.