liblouis / liblouis-js

Port/cross-compiled version of liblouis to Javascript
GNU General Public License v3.0
11 stars 4 forks source link

Translating numbers and spaces throws error with en-ueb-g2 #50

Open evanhackett opened 5 years ago

evanhackett commented 5 years ago

I'm having issues translating simple strings that contain numbers and spaces. It is hard to identify a pattern regarding what exactly causes the error. One example is the string "1 2 3".

const liblouis = require('liblouis')

console.log(liblouis.version());

liblouis.enableOnDemandTableLoading('');

var unicode_braille = liblouis.translateString('tables/unicode.dis,tables/en-ueb-g2.ctb', "1 2 3")

The above code has this output:

3.2.0

/Users/evan/dev/7apps/UEB-Admin/backend/node_modules/liblouis-build/build-no-tables-utf16.js:115
      throw ex;
      ^
abort() at Error
    at jsStackTrace (/Users/evan/dev/7apps/UEB-Admin/backend/node_modules/liblouis-build/build-no-tables-utf16.js:1104:13)
    at stackTrace (/Users/evan/dev/7apps/UEB-Admin/backend/node_modules/liblouis-build/build-no-tables-utf16.js:1121:12)
    at Object.abort (/Users/evan/dev/7apps/UEB-Admin/backend/node_modules/liblouis-build/build-no-tables-utf16.js:60642:44)
    at _abort (/Users/evan/dev/7apps/UEB-Admin/backend/node_modules/liblouis-build/build-no-tables-utf16.js:1725:22)
    at _free (/Users/evan/dev/7apps/UEB-Admin/backend/node_modules/liblouis-build/build-no-tables-utf16.js:57805:8)
    at Object.asm._free (/Users/evan/dev/7apps/UEB-Admin/backend/node_modules/liblouis-build/build-no-tables-utf16.js:60273:19)
    at LiblouisEasyApi.translateString (/Users/evan/dev/7apps/UEB-Admin/backend/node_modules/liblouis/easy-api.js:233:13)
    at LiblouisEasyApi.translateString (/Users/evan/dev/7apps/UEB-Admin/backend/node_modules/liblouis/easy-api.js:484:24)
    at Object.<anonymous> (/Users/evan/dev/7apps/UEB-Admin/backend/test-liblouis.js:7:32)
    at Module._compile (module.js:635:30)

Oddly enough, the string "1 2" does work.

Any idea what could be causing this problem? Is this a known bug or a misuse of the api?

Thanks

Update: we tested the C liblouis library using the docker container referenced in the docs. The string "1 2 3" does indeed work with the C version, so this seems to be a problem specific to the javascript build.

bertfrees commented 5 years ago

I'm sorry, I can't answer this question. Reiner can. I don't know of any bug like this in the core library. Translating the string "1 2 3" using standard command line tools works fine, so it must be something in the JS bindings.

reiner-dolp commented 5 years ago

I can reproduce this using

npm install liblouis-build #liblouis-build@3.2.0-rc
npm install liblouis #liblouis 0.4.0

The progam crashes while trying to free memory of the output buffer of translateString. The issue does not occur if you use a utf32 build instead of a utf16 build:

<!doctype html>
<script src="node_modules/liblouis/easy-api.js"></script>
<script>
louAsync = new LiblouisEasyApiAsync({
    easyapi: "node_modules/liblouis/easy-api.js",
    capi: "node_modules/liblouis-build/build-no-tables-utf32.js"
});

louAsync.enableOnDemandTableLoading("node_modules/liblouis-build/tables/", function() {});
louAsync.setLogLevel(LiblouisEasyApi.prototype.LOG.ALL, function() {});

louAsync.registerLogCallback(function(logLevel, msg){
    console.log(logLevel, msg);
});

louAsync.version(function(version) {
    console.info("Liblouis Version:", version);
})

louAsync.translateString(
  ['unicode.dis', 'en-ueb-g2.ctb'].join(","),
  '1 2 3', function(msg) { console.log("RESULT:", msg); }
);
</script>

produces:

Liblouis Version: 3.2.0
ALL Performing translation: tableList=unicode.dis,en-ueb-g2.ctb, inlen=24 
ALL Inbuf=0x00000031 0x00000020 0x00000032 0x00000020 0x00000033 0x00000000 0x00000000 0x00000023 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000013 0x00000018 0x00000000 0x00000000 0x00000013 0x00000018 0x00000000 0x00000000 0x0000017B ~ 1 2 3 
DEBUG found table unicode.dis 
DEBUG found table en-ueb-g2.ctb 
DEBUG found table en-ueb-g1.ctb 
DEBUG found table en-ueb-chardefs.uti
DEBUG found table latinLetterDef8Dots.uti
DEBUG found table en-ueb-math.ctb 
DEBUG found table braille-patterns.cti 
ALL Translation complete: outlen=7 
ALL Outbuf=0x0000283C 0x00002801 0x00002810 0x00002803 0x00002810 0x0000283C 0x00002809 ~  
RESULT: ⠼⠁⠐⠃⠐⠼⠉

Using the 16bit build we get the correct result, but freeing the C memory of the result after copying it into Javascript fails:

Liblouis Version: 3.2.0
ALL Performing translation: tableList=unicode.dis,en-ueb-g2.ctb, inlen=12 
ALL Inbuf=0x0031 0x0020 0x0032 0x0020 0x0033 0x0000 0x0013 0x0000 0x0000 0x0000 0x0000 0x0000 ~ 1 2 3 
DEBUG found table unicode.dis 
DEBUG found table en-ueb-g2.ctb
DEBUG found table en-ueb-g1.ctb 
DEBUG found table en-ueb-chardefs.uti 
DEBUG found table latinLetterDef8Dots.uti
DEBUG found table en-ueb-math.ctb 
DEBUG found table braille-patterns.cti 
ALL Translation complete: outlen=7 
ALL Outbuf=0x283C 0x2801 0x2810 0x2803 0x2810 0x283C 0x2809 ~