This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: regex.c is not 64bit clean


"H . J . Lu" <hjl@valinux.com> wrote:
> regex still doesn't work on my ia64. It failed at test

At last, I noticed that I had an invalid assumption.
Though wctype_t is defined as unsigned long int, I thought
the size of wctype_t is not larger than the size of wchar_t.

I think following patch will fix the problem.
(I can't test on ia64, so if there are still some problems,
 please let me know.)
In addition this patch is against
regex.c(rev 1.87) + the patch I sent some time ago.

Thanks,
--
Isamu Hasegawa
IBM Japan, Ltd.

--- regex.c.bug	Wed Feb  7 21:18:12 2001
+++ regex.c	Wed Feb  7 21:19:04 2001
@@ -62,6 +62,7 @@
 # define US_CHAR_TYPE wchar_t/* unsigned character type */
 # define COMPILED_BUFFER_VAR wc_buffer
 # define OFFSET_ADDRESS_SIZE 1 /* the size which STORE_NUMBER macro use */
+# define CHAR_CLASS_SIZE (sizeof(wctype_t)/sizeof(CHAR_TYPE)+1)
 # define PUT_CHAR(c) \
   do {									      \
     if (MC_CUR_MAX == 1)						      \
@@ -2643,6 +2644,7 @@
 	       charset[5] = p (= length of chars)
 
                charset[6] = char_class (wctype_t)
+               charset[6+CHAR_CLASS_SIZE] = char_class (wctype_t)
                          ...
                charset[l+5]  = char_class (wctype_t)
 
@@ -2817,15 +2819,16 @@
                         if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
 
 			/* Allocate the space for character class.  */
-                        GET_BUFFER_SPACE(1);
+                        GET_BUFFER_SPACE(CHAR_CLASS_SIZE);
 			/* Update the pointer to indicate end of buffer.  */
-                        b++;
+                        b += CHAR_CLASS_SIZE;
 			/* Move data which follow character classes
 			    not to violate the data.  */
-                        insert_space(1, laststart+6, b-1);
+                        insert_space(CHAR_CLASS_SIZE, laststart + 6, b - 1);
 			/* Store the character class.  */
-                        laststart[6] = (CHAR_TYPE) wt;
-                        laststart[1]++; /* Update length of char_classes */
+                        *((wctype_t*)(laststart + 6)) = wt;
+                        /* Update length of char_classes */
+                        laststart[1] += CHAR_CLASS_SIZE;
 
                         had_char_class = true;
                       }
@@ -4356,7 +4359,8 @@
 }
 
 #ifdef MBS_SUPPORT
-/* This insert space into the pattern.  */
+/* This insert space, which size is "num", into the pattern at "loc".
+   "end" must point the end of the allocated buffer.  */
 static void
 insert_space (num, loc, end)
      int num;
@@ -5995,9 +5999,13 @@
               2*ranges_length + chars_length;
 
             /* match with char_class?  */
-	    for (i = 0; i < char_class_length ; i++)
-              if (iswctype((wint_t)c, (wctype_t)(*workp++)))
-                goto char_set_matched;
+	    for (i = 0; i < char_class_length ; i += CHAR_CLASS_SIZE)
+	      {
+		wctype_t wctype = *((wctype_t*)workp);
+		workp += CHAR_CLASS_SIZE;
+		if (iswctype((wint_t)c, wctype))
+		  goto char_set_matched;
+	      }
 
             /* match with collating_symbol?  */
 # ifdef _LIBC
@@ -6130,7 +6138,7 @@
 
 		/* Update d, however d will be incremented at
 		   char_set_matched:, we decrement d here.  */
-		d = backup_d + ((uintptr_t)cp - (uintptr_t)str_buf - 1);
+		d = backup_d + ((wchar_t*)cp - (wchar_t*)str_buf - 1);
 		if (d >= dend)
 		  {
 		    if (dend == end_match_2)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]