On Wed, 30 Sep 2009, Jed Brown wrote: > Roy Stogner wrote: >> Do they call endpwent() when they're done with it? > > I'm not sure PETSc can call this, the user may expect it to be open. > Consider > > pw = getpwent(); > PetscInitialize(); > /* pw should be valid */ > PetscFinalize(); > /* pw should still be valid */ > endpwent();
Very good point; you're right. > I can't think of a reason why a user would *need* the semantics above, > but it's certainly what one would expect. In the current > implementation, even though pw will still be valid, its value may have > changed (implementation dependent, and likely surprising). If you think > PETSc should call endpwent(), feel free to raise the issue on the > mailing list. > > Whoever wrote the pwd.h API should be tarred and feathered. Hah! Yeah, even before "this isn't naturally thread-safe" became obvious, it should have been clear that they ought to be allocating dynamic memory for the strings in the struct passwd, and that there needed to be a good way to free that memory too. It looks like even the official reentrant API is a bit screwed up. You have to provide your own string buffer and length to getpwuid_r, and how long does that buffer need to be? Who knows?! Just test for ERANGE and keep feeding it more memory until the call succeeds! If I ever actually write the above strategy into robust code, I'll contribute it to PETSc. Until then, asking someone else to waste time working around an API that isn't their fault would just make me feel guilty. --- Roy ------------------------------------------------------------------------------ Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf _______________________________________________ Libmesh-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libmesh-devel
