Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
evanhackett opened this issue Nov 17, 2018 · 2 comments
Open

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

evanhackett opened this issue Nov 17, 2018 · 2 comments

Comments

@evanhackett
Copy link

evanhackett commented Nov 17, 2018

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
Copy link
Member

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
Copy link
Collaborator

reiner-dolp commented Nov 26, 2018

I can reproduce this using

npm install liblouis-build #[email protected]
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 ~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants