Le 21/08/2012 18:39, Alexander Burger a écrit :
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.


(to be honest, I'm far from understanding everything myself ;-) I mostly tend to jump in, and try to understand the results I get...)

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))
       ...


This is a good "trick"! I didn't even think about using (pp) to see if my functions got interpreted correctly, but I'm sure I'll have much use for it...
Thanks!

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



Thanks. I've got some problems understanding what went where from reading the doc and tuto...

Then I would stay with some naming conventions, define 'Dest' and

Yes... I NEED to re-read the naming conventions from the doc...

'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)


Thanks for everything!

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

Reply via email to