Skip to content

Instantly share code, notes, and snippets.

@Ralith
Created July 18, 2010 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ralith/480086 to your computer and use it in GitHub Desktop.
Save Ralith/480086 to your computer and use it in GitHub Desktop.
(defmacro with-double-ptr ((inner outer c-type) &body body)
"Creates a pointer INNER (ostensibly of type C-TYPE) which is addressed by OUTER. Only OUTER is deallocated.
This is intended for use with functions which set take a pointer to a pointer and set the inner pointer's value to the address of some C-TYPE. Note that no typechecking is done."
`(let ((,inner (make-pointer 0)))
(with-foreign-object (,outer '(:pointer ,c-type))
(setf (mem-ref ,outer :pointer) ,inner)
,@body)))
(defmacro with-double-ptr-wfo ((inner outer c-type) &body body)
"Creates a pointer INNER (ostensibly of type C-TYPE) which is addressed by OUTER."
`(with-foreign-objects ((,inner ',c-type)
(,outer '(:pointer ,c-type)))
(setf (mem-ref ,outer :pointer) ,inner)
,@body))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment