[PATCH] Use "|" instead of "+" when combine the _IO_LINE_BUF and _IO_UNBUFFERED flags

Feng Gao gfree.wind@gmail.com
Wed Jul 8 06:15:00 GMT 2015


Hi Siddhesh,

Firstly, sorry about that I forget fixing the last space issue. Maybe
I was very tried when it was very late in the night.

Now the attachment "file_flags.diff" is the latest change which fix
the issue you mentioned.
The "test_flag.c" is the test codes to check the flag value.
The "test_buf.c" is the test codes to test if the setbuf of libc works well.

The following are the tests I did:
1. Run the test_flag.c on 32-bits and 64-bits platform, the output is "Equal".
    It means (_IO_UNBUFFERED | _IO_LINE_BUF) has the same value of
(_IO_UNBUFFERED + _IO_LINE_BUF);
2. After update the glibc, gdb the test_buf.c to check if the setbuf
works well like before.
    Because i am using the glibc-2.19 on my linux, so I apply my patch
to glibc-2.19, build and replace the original one. ( I am afraid my
computer become brick:))
    Then gdb the binary of test_buf.c to check if the setbuf works
well like before.
Breakpoint 1, main () at test_buf.c:23
23      {
(gdb) n
26              printf("Before no-buffer.");
(gdb)
27              printf("Output now.\n");
(gdb)
Before no-buffer.Output now.
29              setbuf(stdout, NULL);
(gdb)
30              printf("No buffer now.");
(gdb)
No buffer now.32                setvbuf(stdout, buffer, _IOLBF, sizeof(buffer));
(gdb)
33              printf("Restore linebuf.");
(gdb)
34              printf("Output now.\n");
(gdb)
Restore linebuf.Output now.
36              return 0;

The output is the right behavior we expect.

3. I doesn't execute the "make check". Because it will hang without my
patch. So I could not do "make check" with my patch.
I don't know if there already is one bug in the current glibc codes.

It stop the following step for about 2 hours, so I have to cancel it.

        scripts/evaluate-test.sh c++-types-check $? false false >
/home/fgao/works/my_git_codes/glibc-build/c++-types-check.test-result
AWK='gawk' scripts/check-local-headers.sh \
          "/usr/include" "/home/fgao/works/my_git_codes/glibc-build/"
> /home/fgao/works/my_git_codes/glibc-build/check-local-headers.out; \
        scripts/evaluate-test.sh check-local-headers $? false false >
/home/fgao/works/my_git_codes/glibc-build/check-local-headers.test-result

That's why I did not execute the "make check" with my change.



















On Wed, Jul 8, 2015 at 12:28 AM, Siddhesh Poyarekar <siddhesh@redhat.com> wrote:
> On Wed, Jul 08, 2015 at 12:02:38AM +0800, Feng Gao wrote:
>> About the tests, I did the following cases:
>> 1. Write test codes to check if the (_IO_LINE_BUF|_IO_UNBUFFERED)
>> equals  (_IO_LINE_BUF+_IO_UNBUFFERED);
>> 2. Update the glibc to check if it works like before.
>
> Thanks, it looks like you missed fixing spacing in the last instance
> (quoted below).  Also, run 'make check' before and after the patch to
> make sure that there are no regressions due to this change.  Updating
> glibc is a brave thing to do - if it breaks, your box is a brick that
> only a rescue disk can get back :)
>
> Please post an updated patch and also let me know the results of your
> test.
>
> Thanks,
> Siddhesh
>
>> @@ -477,7 +477,7 @@ _IO_wfile_overflow (_IO_FILE *f, wint_t wch)
>>        f->_IO_read_base = f->_IO_read_ptr = f->_IO_read_end;
>>
>>        f->_flags |= _IO_CURRENTLY_PUTTING;
>> -      if (f->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
>> +      if (f->_flags & (_IO_LINE_BUF|_IO_UNBUFFERED))
>>       f->_wide_data->_IO_write_end = f->_wide_data->_IO_write_ptr;
>>      }
>>    if (wch == WEOF)
>
-------------- next part --------------
diff --git a/ChangeLog b/ChangeLog
index 2ccf739..2d94135 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+015-07-07  Feng Gao  <gfree.wind@gmail.com>
+	* libio/fileops.c: Use "|" instead of "+" when combine _IO_LINE_BUF
+	and _IO_UNBUFFERED
+	* libio/oldfileops.c: Likewise
+	* libio/wfileops.c: Likewise
+
 2015-07-07  Pavel Kopyl  <p.kopyl@samsung.com>
 	    Mikhail Ilin  <m.ilin@samsung.com>
 
