[C++-sig] Strange Behavior w/File Pointers
Michael Wieher
michael.wieher at gmail.com
Fri Mar 7 16:43:51 CET 2008
mYmodule.cpp
---------------------------
istream globalFile;
struct dataStruct {
int a;
int b;
short c;
} __attribute__(align(2));
PyObject *
mYmodule_setFile() {
--parseTuple--
globalFile.open(pathToFile,ios::in|ios::binary);
}
PyObject *
mYmodule_getNBytesAtATime() {
--parseTuple--
int N; //the size of a dataStruct
globalFile.read((char*)&dataStruct,N);
Py_BuildValue('ii',dataStruct->a, dataStruct->b);
}
==============
Given the above rough pseudocode, I find that each time my Python module
calls myModule.getNBytesAtATime() the file-pointer shifts strangely. Most
of the time it shifts N bytes. But, sometimes, on the same points but with
no definable reason that I can see, it shifts N*x bytes, where x is some
integer.
I've fixed the problem by manually resetting the file-pointer on re-entry to
getNBytesAtATime, so the code works, but if anyone can shed some light on
this little quirk, I'd be interested.
-Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080307/a531f237/attachment.htm>
More information about the Cplusplus-sig
mailing list