[issue17428] replace readdir to readdir_r in function posix_listdir

2013-03-15 Thread Rock Li

New submission from Rock Li:

When I'm how glob module is implemented. I found in file posixmodule.c, the 
function posix_listdir is using readdir to get all the entries under one 
directory and the context is setted to allow multi threads. But the function 
readdir is not thread-safe, so I changed this call to use readdir_r instead. 

I'm using the lastest codes in the repo.

--
components: Extension Modules
files: mywork.patch
keywords: patch
messages: 184224
nosy: Rock
priority: normal
severity: normal
status: open
title: replace readdir to readdir_r in function posix_listdir
type: enhancement
versions: Python 3.4
Added file: http://bugs.python.org/file29413/mywork.patch

___
Python tracker 
<http://bugs.python.org/issue17428>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17428] replace readdir to readdir_r in function posix_listdir

2013-03-15 Thread Rock Li

Rock Li added the comment:

Hi Ross, 

What about if one implementation of posix use the global variable to store 
something. From `man readdir`, I didn't see the sentence "This data is not 
overwritten by another call to readdir() on a different directory stream.".

And from the link you gived, 
""
Background

The POSIX readdir_r function is a thread-safe version of the readdir function 
used to read directory entries. Whereas readdir returns a pointer to a 
system-allocated buffer and may use global state without mutual exclusion, 
readdir_r uses a user-supplied buffer and is guaranteed to be reentrant. Its 
use is therefore preferable or even essential in portable multithreaded 
programs.
""

Actually readdir_r is guaranteed to be reentrant. By using readdir, I think 
just like to use errno in a multi thread programs, we can't always think it 
will work as the right way. But readdir_r, we can. 

And another question, you say 
"struct dirent should not be allocated on the stack since the last field may be 
an unspecified size."

What does this mean? Can you explain detail to me?
Thx.

--

___
Python tracker 
<http://bugs.python.org/issue17428>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17428] replace readdir to readdir_r in function posix_listdir

2013-03-16 Thread Rock Li

Rock Li added the comment:

You are right. I checked the GLibc implementation of readdir and readdir_r, 
there's no global variale used in the function readdir. Just as the POSIX 
standards says, "This data is not overwritten by another call to readdir() on a 
different directory stream". 

To the second question, now I understood. POSIX does not specify the size of 
the d_name field. This will cause our codes a bit inconvenient.

Next time, I will check the POSIX specifications and related several 
implementations first, not just the documents.

Thx All.

--
status: open -> closed

___
Python tracker 
<http://bugs.python.org/issue17428>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com