diff --git a/libio/fileops.c b/libio/fileops.c
index 9668024..cbcd6f5 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -521,7 +521,7 @@ new_do_write (_IO_FILE *fp, const char *data, _IO_size_t to_do)
   _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
   fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_buf_base;
   fp->_IO_write_end = (fp->_mode <= 0
-		       && (fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
+		       && (fp->_flags & (_IO_LINE_BUF | _IO_UNBUFFERED))
 		       ? fp->_IO_buf_base : fp->_IO_buf_end);
   return count;
 }
@@ -844,7 +844,7 @@ _IO_new_file_overflow (_IO_FILE *f, int ch)
       f->_IO_read_base = f->_IO_read_ptr = f->_IO_read_end;
 
       f->_flags |= _IO_CURRENTLY_PUTTING;
-      if (f->_mode <= 0 && f->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
+      if (f->_mode <= 0 && f->_flags & (_IO_LINE_BUF | _IO_UNBUFFERED))
 	f->_IO_write_end = f->_IO_write_ptr;
     }
   if (ch == EOF)
diff --git a/libio/oldfileops.c b/libio/oldfileops.c
index 84939e3..54789b2 100644
--- a/libio/oldfileops.c
+++ b/libio/oldfileops.c
@@ -313,7 +313,7 @@ old_do_write (fp, data, to_do)
     fp->_cur_column = _IO_adjust_column (fp->_cur_column - 1, data, count) + 1;
   _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
   fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_buf_base;
-  fp->_IO_write_end = ((fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
+  fp->_IO_write_end = ((fp->_flags & (_IO_LINE_BUF | _IO_UNBUFFERED))
 		       ? fp->_IO_buf_base : fp->_IO_buf_end);
   return count;
 }
@@ -418,7 +418,7 @@ _IO_old_file_overflow (f, ch)
       f->_IO_write_end = f->_IO_buf_end;
       f->_IO_read_base = f->_IO_read_ptr = f->_IO_read_end;
 
-      if (f->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
+      if (f->_flags & (_IO_LINE_BUF | _IO_UNBUFFERED))
 	f->_IO_write_end = f->_IO_write_ptr;
       f->_flags |= _IO_CURRENTLY_PUTTING;
     }
diff --git a/libio/wfileops.c b/libio/wfileops.c
index 73d7709..99f9c8f 100644
--- a/libio/wfileops.c
+++ b/libio/wfileops.c
@@ -118,7 +118,7 @@ _IO_wdo_write (_IO_FILE *fp, const wchar_t *data, _IO_size_t to_do)
 	     fp->_wide_data->_IO_buf_base);
   fp->_wide_data->_IO_write_base = fp->_wide_data->_IO_write_ptr
     = fp->_wide_data->_IO_buf_base;
-  fp->_wide_data->_IO_write_end = ((fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
+  fp->_wide_data->_IO_write_end = ((fp->_flags & (_IO_LINE_BUF | _IO_UNBUFFERED))
 				   ? fp->_wide_data->_IO_buf_base
 				   : fp->_wide_data->_IO_buf_end);
 
@@ -216,7 +216,7 @@ _IO_wfile_underflow (_IO_FILE *fp)
 
   /* Flush all line buffered files before reading. */
   /* FIXME This can/should be moved to genops ?? */
-  if (fp->_flags & (_IO_LINE_BUF|_IO_UNBUFFERED))
+  if (fp->_flags & (_IO_LINE_BUF | _IO_UNBUFFERED))
     {
 #if 0
       _IO_flush_all_linebuffered ();
@@ -477,7 +477,7 @@ _IO_wfile_overflow (_IO_FILE *f, wint_t wch)
       f->_IO_read_base = f->_IO_read_ptr = f->_IO_read_end;
 
       f->_flags |= _IO_CURRENTLY_PUTTING;
-      if (f->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
+      if (f->_flags & (_IO_LINE_BUF | _IO_UNBUFFERED))
 	f->_wide_data->_IO_write_end = f->_wide_data->_IO_write_ptr;
     }
   if (wch == WEOF)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_flag.c
Type: text/x-csrc
Size: 678 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20150708/9da859a7/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_buf.c
Type: text/x-csrc
Size: 729 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20150708/9da859a7/attachment-0001.bin>


More information about the Libc-alpha mailing list