[Python-checkins] r45573 - in python/trunk: Doc/lib/libos.tex Lib/test/test_posix.py Modules/posixmodule.c (original) (raw)
"Martin v. Löwis" martin at v.loewis.de
Thu Apr 20 08:11:37 CEST 2006
- Previous message: [Python-checkins] r45573 - in python/trunk: Doc/lib/libos.tex Lib/test/test_posix.py Modules/posixmodule.c
- Next message: [Python-checkins] r45573 - in python/trunk: Doc/lib/libos.tex Lib/test/test_posix.py Modules/posixmodule.c
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
skip.montanaro wrote:
Correct implementation and documentation of os.confstr. Add a simple test case. I've yet to figure out how to provoke a None return I can test.
I couldn't find an "unconfigured" value on Linux, either. I could find some values which return an empty string (e.g. 1006, _CS_LFS64_LIBS), so I still think it is good to tell these cases apart.
if ((unsigned int)len >= sizeof(buffer)) { - result = PyStringFromStringAndSize(NULL, len); + result = PyStringFromStringAndSize(NULL, len+1); if (result != NULL) confstr(name, PyStringASSTRING(result), len+1); }
Somebody please correct me, but this still doesn't look right. As "len" includes the terminating null byte as returned from confstr, and as PyString_FromStringAndSize requires the number of characters in the string (i.e. excluding the terminating null byte), I think this should be
if ((unsigned int)len >= sizeof(buffer)) {
result = PyString_FromStringAndSize(NULL, len-1);
if (result != NULL)
confstr(name, PyString_AS_STRING(result), len);
}
Also, for symmetry, I would like the second case to read
result = PyString_FromStringAndSize(buffer, len-1);
What do you think?
Regards, Martin
- Previous message: [Python-checkins] r45573 - in python/trunk: Doc/lib/libos.tex Lib/test/test_posix.py Modules/posixmodule.c
- Next message: [Python-checkins] r45573 - in python/trunk: Doc/lib/libos.tex Lib/test/test_posix.py Modules/posixmodule.c
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]