Skip to content
Snippets Groups Projects
Commit 4d69bb66 authored by Liam Healy's avatar Liam Healy
Browse files

Callback with scalars uses new function gref-mpointer-form

In reference-foreign-element for callbacks being passed scalars, use
the new function gref-mpointer-form instead of grid:gref.  This
function expands to one of the gsl_*_get functions to directly get
an element from the GSL mpointer, instead of using the foreign-array
mechanism.
parent 6aec67c2
No related branches found
No related tags found
No related merge requests found
;; Generate a lambda that calls the user function; will be called by callback. ;; Generate a lambda that calls the user function; will be called by callback.
;; Liam Healy ;; Liam Healy
;; Time-stamp: <2010-06-30 19:57:28EDT funcallable.lisp> ;; Time-stamp: <2010-07-10 22:18:51EDT funcallable.lisp>
;; ;;
;; Copyright 2009 Liam M. Healy ;; Copyright 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License ;; Distributed under the terms of the GNU General Public License
...@@ -65,21 +65,35 @@ ...@@ -65,21 +65,35 @@
;;;; Reference foreign elements and make multiple-value-bind form ;;;; Reference foreign elements and make multiple-value-bind form
;;;;**************************************************************************** ;;;;****************************************************************************
(defun gref-mpointer-form
(mpointer index &optional (category 'vector) (element-type 'double-float))
"Create the call that will return an element from a GSL array mpointer."
(ffexpand
nil
(actual-gsl-function-name
'("gsl_" :category :type "_get") category element-type)
`(:pointer ,mpointer sizet ,index ,element-type)))
(defun reference-foreign-element (defun reference-foreign-element
(foreign-variable-name linear-index argspec dimension-values) (foreign-variable-name linear-index argspec dimension-values)
"Form to reference, for getting or setting, the element of a foreign "Form to reference, for getting or setting, the element of a foreign
array, or a scalar." array, or a scalar."
(if (parse-callback-argspec argspec 'dimensions) (if (parse-callback-argspec argspec 'dimensions)
(if (eql (parse-callback-argspec argspec 'array-type) :foreign-array) (if (eql (parse-callback-argspec argspec 'array-type) :foreign-array)
`(grid:gref (if (= (length (value-from-dimensions argspec dimension-values)) 2) ; matrix
,foreign-variable-name (error "Not ready for matrices yet!")
,@(let ((dims (value-from-dimensions argspec dimension-values))) #+(or)
(if (= (length dims) 2) ; matrix (gref-mpointer-form
(multiple-value-list foreign-variable-name
(floor linear-index (multiple-value-list
(first dims))) (floor linear-index
(list linear-index nil))) (first dims)))
',(grid:cffi-cl (parse-callback-argspec argspec 'element-type))) 'matrix
(parse-callback-argspec argspec 'element-type))
;; A vector
(gref-mpointer-form
foreign-variable-name linear-index 'vector
(parse-callback-argspec argspec 'element-type)))
`(cffi:mem-aref `(cffi:mem-aref
,foreign-variable-name ,foreign-variable-name
',(parse-callback-argspec argspec 'element-type) ',(parse-callback-argspec argspec 'element-type)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment