Name

with-foreign-object — Wraps the allocation of a foreign object around a body of code. Macro

Syntax

	  with-foreign-object (var type) &body body => form-return
	

Arguments and Values

var

The variable name to bind.

type

The type of foreign object to allocate. This parameter is evaluated.

form-return

The result of evaluating the body.

Description

This function wraps the allocation, binding, and destruction of a foreign object. On CMUCL and Lispworks platforms the object is stack allocated for efficiency. Benchmarks show that AllegroCL performs much better with static allocation.

Examples

(defun gethostname2 ()
  "Returns the hostname"
  (uffi:with-foreign-object (name '(:array :unsigned-char 256))
    (if (zerop (c-gethostname (uffi:char-array-to-pointer name) 256))
	(uffi:convert-from-foreign-string name)
	(error "gethostname() failed."))))
	

Side Effects

None.

Affected by

None.

Exceptional Situations

None.