Dushistov / sdcv

https://dushistov.github.io/sdcv/
GNU General Public License v2.0
294 stars 42 forks source link

Test failures on big endian #36

Closed nijel closed 6 years ago

nijel commented 6 years ago

Both fail with:

sdcv: /<<PKGBUILDDIR>>/src/stardict_lib.cpp:542: const gchar* {anonymous}::OffsetIndex::read_first_on_page_key(glong): Assertion `(nitems == 1)' failed.

Problematic code:

https://github.com/Dushistov/sdcv/blob/925a4bc163f181c762681c59082de9598a79ddd4/src/stardict_lib.cpp#L535-L545

Dushistov commented 6 years ago

Thanks for info @nijel , can you run t_json test on one of this architecture with this patch?:

diff --git a/src/stardict_lib.cpp b/src/stardict_lib.cpp
index 63e23f5..7f222fd 100644
--- a/src/stardict_lib.cpp
+++ b/src/stardict_lib.cpp
@@ -539,6 +539,7 @@ inline const gchar *OffsetIndex::read_first_on_page_key(glong page_idx)
     const size_t nitems = fread(wordentry_buf,
                                 std::min(sizeof(wordentry_buf), static_cast<size_t>(page_size)),
                                 1, idxfile);
+    fprintf(stderr, "%p %lld %llu %zu %p %zu\n", idxfile, (long long)page_idx, (long long unsigned)page_size, nitems, wordentry_buf, sizeof(wordentry_buf));
     THROW_IF_ERROR(nitems == 1);
     //TODO: check returned values, deal with word entry that strlen>255.
     return wordentry_buf;
nijel commented 6 years ago

Probably yes, I will look into this next week.

nijel commented 6 years ago

From the gdb session:

(gdb) print page_idx
$3 = 0
(gdb) print idxfile 
$4 = (FILE *) 0x200a5140
(gdb) print page_size
$5 = 385875968
(gdb) print nitems
$6 = 0
(gdb) print wordentry_buf
$7 = "\321\207\320\265\320\273\320\276\320\262\320\265\320\272\000\000\000\000\000\000\000\000\031", '\000' <repeats 240 times>
(gdb) print sizeof(wordentry_buf)
$9 = 264

IMHO it seems that page_size is wrong...

nijel commented 6 years ago

The problem is in cache loading, following workaround works:

diff --git a/src/stardict_lib.cpp b/src/stardict_lib.cpp
index 63e23f5..1c91fe3 100644
--- a/src/stardict_lib.cpp
+++ b/src/stardict_lib.cpp
@@ -561,6 +561,7 @@ inline const gchar *OffsetIndex::get_first_on_page_key(glong page_idx)
 bool OffsetIndex::load_cache(const std::string &url)
 {
     const std::list<std::string> vars = get_cache_variant(url);
+    return false;

     for (const std::string &item : vars) {
         struct ::stat idxstat, cachestat;
nijel commented 6 years ago

Okay the problem is that the cache loading code doesn't detect as invalid caches created on other architecture and testsuite ships tests/rus-eng-stardict-2.4.2/1.xdxf.idx.oft created on little endian machine. This leads to loading wrong offsets.

nijel commented 6 years ago

Should be fixed by https://github.com/Dushistov/sdcv/pull/38