Re: LZO decompression utility method on Windows using ctypes for dummies
Thomas Stover <[email protected]>
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
> From: Kim Hansen <[email protected]> > There is also a header file lzo1x.h, which contains the call signature for > the lzo decompress function I should bind to: > > /* safe decompression with overrun testing */ > LZO_EXTERN(int) > lzo1x_decompress_safe ( const lzo_byte *src, lzo_uint src_len, > lzo_byte *dst, lzo_uintp dst_len, > lzo_voidp wrkmem /* NOT USED */ ); 1) You'll have to look at the documentation for that API if you haven't already. Often functions like this require some steps to be taken first, and possibly after the real work is done. So for instance you might need functions to initialize and finalize a lzo context. Not that you do, just look into that. 2) "lzo_byte", etc are not real variable types in C. Those are "typedefs" which frustratingly conceal the real types to those reading the function declaration above. So you will need to find out what the real types are for ctypes. This usually can be found in the same header. It is very likely that they are: lzo_byte : unsigned char lzo_uint : unsigned int lzo_uintp : unsigned int * lzo_voidp : void * > in_len = len - 5; > out_len = (in[1] << 24) | (in[2] << 16) | (in[3] << 8) | in[4]; > if ((int)out_len < 0 || in_len > out_len + out_len / 64 + 16 + 3) > goto header_error; > Here they appear to be looking at the compressed input directly, using an understanding of the file format, to figure out how big the decompressed version will be so that the required space can be first allocated. Surely there is a better way than that. Once that is done, an appropriately sized buffer can be allocated from within ctypes via create_string_buffer(). -- www.thomasstover.com NO CARRIER ------------------------------------------------------------------------------ This SF.net Dev2Dev email is sponsored by: Show off your parallel programming skills. Enter the Intel(R) Threading Challenge 2010. http://p.sf.net/sfu/intel-thread-sfd