fseek with SEEK_END returns a "Invalid argument" error to manage large data(7GB) with python x86 C extension lib on windows7 x64 -
i've been trying manage big binary data(7gb) within python x86 original extension library. fseek seek_end doesn't work well.
i set _file_offset_bits 64 macro. tried fseeko64, raises error. less 2gb files or using seek_cur, seek_set it's works fine.
i've been stuck couple of days. give me ideas?
#define _gnu_source #define _largefile_source #define _largefile64_source #define _file_offset_bits 64 #include <python.h> #include "structmember.h" #include <stdio.h> static pyobject * myclass_load(myclass* self, pyobject *args) { const char* file_path; if (!pyarg_parsetuple(args, "s", &file_path)) homecoming null; self->fp = fopen(file_path ,"rb"); if (self->fp == null) { pyerr_setstring(pyexc_ioerror, "file not exist."); homecoming null; } off_t offset = 0; if(fseek(self->fp, offset, seek_end) != 0){ printf("%s\n", strerror(errno)); // show "invalid argument" pyerr_setstring(pyexc_ioerror, "seek failed."); homecoming null; } py_incref(py_none); homecoming py_none; } environment:
windows 7 x64 python 2.7 x86 mingw gcc
using '_fseeki64' , '_ftelli64' vc works perfectly. know i'm still using gcc compile c file python c library file, don't know why can utilize vc code in gcc. anyway, problem solved!
python large-files python-c-extension
No comments:
Post a Comment