From: Jason Kantz
Subject: foreign function help
Date: 
Message-ID: <388F7964.4E7598B6@kantz.com>
Looking for pointers on using ff's to get gd gif maker in CL
see http://kantz.com/jason/ff/gd.lisp
http://kantz.com/jason/ff/gd.c
http://kantz.com/jason/ff/gd.h



-- 
Jason Kantz
http://kantz.com/jason

From: Jason Kantz
Subject: Re: foreign function help
Date: 
Message-ID: <388FAF5D.D2C7A366@kantz.com>
My girlfriend was pulling me away from the computer to go out to eat,
so I didn't have time to give much detail in the prev post.

gd is a c graphics library for drawing images and writing results as
.gif files.  I'd like to bring it into CL to use w/ CL-HTTP.

I successfully brought the line drawing function into CL, but have
some trouble w/ polygons b/c of the array of points.

I'm having pains getting the array of points back and forth in the
polygon fun.

Here's my attempt- 

(def-foreign-type gdPoint
    (:struct (x :int)
             (y :int)))

(def-foreign-call (gdImagePolygon "gdImagePolygon")
    ((im :foreign-address) 
     (points (* :gdPoint) (simple-array gdPoint (*)))
     pointsTotal color) :returning :void)


(defun make-point (x y)
  (let ((obj (ff:allocate-fobject 'gdPoint)))
    (setf (fslot-value obj 'x) x)
    (setf (fslot-value obj 'y) y)
    obj))

(defmacro make-gdPoint-array (&rest xys)
  `(make-array ,(/ (length xys) 2) 
	      :initial-contents
	      (list ,@(loop for (x y) on xys by #'cddr
			  collect (make-point x y)))))

;; doesn't work
(defmacro draw-polygon (im xys color)
  `(gdImagePolygon ,im (make-gdPoint-array ,@xys) ,(/ (length xys) 2)
,color))


see http://kantz.com/jason/ff for all the goods.
From: Jason Kantz
Subject: Re: foreign function help
Date: 
Message-ID: <388FAEF2.3AB4A7F3@kantz.com>
My girlfriend was pulling me away from the computer to go out to eat,
so I didn't have time to give much detail in the prev post.

gd is a c graphics library for drawing images and writing results as
.gif files.  I'd like to bring it into CL to use w/ CL-HTTP.

I successfully brought the line drawing function into CL, but have
some trouble w/ polygons b/c of the array of points.

I'm having pains getting the array of points back and forth in the
polygon fun.

Here's my attempt- 

(def-foreign-type gdPoint
    (:struct (x :int)
             (y :int)))

(def-foreign-call (gdImagePolygon "gdImagePolygon")
    ((im :foreign-address) 
     (points (* :gdPoint) (simple-array gdPoint (*)))
     pointsTotal color) :returning :void)


(defun make-point (x y)
  (let ((obj (ff:allocate-fobject 'gdPoint)))
    (setf (fslot-value obj 'x) x)
    (setf (fslot-value obj 'y) y)
    obj))

(defmacro make-gdPoint-array (&rest xys)
  `(make-array ,(/ (length xys) 2) 
	      :initial-contents
	      (list ,@(loop for (x y) on xys by #'cddr
			  collect (make-point x y)))))

(defmacro draw-polygon (im xys color)
  `(gdImagePolygon ,im (make-gdPoint-array ,@xys) ,(/ (length xys) 2)
,color))

see http://kantz.com/jason/ff for all the goods.
From: Joe Marshall
Subject: Re: foreign function help [NOISE]
Date: 
Message-ID: <RtZj4.55709$Rj5.44299@dfw-read.news.verio.net>
Jason Kantz <·····@kantz.com> wrote in message
······················@kantz.com...
> My girlfriend was pulling me away from the computer to go out to eat,
> so I didn't have time to give much detail in the prev post.
>

Try WITHOUT-INTERRUPTS.
From: Tim Bradshaw
Subject: Re: foreign function help [NOISE]
Date: 
Message-ID: <ey3d7qnldyy.fsf@cley.com>
* Joe Marshall wrote:
> Jason Kantz <·····@kantz.com> wrote in message

> Try WITHOUT-INTERRUPTS.

We all know that WITHOUT-INTERRUPTS is pretty toxic on a
multiprocessor system, you should be using a lock of some kind (on the
door perhaps?).

--tim
From: Joe Marshall
Subject: Re: foreign function help [NOISE]
Date: 
Message-ID: <C%0k4.55841$Rj5.45423@dfw-read.news.verio.net>
Well, if he were a multiprocessor, he could answer the door AND post to the
usenet
simultaneously.  But it does sound like a resource management problem.

Tim Bradshaw <···@cley.com> wrote in message
····················@cley.com...
> * Joe Marshall wrote:
> > Jason Kantz <·····@kantz.com> wrote in message
>
> > Try WITHOUT-INTERRUPTS.
>
> We all know that WITHOUT-INTERRUPTS is pretty toxic on a
> multiprocessor system, you should be using a lock of some kind (on the
> door perhaps?).
>
> --tim
>
From: Robert Monfera
Subject: Re: foreign function help [NOISE]
Date: 
Message-ID: <3890A51C.90241164@fisec.com>
Joe Marshall wrote:
>
> Well, if he were a multiprocessor, he could answer the door AND post to the
> usenet
> simultaneously.  But it does sound like a resource management problem.

Unless his memory is leaking, he remembers to empty the garbage can
regularly (triggered by his girlfriend's request), during which he still
has to leave his desk.
From: Jason Kantz
Subject: Re: foreign function help [MUSIC]
Date: 
Message-ID: <3891C5CC.C3C17164@kantz.com>
The thing I find hardest about programming in Lisp is learning
invented syntax with terse documentation.

For those who may have been interested in more than my resource
management problem ... what was giving me grief was this--

I had this foreign type

(def-foreign-type gdPoint
    (:struct (x :int)
             (y :int)))

and a foreign c function that took an aray of gdPoints.

To make one of those arrays I naievly thought I could do this within a
macro

`(allocate-fobject '(:array (* :gdPoint) ,(/ (length xys) 2)) :c)

This seemed to have worked.  I was able to access all the parts from
Lisp.
But when I passed the address of this foreign object to my function I
got a 
hanging Lisp that seemed to run infefinitely, wouldn't take a C-c C-c,
and 
wouldn't give any errors to debug.

After way too much time, I finally discovered that the syntax is like
this:

`(allocate-fobject '(:array (:struct (x :int) (y :int)) ,(/ (length xys)
2)) :c)

and then I heard music.

-- 
Jason Kantz
http://kantz.com/jason
From: Jason Kantz
Subject: Re: foreign function help
Date: 
Message-ID: <388FAF86.F473DA41@kantz.com>
My girlfriend was pulling me away from the computer to go out to eat,
so I didn't have time to give much detail in the prev post.

gd is a c graphics library for drawing images and writing results as
.gif files.  I'd like to bring it into CL to use w/ CL-HTTP.

I successfully brought the line drawing function into CL, but have
some trouble w/ polygons b/c of the array of points.

I'm having pains getting the array of points back and forth in the
polygon fun.

Here's my attempt- 

(def-foreign-type gdPoint
    (:struct (x :int)
             (y :int)))

(def-foreign-call (gdImagePolygon "gdImagePolygon")
    ((im :foreign-address) 
     (points (* :gdPoint) (simple-array gdPoint (*)))
     pointsTotal color) :returning :void)


(defun make-point (x y)
  (let ((obj (ff:allocate-fobject 'gdPoint)))
    (setf (fslot-value obj 'x) x)
    (setf (fslot-value obj 'y) y)
    obj))

(defmacro make-gdPoint-array (&rest xys)
  `(make-array ,(/ (length xys) 2) 
	      :initial-contents
	      (list ,@(loop for (x y) on xys by #'cddr
			  collect (make-point x y)))))

;; doesn't work
(defmacro draw-polygon (im xys color)
  `(gdImagePolygon ,im (make-gdPoint-array ,@xys) ,(/ (length xys) 2)
,color))


see http://kantz.com/jason/ff for all the goods.
From: Jason Kantz
Subject: Re: foreign function help
Date: 
Message-ID: <388FAFE4.AD775D6C@kantz.com>
My girlfriend was pulling me away from the computer to go out to eat,
so I didn't have time to give much detail in the prev post.

gd is a c graphics library for drawing images and writing results as
.gif files.  I'd like to bring it into CL to use w/ CL-HTTP.

I successfully brought the line drawing function into CL, but have
some trouble w/ polygons b/c of the array of points.

I'm having pains getting the array of points back and forth in the
polygon fun.

Here's my attempt- 

(def-foreign-type gdPoint
    (:struct (x :int)
             (y :int)))

(def-foreign-call (gdImagePolygon "gdImagePolygon")
    ((im :foreign-address) 
     (points (* :gdPoint) (simple-array gdPoint (*)))
     pointsTotal color) :returning :void)


(defun make-point (x y)
  (let ((obj (ff:allocate-fobject 'gdPoint)))
    (setf (fslot-value obj 'x) x)
    (setf (fslot-value obj 'y) y)
    obj))

(defmacro make-gdPoint-array (&rest xys)
  `(make-array ,(/ (length xys) 2) 
	      :initial-contents
	      (list ,@(loop for (x y) on xys by #'cddr
			  collect (make-point x y)))))

;; doesn't work
(defmacro draw-polygon (im xys color)
  `(gdImagePolygon ,im (make-gdPoint-array ,@xys) ,(/ (length xys) 2)
,color))


see http://kantz.com/jason/ff for all the goods.