This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Question about the use of _newlib_flockfile_* in newlib


On Mon, Dec 17, 2012 at 9:56 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
> On Dec 17 21:42, Bin.Cheng wrote:
>> On Mon, Dec 17, 2012 at 6:53 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
>> > On Dec 17 10:06, Bin.Cheng wrote:
>> >> Hi,
>> >> I have two questions on _newlib_flockfile_*.
>> >> 1.
>> >> _fputc_r calls _putc_r to do the job, but both of them calls
>> >> _newlib_flockfile_*. Is it OK? Why if it is.
>> >
>> > I'm not quite sure, but I think the reason is that putc and, in analogy,
>> > _putc_r might be defined as macro.  Newlib doesn't do that by default
>> > for _putc_r, but target-specific code could.
>> >
>> >> 2. In most functions, the macro ORIENT() is guarded by
>> >> _newlib_flockfile_*, but it is not in _puts_r. Anything special or
>> >> just missed something?
>> >
>> > I had a look into the CVS annotation and it seems that this is not about
>> > ORIENT, but about the fact that the __sfvwrite_r call in _puts_r was
>> > never guarded by a flockfile/funlockfile (the predecessor of
>> > _newlib_flockfile_start/_newlib_flockfile_end).
>> Yes.
>> >
>> > I don't know why, though.  Jeff?
>>
>> Another problem.
>> In function _fwrite_r, there is code like:
>>
>>   _newlib_flockfile_start (fp);
>>   ORIENT (fp, -1);
>>   if (__sfvwrite_r (ptr, fp, &uio) == 0)
>>     {
>>       _newlib_flockfile_exit (fp);
>>       return count;
>>     }
>>   _newlib_flockfile_end (fp);
>>   return (n - uio.uio_resid) / size;
>>
>> I think _newlib_flockfile_exit and _newlib_flockfile_end are
>> mis-placed with each other, right?
>
> No, that's correct.  See libc/stdio/local.h.
I am a little confused. Yes, the expanded code of the two macros are
same, but the literal meaning of them are as commented:
/* Exit from a stream oriented critical section prematurely: */
# define _newlib_flockfile_exit(_fp)
/* End a stream oriented critical section: */
# define _newlib_flockfile_end(_fp)

So why _newlib_flockfile_exit is called when __sfvwrite_r succeeded
and _newlib_flockfile_end is used otherwise?

Thanks.

--
Best Regards.


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