When used along with my build fixes patch in #400183, this patch adds
support for 64bit systems (tested on ia64 and amd64). BTW, this patch
has also been sent upstream.
Bryan
diff -ruN tesseract-1.02.orig/ccutil/memblk.cpp tesseract-1.02/ccutil/memblk.cpp
--- tesseract-1.02.orig/ccutil/memblk.cpp 2006-06-16 16:17:05.000000000
-0600
+++ tesseract-1.02/ccutil/memblk.cpp 2006-12-04 15:42:38.000000000 -0700
@@ -441,9 +441,8 @@
//out of bounds
|| chunk + chunksize - block->blockstart <= 0 || block->blockend -
(chunk + chunksize) < 0)
BADMEMCHUNKS.error ("check_mem", ABORT,
- "Block=%x, Prev chunk=%x, Chunk=%x, Size=%x",
- (int) block, (int) prevchunk, (int) chunk,
- (int) chunk->size);
+ "Block=%p, Prev chunk=%p, Chunk=%p, Size=%x",
+ block, prevchunk, chunk, (int) chunk->size);
else if (chunk->size < 0) {
usedcount++; //used block
diff -ruN tesseract-1.02.orig/ccutil/memry.cpp tesseract-1.02/ccutil/memry.cpp
--- tesseract-1.02.orig/ccutil/memry.cpp 2006-06-16 16:17:05.000000000
-0600
+++ tesseract-1.02/ccutil/memry.cpp 2006-12-04 15:42:38.000000000 -0700
@@ -124,7 +124,7 @@
DLLSYM void free_string( //free a string
char *string //string to free
) {
- if (((int) string & 3) == 1) { //one over word
+ if (((ptrdiff_t) string & 3) == 1) { //one over word
string--; //get id marker
if (*string == 0) {
free_mem(string); //generally free it
diff -ruN tesseract-1.02.orig/ccutil/strngs.h tesseract-1.02/ccutil/strngs.h
--- tesseract-1.02.orig/ccutil/strngs.h 2006-06-16 16:17:05.000000000 -0600
+++ tesseract-1.02/ccutil/strngs.h 2006-12-04 15:42:38.000000000 -0700
@@ -168,7 +168,7 @@
char *instring; //input from read
INT32 length; //length of string
- instring = (char *) de_serialise_bytes (f, (int) ptr);
+ instring = (char *) de_serialise_bytes (f, (ptrdiff_t) ptr);
length = (INT32) ptr;
ptr = NULL;
*this = instring;
diff -ruN tesseract-1.02.orig/classify/adaptmatch.cpp
tesseract-1.02/classify/adaptmatch.cpp
--- tesseract-1.02.orig/classify/adaptmatch.cpp 2006-06-16 17:19:53.000000000
-0600
+++ tesseract-1.02/classify/adaptmatch.cpp 2006-12-04 15:42:38.000000000
-0700
@@ -824,7 +824,13 @@
#else
File = Efopen (Filename, "rb");
#endif
+
+ #ifdef __MOTO__
+ PreTrainedTemplates = ReadIntTemplates (File, FALSE);
+ #else
PreTrainedTemplates = ReadIntTemplates (File, TRUE);
+ #endif
+
fclose(File);
strcpy(Filename, demodir);
diff -ruN tesseract-1.02.orig/classify/intproto.cpp
tesseract-1.02/classify/intproto.cpp
--- tesseract-1.02.orig/classify/intproto.cpp 2006-09-07 16:20:48.000000000
-0600
+++ tesseract-1.02/classify/intproto.cpp 2006-12-04 15:42:38.000000000
-0700
@@ -861,6 +861,8 @@
*/
int i, j, x, y, z;
int nread;
+ int tot_nread = 0;
+ int junk;
INT_TEMPLATES Templates;
CLASS_PRUNER Pruner;
INT_CLASS Class;
@@ -869,21 +871,40 @@
/* first read the high level template struct */
Templates = NewIntTemplates ();
- if ((nread =
- fread ((char *) Templates, 1, sizeof (INT_TEMPLATES_STRUCT),
- File)) != sizeof (INT_TEMPLATES_STRUCT))
- cprintf ("Bad read of inttemp!\n");
- // int tmp=__NATIVE__;
- //xiaofan
- // swap status is determined automatically
- if (swap && Templates->NumClassPruners > 0 &&
- Templates->NumClassPruners < 1000)
- swap = FALSE;
- if (swap) {
- reverse32 (&Templates->NumClassPruners);
- reverse32 (&Templates->NumClasses);
- for (i = 0; i < MAX_CLASS_ID + 1; i++)
- reverse16 (&Templates->IndexFor[i]);
+
+ if((nread = fread(&Templates->NumClasses, 1, sizeof(int), File)) !=
sizeof(int))
+ cprintf("Bad read of inttemp!\n");
+ if(swap) reverse32(&Templates->NumClasses);
+ tot_nread += nread;
+
+ if((nread = fread(&Templates->NumClassPruners, 1, sizeof(int), File)) !=
sizeof(int))
+ cprintf("Bad read of inttemp!\n");
+ if(swap) reverse32(&Templates->NumClassPruners);
+ tot_nread += nread;
+
+ for(i=0; i < MAX_CLASS_ID + 1; i++) {
+ if((nread = fread(&Templates->IndexFor[i], 1, sizeof(CLASS_INDEX), File))
!= sizeof(CLASS_INDEX))
+ cprintf("Bad read of inttemp!\n");
+ if(swap) reverse16(&Templates->IndexFor[i]);
+ tot_nread += nread;
+ }
+
+ for(i=0; i < MAX_NUM_CLASSES; i++) {
+ if((nread = fread(&Templates->ClassIdFor[i], 1, sizeof(CLASS_ID), File))
!= sizeof(CLASS_ID))
+ cprintf("Bad read of inttemp!\n");
+ tot_nread += nread;
+ }
+
+ for(i=0; i < MAX_NUM_CLASSES; i++) {
+ if((nread = fread(&junk, 1, sizeof(junk), File)) != sizeof(junk))
+ cprintf("Bad read of inttemp!\n");
+ tot_nread += nread;
+ }
+
+ for(i=0; i < MAX_NUM_CLASS_PRUNERS; i++) {
+ if((nread = fread(&junk, 1, sizeof(junk), File)) != sizeof(junk))
+ cprintf("Bad read of inttemp!\n");
+ tot_nread += nread;
}
/* then read in the class pruners */
@@ -904,6 +925,7 @@
}
}
}
+ tot_nread += nread;
Templates->ClassPruner[i] = Pruner;
}
@@ -911,13 +933,35 @@
for (i = 0; i < NumClassesIn (Templates); i++) {
/* first read in the high level struct for the class */
Class = (INT_CLASS) Emalloc (sizeof (INT_CLASS_STRUCT));
- if ((nread = fread ((char *) Class, 1, sizeof (INT_CLASS_STRUCT), File))
- != sizeof (INT_CLASS_STRUCT))
- cprintf ("Bad read of inttemp!\n");
- if (swap) {
- reverse16 (&Class->NumProtos);
- for (j = 0; j < MAX_NUM_CONFIGS; j++)
- reverse16 (&Class->ConfigLengths[j]);
+
+ if((nread = fread(&Class->NumProtos, 1, sizeof(UINT16), File)) !=
sizeof(UINT16))
+ cprintf("Bad read of inttemp!\n");
+ if(swap) reverse16(&Class->NumProtos);
+ tot_nread += nread;
+
+ if((nread = fread(&Class->NumProtoSets, 1, sizeof(UINT8), File)) !=
sizeof(UINT8))
+ cprintf("Bad read of inttemp!\n");
+ tot_nread += nread;
+
+ if((nread = fread(&Class->NumConfigs, 1, sizeof(UINT8), File)) !=
sizeof(UINT8))
+ cprintf("Bad read of inttemp!\n");
+ tot_nread += nread;
+
+ for(j=0; j < MAX_NUM_PROTO_SETS; j++) {
+ if((nread = fread(&junk, 1, sizeof(junk), File)) != sizeof(junk))
+ cprintf("Bad read of inttemp!\n");
+ tot_nread += nread;
+ }
+
+ if((nread = fread(&junk, 1, sizeof(junk), File)) != sizeof(junk))
+ cprintf("Bad read of inttemp!\n");
+ tot_nread += nread;
+
+ for(j=0; j < MAX_NUM_CONFIGS; j++) {
+ if((nread = fread(&Class->ConfigLengths[j], 1, sizeof(UINT16), File)) !=
sizeof(UINT16))
+ cprintf("Bad read of inttemp!\n");
+ if(swap) reverse16(&Class->ConfigLengths[j]);
+ tot_nread += nread;
}
ClassForIndex (Templates, i) = Class;
@@ -929,6 +973,7 @@
File)) != MaxNumIntProtosIn (Class))
cprintf ("Bad read of inttemp!\n");
Class->ProtoLengths = Lengths;
+ tot_nread += nread;
/* then read in the proto sets */
for (j = 0; j < NumProtoSetsIn (Class); j++) {
@@ -947,6 +992,7 @@
reverse32 (&ProtoSet->Protos[x].Configs[y]);
}
ProtoSetIn (Class, j) = ProtoSet;
+ tot_nread += nread;
}
}
return (Templates);
diff -ruN tesseract-1.02.orig/configure tesseract-1.02/configure
--- tesseract-1.02.orig/configure 2006-12-04 15:28:39.000000000 -0700
+++ tesseract-1.02/configure 2006-12-04 15:42:38.000000000 -0700
@@ -3934,7 +3934,7 @@
OPTS="$OPTS $VCOPTS_COMMON /Ow /O2"
else
- opt="-O3"
+ opt="-O2"
echo "$as_me:$LINENO: checking if $CXX accepts $opt" >&5
echo $ECHO_N "checking if $CXX accepts $opt... $ECHO_C" >&6
echo 'void f(){}' > conftest.cc
@@ -3942,7 +3942,7 @@
echo "$as_me:$LINENO: result: yes" >&5
echo "${ECHO_T}yes" >&6
rm conftest.*
- OPTS="$OPTS -O3"
+ OPTS="$OPTS -O2"
else
echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6
diff -ruN tesseract-1.02.orig/cutil/structures.h
tesseract-1.02/cutil/structures.h
--- tesseract-1.02.orig/cutil/structures.h 2006-06-16 16:17:07.000000000
-0600
+++ tesseract-1.02/cutil/structures.h 2006-12-04 15:42:38.000000000 -0700
@@ -82,7 +82,7 @@
newblock=(char *)memalloc_p(sizeof(type)*blocksize+4);
\
if (newblock!=NULL)
\
{
\
- newblock=(char *)(((int)newblock +4) & (-8));
\
+ newblock=(char *)(((ptrdiff_t)newblock +4) &
(-8)); \
}
\
element=(type *)newblock;
\
}
\
@@ -142,7 +142,7 @@
newblock=(char *)memalloc_p(sizeof(type)*blocksize+4);\
if (newblock!=NULL)\
{\
- newblock=(char *)(((int)newblock +4) & (-8));\
+ newblock=(char *)(((ptrdiff_t)newblock +4) &
(-8));\
}\
element=(type *)newblock;\
}\
diff -ruN tesseract-1.02.orig/cutil/variables.cpp
tesseract-1.02/cutil/variables.cpp
--- tesseract-1.02.orig/cutil/variables.cpp 2006-06-16 17:19:53.000000000
-0600
+++ tesseract-1.02/cutil/variables.cpp 2006-12-04 15:42:38.000000000 -0700
@@ -61,15 +61,16 @@
F u n c t i o n s
----------------------------------------------------------------------*/
/**********************************************************************
- * add_variable
+ * add_ptr_variable
*
- * Add a new variable to the global variable list. Initalize its value.
+ * Add a new ptr variable to the global variable list. Initalize its
+ * value.
**********************************************************************/
-void add_variable(void *address,
- const char *string,
- VALUE default_value,
- variables_io reader,
- variables_io writer) {
+void add_ptr_variable(void *address,
+ const char *string,
+ VALUE default_value,
+ variables_io reader,
+ variables_io writer) {
VARIABLE *this_var;
this_var =
(VARIABLE *) c_alloc_struct (sizeof (VARIABLE), "VARIABLE(TESS)");
@@ -86,6 +87,32 @@
/**********************************************************************
+ * add_32bit_variable
+ *
+ * Add a new 32bit variable to the global variable list. Initalize
+ * its value.
+ **********************************************************************/
+void add_32bit_variable(void *address,
+ const char *string,
+ VALUE default_value,
+ variables_io reader,
+ variables_io writer) {
+ VARIABLE *this_var;
+ this_var =
+ (VARIABLE *) c_alloc_struct (sizeof (VARIABLE), "VARIABLE(TESS)");
+
+ this_var->address = address;
+ this_var->string = string;
+ this_var->default_value = default_value;
+ this_var->type_reader = reader;
+ this_var->type_writer = writer;
+
+ *((int *) this_var->address) = default_value.int_part;
+ variable_list = push (variable_list, this_var);
+}
+
+
+/**********************************************************************
* float_read
*
* Read an integer value and save it in a variable structure.
diff -ruN tesseract-1.02.orig/cutil/variables.h tesseract-1.02/cutil/variables.h
--- tesseract-1.02.orig/cutil/variables.h 2006-06-16 16:17:07.000000000
-0600
+++ tesseract-1.02/cutil/variables.h 2006-12-04 15:42:38.000000000 -0700
@@ -71,7 +71,7 @@
#define float_variable(name,string,default) \
dummy.float_part = default; \
-add_variable (&name, "", dummy, float_read, float_write)
+add_32bit_variable (&name, "", dummy, float_read, float_write)
/**********************************************************************
* string_variable
@@ -82,7 +82,7 @@
#define string_variable(name,string,default) \
dummy.char_part = strsave (default); \
-add_variable (&name, "", dummy, string_read, string_write)
+add_ptr_variable (&name, "", dummy, string_read, string_write)
/**********************************************************************
* int_variable
@@ -93,7 +93,7 @@
#define int_variable(name,string,default) \
dummy.int_part = default; \
-add_variable (&name, "", dummy, int_read, int_write)
+add_32bit_variable (&name, "", dummy, int_read, int_write)
#else
/**********************************************************************
@@ -105,7 +105,7 @@
#define float_variable(name,string,default) \
dummy.float_part = default; \
-add_variable (&name, string, dummy, float_read, float_write)
+add_32bit_variable (&name, string, dummy, float_read, float_write)
/**********************************************************************
* string_variable
@@ -116,7 +116,7 @@
#define string_variable(name,string,default) \
dummy.char_part = strsave (default); \
-add_variable (&name, string, dummy, string_read, string_write)
+add_ptr_variable (&name, string, dummy, string_read, string_write)
/**********************************************************************
* int_variable
@@ -127,17 +127,23 @@
#define int_variable(name,string,default) \
dummy.int_part = default; \
-add_variable (&name, string, dummy, int_read, int_write)
+add_32bit_variable (&name, string, dummy, int_read, int_write)
#endif
/*--------------------------------------------------------------------------
Public Function Prototoypes
----------------------------------------------------------------------------*/
-void add_variable(void *address,
- const char *string,
- VALUE default_value,
- variables_io reader,
- variables_io writer);
+void add_ptr_variable(void *address,
+ const char *string,
+ VALUE default_value,
+ variables_io reader,
+ variables_io writer);
+
+void add_32bit_variable(void *address,
+ const char *string,
+ VALUE default_value,
+ variables_io reader,
+ variables_io writer);
void float_read(VARIABLE *variable, char *string);
diff -ruN tesseract-1.02.orig/dict/dawg.cpp tesseract-1.02/dict/dawg.cpp
--- tesseract-1.02.orig/dict/dawg.cpp 2006-06-16 16:17:07.000000000 -0600
+++ tesseract-1.02/dict/dawg.cpp 2006-12-04 15:42:38.000000000 -0700
@@ -270,7 +270,7 @@
void read_squished_dawg(char *filename, EDGE_ARRAY dawg, INT32 max_num_edges)
{
FILE *file;
EDGE_REF edge;
- INT32 num_edges;
+ INT32 num_edges = 0;
INT32 node_count = 0;
if (debug) print_string ("read_debug");