Re: (native) wrapper around zlib

2012-08-23 Thread Laurent Artaud

Le 23/08/2012 08:57, Alexander Burger a écrit :

Hi Laurent,


It took the error message I got when I worked on the uncompress
function to realize that, indeed, InBuf should be a byte list, and
not a string... (this is binary data, and there are null bytes, and
a (pack (mapcar 'char TheList)) removes said bytes...)
Looking at the Memory Management section at
http://software-lab.de/doc/native.html, I am considering using
malloc (I will have many calls) but for what I have in mind, I would
need to be able to set and get the value of a malloc-ed variable
outside of a native call.
Is it possible?


Yes. This should be possible with 'struct'.



Thanks! It works perfectly!

Regards,
--
Laurent ARTAUD (laurent.art...@free.fr)
--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: (native) wrapper around zlib

2012-08-21 Thread Alexander Burger
Hi Laurent,

 # uLong compressBound (uLong sourceLen)
 # int compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
 uLong sourceLen, int level)

I'm afraid I can give only a partial answer, as I don't understand the
exact requirements of these functions well enough.

However, here are some points:

The lines

   '(dest `(genCharBuff bufSize) . 0)  # *dest
   '(destLen (8 . N) . `bufSize)   # *destLen

are probably a problem. For one thing, using a read macro (with
backquote) here doesn't do what you expect, because 'bufSize' is not
bound yet when the function 'Zcompress2' is read.

You can check that with (pp 'Zcompress2):
   ...
   (native libz.so
  ...
  '(dest (NIL B) . 0)
  '(destLen (8 . N))
  ...

Also, the size and type specifier must be reversed in the cons pairs.
Correct would probably be

   (dest (bufSize B . bufSize))  # Return in 'dest', buffer size, return 
bufSize bytes

and

   (destLen (8 . N) (bufSize . 8))  # Pass buffer size as long, return a long


Then I would stay with some naming conventions, define 'Dest' and
'DestLen' as local variables, and get finally:

   (de Zcompress2 (InBuf Level)
  (let (InBufSize (size InBuf)  BufSize (ZcompressBound InBufSize))
 (use (Dest DestLen)
(list
   (native
  libz.so# lib file
  compress2  # function
  'I   # return value (error status)
  (list 'Dest  # *dest
 (cons BufSize 'B BufSize) )
  (list 'DestLen   # *destLen
 (8 . N)
 (cons BufSize 8) )
  InBuf# *source
  InBufSize# sourceLen
  Level )  # level
   (head DestLen Dest) ) ) ) )

Notes:
   - For system libraries, you don't need to pass the full path. Thus,
 instead of (native /usr/lib/libz.so ..) you can simply write
 (native libz.so ..)

   - I don't know what 'compress2' does with multibyte UTF-8 chars, but
 in any case it is better to use (size inBuf) instead of (length
 inBuf)

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe