kripken / xml.js

Port of libxml to JavaScript using Emscripten
Other
174 stars 67 forks source link

Compiles, but no longer runs with emcc 1.29.0 #4

Closed sterpe closed 9 years ago

sterpe commented 9 years ago

Running the test fails after an apparently successful compile with emcc 1.29.0.

Attempted on both OS X & Ubuntu, same result.

On further investigation this appears to be related to a function pointer cast issue.

compiling with -s EMULATE_FUNCTION_POINTER_CASTS=1 seems to work.

kripken commented 9 years ago

We should probably add that to the build flags then (pull request welcome). I wonder though why this changed. Which version worked before?

sterpe commented 9 years ago

Not sure, I found your blog with instructions here:

http://mozakai.blogspot.com/2012/03/howto-port-cc-library-to-javascript.html And these here: https://github.com/jallwine/emscripten_test/wiki/Getting-Started-With-Emscripten

Both of which are over 2.5 years old.

I think I've more or less tracked this down to the casting of functions to (xmlHashScanner) defined in libxml2/nclude/libxml/hash.c which is a viii signature.

88  typedef void (*xmlHashScanner)(void *payload, void *data, xmlChar *name);

Here's the error in node.js:


sterpe@sailor-jupiter:~/git/xml.js$ node xmllint.test.js --noout --schema test.xsd test.xml

Invalid function pointer '371' called with signature 'viii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)
This pointer might make sense in another type signature: vii: _xmlSchemaAugmentImportedIDC  vi: 0  viiii: 0  v: 0  viiiii: 0  viiiiii: 0  viiiiiii: 0  viiiiiiiii: 0  iii: 0  ii: 0  iiii: 0  iiiii: 0  i: undefined  iiiiii: 0  iiiiiii: 0  iiiiiiii: 0  
371
371

/home/sterpe/git/xml.js/xmllint.test.js:116
      throw ex;
            ^
abort() at Error
    at jsStackTrace (/home/sterpe/git/xml.js/xmllint.test.js:1019:13)
    at stackTrace (/home/sterpe/git/xml.js/xmllint.test.js:1036:22)
    at abort (/home/sterpe/git/xml.js/xmllint.test.js:423743:25)
    at nullFunc_viii (/home/sterpe/git/xml.js/xmllint.test.js:7447:1089)
    at Array.b4918 [as 371] (/home/sterpe/git/xml.js/xmllint.test.js:418385:61)
    at Array._stubHashScannerFull [as 227] (/home/sterpe/git/xml.js/xmllint.test.js:178772:31)
    at _xmlHashScanFull (/home/sterpe/git/xml.js/xmllint.test.js:74155:39)
    at _xmlHashScan (/home/sterpe/git/xml.js/xmllint.test.js:74063:2)
    at _xmlSchemaPreRun (/home/sterpe/git/xml.js/xmllint.test.js:220352:2)
    at _xmlSchemaVStart (/home/sterpe/git/xml.js/xmllint.test.js:218186:8)

Which seems to initially be occurring here:

28003       xmlHashScan(vctxt->schema->schemasImports,(xmlHashScanner)xmlSchemaAugmentImportedIDC, vctxt);

in xmlschemas.c

However, this cast seems to be done all over the place thoughout the code so fixing it might be tricky.

sterpe commented 9 years ago

In the past did emcc always emulate function pointer casts?

I will create a pull request for the compile flag.

kripken commented 9 years ago

In the far past, I guess maybe 2.5 is enough ;), we did function pointers differently, and it could explain this.

sterpe commented 9 years ago

Mind if I replace ./build.sh with a gulp file ?

kripken commented 9 years ago

What is gulp? :)

sterpe commented 9 years ago

Node streaming build tool...In this case it would probably just end up child_process.exec'ing shell commands to launch emcc etc. I'll try it out on my fork and if it seems pointless I won't bother.

http://slides.com/contra/gulp#/

rajashekhargundeti commented 8 years ago

with the latest build, i dont have any issues as the flag is already part of it.

I looked at script/test file. it is using emcc library to build xmllint-test.js file along with .mem file. I wonder how i could use this in my project since it needs emcc library and its dependencies need to be part of box, which is sometimes not possible.

xmllint.js file needs to be generated for the given set of xml and xsd documents.