Subject: [clisp-list] Re: Problem with ffi:foreign-pointer

From: Roland Averkamp <[email-masked]>
Date: Thu Sep 11 10:01:51 2003

Hello,

I have a foreign-adress and want to read the double-float at the memory
location the address points to.

So I tried to change the foreign-address behind a foreign-variable object.

How can I do this otherwise?

I am trying to port the lisp odbc interface from Paul Meurer to clisp. 
And for this interface I need functions like "read-double-float" which read
the double-float from a given memory location.

Bye,
Roland

-- 
COMPUTERBILD 15/03: Premium-e-mail-Dienste im Test
--------------------------------------------------
1. GMX TopMail - Platz 1 und Testsieger!
2. GMX ProMail - Platz 2 und Preis-Qualitätssieger!
3. Arcor - 4. web.de - 5. T-Online - 6. freenet.de - 7. daybyday - 8. e-Post

---

From: Sam Steingold <[email-masked]>
Date: Thu Sep 11 10:52:41 2003

>* Roland Averkamp <[email-masked]> [2003-09-11 18:18:02 +0200]:
>
> I have a foreign-adress and want to read the double-float at the
> memory location the address points to.

<http://clisp.cons.org/impnotes/dffi.html#cast>
<http://clisp.cons.org/impnotes/dffi.html#with-c-place>

(with-c-place (c <your foreign address>)
  (cast c 'double-float))

or maybe

(with-c-place (c <your foreign address>)
  (cast c '(c-ptr double-float)))

UNTESTED!!!

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
If you try to fail, and succeed, which have you done?

---

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Thu Sep 11 20:51:38 2003

>Von: Roland Averkamp [mailto:[email-masked]]
>Hello,
>I am using clisp-2.31 and did the following at the prompt:
>
>[17]> (ffi:unsigned-foreign-address 65535)
>#<FOREIGN-ADDRESS #x0000FFFF>
>[18]> (ffi:foreign-pointer (ffi:unsigned-foreign-address 65535))
>#<FOREIGN-POINTER #x00000000>
>[19]> (ffi:foreign-address (ffi:foreign-pointer
>(ffi:unsigned-foreign-address 65535)))
>#<FOREIGN-ADDRESS #x00000000>
>[20]> 

>I would have expected as results #<FOREIGN-POINTER #x0000ffff> and
>#<FOREIGN-ADDRESS #x0000ffff>

Nope.

1. What do you need foreign-pointer objects for? Normally people manipulate FOREIGN-ADDRESS objects (which are used with C-POINTER type declarations).
Until the shared library FFI code became available for MS-Windows and UNIX, I bet very few people even knew about the existance of FOREIGN-POINTER objects.

2. most functions returning FOREIGN-ADDRESS objects return a pointer object relative to what I call the current FFI session pointer. This one is unique per invocation of CLISP and is a #<FOREIGN-POINTER #x00000000> object.
Therefore what you observe is completely normal.

This is part of a yet not documented dependency mechanism and allows setting all sorts of foreign-address obejct invalid with a single call. I sketched some parts in clisp-list . E.g. all pointers become invalid when the session is terminated.
More precisely, you cannot save a FFI pointer in a Lisp image file and reuse it in a new invocation (unless you hack the C code). It will have been marked invalid.

3. I never came to check what Sam implemented as FOREIGN-POINTER and SETF FOREIGN-POINTER based on my talks in clisp-list. I still have to look at that code.
In my talks/thoughts/proposals, there were means to obtain a #<FOREIGN-POINTER #xwantedaddress> object.

4. Exceptions to 2. are FOREIGN-LIBRARY, WITH-C-VAR, WITH-FOREIGN-OBJECT, WITH-FOREIGN-STRING, ALLOCATE-FOREIGN. This permits to control the validity of the memory regions allocated by these functions. When their scope exists, or when FOREIGN-FREE is used, the pointer is marked invalid.

Regards,
	Jörg Höhle.

---

From: amit phalgune <[email-masked]>
Date: Fri Sep 12 11:55:43 2003

Hi,
I would like to put a escape character in a string Like :

(setf A "Z:\ABC")
but this remove the "\" character. How do I keep it ?

Thanks
Amit

---

From: Sam Steingold <[email-masked]>
Date: Fri Sep 12 12:31:50 2003

>* amit phalgune <[email-masked]> [2003-09-11 22:03:57 -0700]:
>

(setf A "Z:\\ABC")

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
In C you can make mistakes, while in C++ you can also inherit them!

---

From: amit phalgune <[email-masked]>
Date: Fri Sep 12 13:25:28 2003

Well,
I did that and then once I do a format on A. it shows "Z:\\ABC" so I am
not sure if it works.
Amit

On Fri, 12 Sep 2003, Sam Steingold wrote:

> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> clisp-list mailing list
> [email-masked]
> https://lists.sourceforge.net/lists/listinfo/clisp-list
>

---

From: Randall R Schulz <[email-masked]>
Date: Fri Sep 12 14:00:06 2003

Amit,

>I did that and then once I do a format on A. it shows "Z:\\ABC" so I am

You're probably using a format directive that produces readable output. 
I.e., you're using ~S. To get the string unaltered (for re-reading), use ~A.

Randall Schulz

---

From: amit phalgune <[email-masked]>
Date: Fri Sep 12 16:32:05 2003

Thanks,
That works..
Amit

---

From: amit phalgune <[email-masked]>
Date: Sun Sep 14 18:54:03 2003

Hi Guys,
I need your help again.
There seems to be a macro WITHOUT-SCHEDULING in LISP. I was looking for he
problems and whther CLISP supports it.
I found on one of the postings on comp.lang.lisp that CLISP does not have
a corresponding implementation of WITHOUT-SCHEDULING .

Is this true. Can anyone suggest a work around or can share with their
code for the work around they have already found .

Thanks in advance,
Amit

---

From: Pascal J.Bourguignon <[email-masked]>
Date: Sun Sep 14 19:49:19 2003

amit phalgune writes:
> Hi Guys,
> I need your help again.
> There seems to be a macro WITHOUT-SCHEDULING in LISP. 

What LISP?  clisp implements _the_ Common-Lisp.

There are 978 symbols in the COMMON-LISP package.
What's not in the list IS NOT Common-Lisp:
http://www.lisp.org/HyperSpec/FrontMatter/Symbol-Index-Alphabetical.html

I  too note  that some  programs use  some  without-scheduling symbol,
taken from the MP package, whatever it may be, and it's even a PRIVATE
symbol since they have to use two ':': (mp::without-scheduling ...).

And they dare call  their programs Common-Lisp programs!  Well, that's
not my idea of a portable  Common-Lisp program.  (Yes, I don't want to
consider non-portable programs).

> I was looking for he problems and whther CLISP supports it.

Well, since there  is no multi-threading in clisp, we  can say that we
are always working without scheduling.  So you could define that macro
as:

(DEFPACKAGE "MP")
(DEFMACRO MP::WITHOUT-SCHEDULING (&BODY BODY) `(PROGN ,@BODY))

-- 
__Pascal_Bourguignon__
http://www.informatimago.com/
Do not adjust your mind, there is a fault in reality.

---

From: Roman Belenov <[email-masked]>
Date: Sun Sep 14 23:15:22 2003

> I did that and then once I do a format on A. it shows "Z:\\ABC" so I am

It seems that you did (format t "~S" A) instead of (format t "~A"
A). The former gives printable representation that can be read back by
the reader, so that escape characters are inserted when needed, while
the latter prints only the actual characters of the string.

-- 
 							With regards, Roman.