? 317277.fix
? 323276.fix
? beagle.c
? filter-shellscript.diff
? filter-source-opt.diff
? filterdoc-wv-gsf.diff
? less
? mem-opt.diff
? perf-test.diff
? try-this-one-against-head.diff
? try-this-one.diff
? Filters/FilterKWord.cs
? Filters/FilterSource.cs.temp
? Filters/another-mem-opt.diff
? beagled/less
? beagled/outfile
? beagled/outfile.new
Index: glue/wv1-glue.c
===================================================================
RCS file: /cvs/gnome/beagle/glue/wv1-glue.c,v
retrieving revision 1.12
diff -u -p -r1.12 wv1-glue.c
--- glue/wv1-glue.c	3 Nov 2005 21:48:28 -0000	1.12
+++ glue/wv1-glue.c	5 Dec 2005 17:56:27 -0000
@@ -32,6 +32,10 @@
 #include <wv.h>
 #include <string.h>
 
+/* Enable for debugging purposes */
+#define d(x)
+
+
 /* Number of structural-break'ed text-chunks to hold
  * in the text/hot pools, before sending them for
  * indexing.  Increasing the number will give good
@@ -127,6 +131,8 @@ append_char (UserData * ud, U16 ch)
   if (ud->bIgnore)
     return;
 
+  d(printf ("append_char: entry: %p, %d, %c \n", ud, ch, ch));
+
   switch (ch) {
   case 0x00: /* End of Document */
     bNeedStructBrk = 1;
@@ -163,53 +169,55 @@ append_char (UserData * ud, U16 ch)
     break;
   }
 
-  if (ch == 0x00 || ch == 0x20 || ch == 0x0A) {
+  if (ch == 0x20 || ch == 0x0A) {
     if (ud->bWasHot)
       g_string_append_len (ud->txtHotPool, ud->txtWord->str, ud->txtWord->len);
+    
+    g_string_append_len (ud->txtPool, ud->txtWord->str, ud->txtWord->len);
 
-    /*    
-    printf ("TxtWord: %s, len: %d\n", ud->txtWord->str, ud->txtWord->len);
-    printf ("TxtPool: %s, len: %d\n", ud->txtPool->str, ud->txtPool->len);       
-    printf ("HotTxtPool: %s, len: %d\n", ud->txtHotPool->str, ud->txtHotPool->len);
-    */
+    d(printf ("TxtWord: %p, len: %d\n", ud->txtWord->str, ud->txtWord->len));
+    d(printf ("TxtPool: %s, len: %d\n", ud->txtPool->str, ud->txtPool->len));
+    d(printf ("HotTxtPool: %s, len: %d\n", ud->txtHotPool->str, ud->txtHotPool->len));
 
-    g_string_append_len (ud->txtPool, ud->txtWord->str, ud->txtWord->len);
-    if (bNeedStructBrk) {
-      g_string_append_c (ud->txtPool, '\n');
-      g_string_append_c (ud->txtHotPool, ' ');
-      ud->structBrkCount++;
-    }
+    ud->txtWord->len = 0;
+    ud->bWasHot = 0;
+  }
 
-    if (ud->structBrkCount >= BUFFERED_STRUCT_BREAK ||
-	ud->bParaEnd) {
-      (*(ud->WordHandler))(ud->txtPool->str, ud->txtPool->len, 
-			   ud->txtHotPool->str, ud->txtHotPool->len, bNeedStructBrk);
-      /* 
-	 g_string_erase () can be used here to erase
-	 the previous content, however, using this 
-	 call will free the "erased-content-memory"
-	 and thereby causing memory fragmentation for
-	 every time we transfer data from unmanaged
-	 to managed code.  Setting "len" to 0 results
-	 in the same way g_string_erase () does, but
-	 doesn't do memory-[de/re]allocation
-      */
+  if (bNeedStructBrk) {
+    g_string_append_c (ud->txtPool, '\n');
+    g_string_append_c (ud->txtHotPool, ' ');
+    ud->structBrkCount++;
+  }
 
-      /*
-	ch == 0x00 refers to EOD.  Do not reset len to
-	zero, we have to free the gstrings.
-       */
-      if (ch != 0x00) {
-	ud->txtPool->len = 0;
-	ud->txtHotPool->len = 0;
-	ud->structBrkCount = 0;
-      }
+  if (ud->structBrkCount >= BUFFERED_STRUCT_BREAK ||
+      ud->bParaEnd) {
+    (*(ud->WordHandler))(ud->txtPool->str, ud->txtPool->len, 
+			 ud->txtHotPool->str, ud->txtHotPool->len, bNeedStructBrk);
+    /* 
+       g_string_erase () can be used here to erase
+       the previous content, however, using this 
+       call will free the "erased-content-memory"
+       and thereby causing memory fragmentation for
+       every time we transfer data from unmanaged
+       to managed code.  Setting "len" to 0 results
+       in the same way g_string_erase () does, but
+       doesn't do memory-[de/re]allocation
+    */
+    
+    /*
+      ch == 0x00 refers to EOD.  Do not reset len to
+      zero, we have to free the gstrings.
+    */
+    d(printf ("append_char:after_calling_callback: %s, %s, %s\n", ud->txtPool->str,
+	      ud->txtHotPool->str, ud->txtWord->str));
+    if (ch != 0x00) {
+      ud->txtPool->len = 0;
+      ud->txtHotPool->len = 0;
+      ud->structBrkCount = 0;
     }
-    if (ch != 0x00)
-      ud->txtWord->len = 0;
-    ud->bWasHot = 0;
-  }  
-}
+  }
+}  
+
 
 /*
  * fill_UserData: fills the UserData structure from the 
@@ -478,60 +486,70 @@ wv1_glue_init_doc_parsing (char* fname, 
   FILE *input;
   int ret = 0;
 
-  wvParseStruct ps;
+  wvParseStruct* ps = NULL;
   char *dir = NULL;
 
-  UserData ud;
+  UserData* ud = NULL;
 
   input = fopen (fname, "rb");
   if (!input)
       return -1;
   fclose (input);
 
-  ret = wvInitParser (&ps, fname);
+  ps = calloc (1, sizeof (wvParseStruct));
+  ret = wvInitParser (ps, fname);
   if (ret & 0x8000)
     ret = -2;
   else if (ret) 
     ret = -3;
 
   if (ret) {
-    wvOLEFree (&ps);
+    wvOLEFree (ps);
+    /* I get a double_free () here. So commenting out
+       the following free (ps) line. 
+    */
+    /* free (ps); */
     return ret;
   }
 
