aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-03-21 19:50:03 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-03-21 19:50:03 -0700
commitb956a15fb40aa661c7feb0f8b078f1bb0ea1d622 (patch)
tree6b8a457060fd2765232d0d3705fde59f674383cc
parent24856d20699818b35f01963e4144c87d1a5c56ff (diff)
poppler-related tweaks
-rw-r--r--src/jsifier.js2
-rw-r--r--src/library.js10
-rw-r--r--tests/poppler/poppler/Array.cc4
-rw-r--r--tests/poppler/poppler/Dict.cc5
-rw-r--r--tests/poppler/poppler/Object.h3
-rw-r--r--tests/poppler/readme.txt5
-rw-r--r--tests/runner.py36
-rwxr-xr-xtools/exec_llvm.py6
8 files changed, 61 insertions, 10 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 7a7bc47f..2e525649 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -803,7 +803,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
// TODO: figure out something here along the lines of return '(' + Math.pow(2, 32) + '+((' + value + ')|0))';
}
}
- return op + 'Sign(' + value + ', ' + bits + ', ' + correctSpecificSign() + ')'; // If we are correcting a specific sign here, do not check for it
+ return op + 'Sign(' + value + ', ' + bits + ', ' + Math.floor(correctSpecificSign()) + ')'; // If we are correcting a specific sign here, do not check for it
} else {
return value;
}
diff --git a/src/library.js b/src/library.js
index 08daceb1..54834d17 100644
--- a/src/library.js
+++ b/src/library.js
@@ -1253,10 +1253,18 @@ function reSign(value, bits, ignore) {
: Math.pow(2, bits-1);
if (value >= half) {
#if CHECK_SIGNS
- if (!ignore) CorrectionsMonitor.note('ReSign');
+ if (!ignore) CorrectionsMonitor.note('ReSign');
#endif
value = -2*half + value; // Cannot bitshift half, as it may be at the limit of the bits JS uses in bitshifts
}
+#if CHECK_SIGNS
+ // If this is a 32-bit value, then it should be corrected at this point. And,
+ // without CHECK_SIGNS, we would just do the |0 shortcut, so check that that
+ // would indeed give the exact same result.
+ if (bits === 32 && (value|0) !== value && typeof value !== 'boolean') {
+ CorrectionsMonitor.note('ReSign');
+ }
+#endif
return value;
}
diff --git a/tests/poppler/poppler/Array.cc b/tests/poppler/poppler/Array.cc
index e7ec4e7d..4c09b034 100644
--- a/tests/poppler/poppler/Array.cc
+++ b/tests/poppler/poppler/Array.cc
@@ -59,6 +59,10 @@ void Array::add(Object *elem) {
size *= 2;
}
elems = (Object *)greallocn(elems, size, sizeof(Object));
+ // XXX Emscripten: Initialize the entries, to prevent undefined values
+ for (int i=length; i<size; i++) {
+ elems[i].zeroUnion();
+ }
}
elems[length] = *elem;
++length;
diff --git a/tests/poppler/poppler/Dict.cc b/tests/poppler/poppler/Dict.cc
index 1428113b..548508c8 100644
--- a/tests/poppler/poppler/Dict.cc
+++ b/tests/poppler/poppler/Dict.cc
@@ -84,6 +84,7 @@ Dict::Dict(Dict* dictA) {
entries = (DictEntry *)gmallocn(size, sizeof(DictEntry));
for (int i=0; i<length; i++) {
entries[i].key = strdup(dictA->entries[i].key);
+ entries[i].val.zeroUnion(); // XXX Emscripten
dictA->entries[i].val.copy(&entries[i].val);
}
}
@@ -112,6 +113,10 @@ void Dict::add(char *key, Object *val) {
size *= 2;
}
entries = (DictEntry *)greallocn(entries, size, sizeof(DictEntry));
+ // XXX Emscripten: Initialize the entries, to prevent undefined values
+ for (int i=length; i<size; i++) {
+ entries[i].val.zeroUnion();
+ }
}
entries[length].key = key;
entries[length].val = *val;
diff --git a/tests/poppler/poppler/Object.h b/tests/poppler/poppler/Object.h
index 72ff6678..fc61a019 100644
--- a/tests/poppler/poppler/Object.h
+++ b/tests/poppler/poppler/Object.h
@@ -111,7 +111,8 @@ enum ObjType {
class Object {
public:
// clear the anonymous union as best we can -- clear at least a pointer
- void zeroUnion() { this->name = NULL; }
+ // XXX Emscripten: Also null out ref.gen
+ void zeroUnion() { this->name = NULL; this->ref.gen = 0; }
// Default constructor.
Object():
diff --git a/tests/poppler/readme.txt b/tests/poppler/readme.txt
new file mode 100644
index 00000000..e965f0d9
--- /dev/null
+++ b/tests/poppler/readme.txt
@@ -0,0 +1,5 @@
+This is Poppler. See README and COPYING.
+
+Changes for Emscripten:
+ Object.h, Array.cc, Dict.cc are modified to avoid uninitialization errors (search for 'Emscripten')
+
diff --git a/tests/runner.py b/tests/runner.py
index fba28828..d80560bb 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -1633,7 +1633,9 @@ if 'benchmark' not in sys.argv:
def test_freetype(self):
if LLVM_OPTS or COMPILER == CLANG: global RELOOP; RELOOP = 0 # Too slow; we do care about typed arrays and OPTIMIZE though
- global CORRECT_SIGNS; CORRECT_SIGNS = 1 # Not sure why, but needed
+
+ global CORRECT_SIGNS
+ if CORRECT_SIGNS == 0: CORRECT_SIGNS = 1 # Not sure why, but needed
def post(filename):
# Embed the font into the document
@@ -1678,11 +1680,33 @@ if 'benchmark' not in sys.argv:
if COMPILER != LLVM_GCC: return # llvm-link failure when using clang, LLVM bug 9498
if RELOOP or LLVM_OPTS: return # TODO
+ global USE_TYPED_ARRAYS; USE_TYPED_ARRAYS = 0 # XXX bug - we fail with this FIXME
+
global SAFE_HEAP; SAFE_HEAP = 0 # Has variable object
- global CORRECT_SIGNS; CORRECT_SIGNS = 1 # isdigit does -ord('0') and then <= 9, assuming unsigned
- global CORRECT_OVERFLOWS; CORRECT_OVERFLOWS = 1
- global COMPILER_TEST_OPTS; COMPILER_TEST_OPTS = ['-I' + path_from_root('tests', 'libcxx', 'include')] # Avoid libstdc++ linking issue, see libcxx test
+ #global CORRECT_OVERFLOWS; CORRECT_OVERFLOWS = 1
+
+ #global CHECK_OVERFLOWS; CHECK_OVERFLOWS = 1
+ #global CHECK_SIGNS; CHECK_SIGNS = 1
+
+ global CORRECT_SIGNS; CORRECT_SIGNS = 1
+ global CORRECT_SIGNS_LINES
+ CORRECT_SIGNS_LINES = ['parseargs.cc:171', 'BuiltinFont.cc:64', 'NameToCharCode.cc:115', 'GooHash.cc:368',
+ 'Stream.h:469', 'PDFDoc.cc:1064', 'Lexer.cc:201', 'Splash.cc:1130', 'XRef.cc:997',
+ 'vector:714', 'Lexer.cc:259', 'Splash.cc:438', 'Splash.cc:532', 'GfxFont.cc:1152',
+ 'Gfx.cc:3838', 'Splash.cc:3162', 'Splash.cc:3163', 'Splash.cc:3164', 'Splash.cc:3153',
+ 'Splash.cc:3159', 'SplashBitmap.cc:80', 'SplashBitmap.cc:81', 'SplashBitmap.cc:82',
+ 'Splash.cc:809', 'Splash.cc:805', 'GooHash.cc:379',
+ # FreeType
+ 't1load.c:1850', 'psconv.c:104', 'psconv.c:185', 'psconv.c:366', 'psconv.c:399',
+ 'ftcalc.c:308', 't1parse.c:405', 'psconv.c:431', 'ftcalc.c:555', 't1objs.c:458',
+ 't1decode.c:595', 't1decode.c:606', 'pstables.h:4048', 'pstables.h:4055', 'pstables.h:4066',
+ 'pshglob.c:166', 'ftobjs.c:2548', 'ftgrays.c:1190', 'psmodule.c:116', 'psmodule.c:119',
+ 'psobjs.c:195', 'pshglob.c:165', 'ttload.c:694', 'ttmtx.c:195', 'sfobjs.c:957',
+ 'sfobjs.c:958', 'ftstream.c:369', 'ftstream.c:372', 'ttobjs.c:1007'] # And many more...
+
+ global COMPILER_TEST_OPTS; COMPILER_TEST_OPTS = ['-I' + path_from_root('tests', 'libcxx', 'include'), # Avoid libstdc++ linking issue, see libcxx test
+ '-g']
global INVOKE_RUN; INVOKE_RUN = 0 # We append code that does run() ourselves
@@ -1696,9 +1720,9 @@ if 'benchmark' not in sys.argv:
src = open(filename, 'a')
src.write(
'''
- this._STDIO.prepare('paper.pdf', eval(read('paper.pdf.js')));
+ _STDIO.prepare('paper.pdf', eval(read('paper.pdf.js')));
run(args);
- print("Data: " + JSON.stringify(this._STDIO.streams[this._STDIO.filenames['*s-0*d.']].data)); // work around __formatString__ fail
+ print("Data: " + JSON.stringify(_STDIO.streams[_STDIO.filenames['*s-0*d.']].data)); // work around __formatString__ fail
'''
)
src.close()
diff --git a/tools/exec_llvm.py b/tools/exec_llvm.py
index c6071934..060c6bf9 100755
--- a/tools/exec_llvm.py
+++ b/tools/exec_llvm.py
@@ -1,3 +1,5 @@
+#!/usr/bin/python
+
'''
Small utility to execute some llvm bitcode.
@@ -35,7 +37,9 @@ exec(open(path_from_root('tools', 'shared.py'), 'r').read())
print '// EXEC_LLVM: ', sys.argv
Popen([LLVM_OPT, sys.argv[1], '-strip-debug', '-o=' + sys.argv[1]+'.clean.bc']).communicate()[0]
-Popen([LLVM_INTERPRETER, sys.argv[1]+'.clean.bc'] + sys.argv[2:]).communicate()[0]
+
+# Execute with empty environment - just like the JS script will have
+Popen([LLVM_INTERPRETER, sys.argv[1]+'.clean.bc'] + sys.argv[2:], env={'HOME': '.'}).communicate()[0]
#Popen([LLVM_COMPILER, '-march=c', sys.argv[1], '-o=' + sys.argv[1]+'.cbe.c']).communicate()[0]
#Popen(['gcc', sys.argv[1]+'.cbe.c', '-lstdc++']).communicate()[0]