Yo integraré flashzlib into one of my flash project. As mentioned in documentation of project. I have successfully generated libz.a and z.l.bc and pushed libs and headers in appropriate places.
Now, I have written this small wrapper https://gist.github.com/65d3c7ff683b326ecd22. This compiles just fine using:
gcc example1_as3.c -lz -O3 -Wall -swc -o example.swc
This is included into flash project like this (uncompressedData is a byteArray):
private var loader:CLibInit = new CLibInit; private var lib:Object = loader.init(); logger.info("B : " + lib.returnString(uncompressedData, uncompressedData.length) + "");
But flash file falla at this last line. Am not sure what am i missing. z.l.bc file is 340KB while example.swc is just 80KB.
preguntado el 08 de noviembre de 11 a las 17:11
It's failing for one of two reasons. Either Alchemy isn't finding
z.l.bc (and isn't bothering to tell you about it), or you're not catching and reporting your error codes correctly.
As I mentioned in the question comments, I was getting a runtime error on the
inflateInit invocation. For my case, it turned out that Alchemy wasn't searching
z.l.bc like it was supposed to be. This was solved by moving it to
/usr/local/lib instead. After that, your code returned
Z_OK como se esperaba.
I notice you have all the
CHECK_ERR calls commented out, which means that you'll enter an infinite loop if you comment out the early return on
example.c:52 since you're not checking for errors on your
inflate call in the following unconditional
for block. For me,
inflate estaba volviendo
Z_DATA_ERROR since I was just handing it some UTF bytes for test purposes.
Speaking of testing, I notice that there's a small test suite supplied by flashzlib:
I borrowed this code, renamed
test_all, commented out the call to
test_gzio¹, and replaced all
printf llamadas con
fprintf llamadas a
stderr instead². This is the result:
zlib version 1.2.3 = 0x1230, compile flags = 0x2000095 uncompress(): hello, hello! inflate(): hello, hello! large_inflate(): OK after inflateSync(): hello, hello! inflate with dictionary: hello, hello! 0
Everything appears to be in order.
notas al pie:
¹ No file access in Alchemy, of course.
stdout is disconnected for me, but
stderr appears in my trace console