-  ps.filename = fname;
-  ps.dir = dir;
+  ps->filename = fname;
+  ps->dir = dir;
 
   /* set to 0 */
-  memset (&ud, 0, sizeof (UserData));
-  ud.WordHandler = callback;
-  ud.txtWord = g_string_sized_new (32);
-  ud.txtHotPool = g_string_sized_new (1024);
-  ud.txtPool = g_string_sized_new (1024);
-  ps.userData = &ud;
-
-  wvSetElementHandler (&ps, eleProc);
-  wvSetDocumentHandler (&ps, docProc);
-  wvSetCharHandler (&ps, charProc);
-  wvSetSpecialCharHandler (&ps, specCharProc);
+  ud = calloc (1, sizeof (UserData));
+  ud->WordHandler = callback;
+  ud->txtWord = g_string_sized_new (32);
+  ud->txtHotPool = g_string_sized_new (1024);
+  ud->txtPool = g_string_sized_new (1024);
+  ps->userData = ud;
+
+  wvSetElementHandler (ps, eleProc);
+  wvSetDocumentHandler (ps, docProc);
+  wvSetCharHandler (ps, charProc);
+  wvSetSpecialCharHandler (ps, specCharProc);
 
-  wvText (&ps);
-  
+  wvText (ps);
+    
   /* free userdata memory */
-  g_string_free (ud.txtWord, TRUE);
+  d(printf ("Freeing userdata memory.\n"));
+  g_string_free (ud->txtWord, TRUE);
 
   /* free text pool memory */
-  g_string_free (ud.txtPool, TRUE);
+  d(printf ("Freeing txtPool memory.\n"));
+  g_string_free (ud->txtPool, TRUE);
 
   /* free hot text pool memory */
-  g_string_free (ud.txtHotPool, TRUE);
+  d(printf ("Freeing Hotpool memory.\n"));
+  g_string_free (ud->txtHotPool, TRUE);
+
+  free (ud);
+  ps->userData = NULL;
 
   /* free associated memory */
-  wvOLEFree (&ps);
+  wvOLEFree (ps);
 
-  ud.txtPool = NULL;
-  ud.txtWord = NULL;
-  ud.txtHotPool = NULL;
+  /* Don't know why I get a double-free error here */
+  /* free (ps); */
 
   return 0;
 }
