Reputation: 1600
I am integrating 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 fails at this last line. Am not sure what am i missing. z.l.bc file is 340KB while example.swc is just 80KB.
Upvotes: 0
Views: 173
Reputation: 7061
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 $ALCHEMY_HOME/usr/local/lib
for 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
as expected.
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
was returning 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 main
to test_all
, commented out the call to test_gzio
¹, and replaced all printf
calls with fprintf
calls to 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.
footnotes:
¹ No file access in Alchemy, of course.
² stdout
is disconnected for me, but stderr
appears in my trace console
Upvotes: 1