At Thu, 25 May 2006 13:42:11 +0400,
Bulat Ziganshin wrote:
>> Hello Jeremy,
>> Monday, May 22, 2006, 12:20:54 AM, you wrote:
>> > For my own needs, I cabalized and debianized the Streams library. It
> > generates binary debs for ghc6 and hugs -- but I think the hugs
> > version is broken. In any case, it is a start, you can download the
> > packaging at:
>> > http://www.n-heptane.com/nhlab/tmp/Streams_packaging.tar.gz>> can i include your work in the library itself?
Absolutely.
> is it better to include 'debian' directory to my archive or left
> this to the debian packagers?
If someone volunteers to maintain the package -- then it is probably
better to not keep a copy of the debian directory in your archive --
because it will often be out of date and confuse people -- and debian
users will be able to get the debianized source easily by typing,
'apt-get source haskell-streams'.
On the other hand -- if there is no one officially maintaing it -- it
would be useful to provide the debian directory (with a disclaimer) so
that debian users can easily build and install the .deb, since
subverting the debian package system tends to lead to long-term
complications.
> can you say how you are use my library? it's both interesting for me
> and can be helpful in deciding how it should be further developed
I am using it to serialize/deserialize haskell data structures so I
can store them in a Berkeley database.
To get them into BDB I need to convert the haskell data structure into
a C structure that looks like this:
struct __db_dbt {
void *data; /* Key/data */
u_int32_t size; /* key/data length */
};
Currently I am doing it like this -- but this will clearly fail if the
serialized data structure is longer than 512 bytes...
withDBT :: (Binary a) => a -> (Ptr DBT -> IO b) -> IO b
withDBT thedata f =
allocaBytes #{size DBT} $ \dbtPtr ->
allocaBytes 512 $ \dataPtr ->
do h <- openMemBuf dataPtr 512
withByteAlignedLE h $ flip put_ thedata
wrote <- vTell h
vClose h
#{poke DBT, data} dbtPtr (castPtr dataPtr)
#{poke DBT, size} dbtPtr ((fromIntegral wrote) :: Int)
f dbtPtr
I don't really need the file-system interface for this project -- what
would be nice is something like 'withCStringLen' and 'peekCString' for
the encode/decode functions:
type PtrLen a = (Ptr a, Int)
encodePtrLen :: (Binary a) => a -> (PtrLen a -> IO b) -> IO b
decodePtr :: (Binary a) => Ptr a -> IO a
I could simulate this by using 'encode' to convert the data structure
to a String and then use 'withCStringLen' to get the pointer and
length -- but having the intermediate String seems like it could be a
big performance hit.
Two alternative ideas are:
(1) accurately pre-calculate the size of the serialized structure and
allocate the correct amount of memory from the start
(2) start with a 'guess' and realloc the memory if the initial guess
is too small.
Both of those alternatives have their own problems -- so I think only
testing will tell what works best...
I have not looked at the library exhaustively, so if there is already
a good way to do this, let me know.
Thanks!
j.