mirror of https://github.com/ecmwf/eccodes.git
Python3: Fix broken test
This commit is contained in:
parent
f052d127c0
commit
32df610cb8
|
@ -1249,7 +1249,7 @@ static void store_file_info(int fd, FILE* fp)
|
|||
tb->file_descriptor = fd;
|
||||
tb->file_pointer = fp;
|
||||
tb->next = NULL;
|
||||
/*printf("store_file_info: fd=%d fp=%p\n",fd,fp);*/
|
||||
//printf("store_file_info: fd=%d fp=%p\n",fd,fp);
|
||||
if (!file_info_cache) {
|
||||
file_info_cache = tb;
|
||||
} else {
|
||||
|
@ -1262,21 +1262,21 @@ static void store_file_info(int fd, FILE* fp)
|
|||
static FILE* retrieve_file_info(int fd)
|
||||
{
|
||||
file_info_cache_t* p = file_info_cache;
|
||||
/*printf("retrieve_file_info: fd=%d\n",fd);*/
|
||||
//printf("retrieve_file_info: fd=%d\n",fd);
|
||||
while (p) {
|
||||
if (p->file_descriptor == fd) {
|
||||
/*printf("\t result=%p\n",p->file_pointer);*/
|
||||
//printf("\t result=%p\n",p->file_pointer);
|
||||
return p->file_pointer;
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
/*printf("\t result=NULL\n");*/
|
||||
//printf("\t result=NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
#if 0
|
||||
static int clear_file_info(int fd)
|
||||
{
|
||||
printf("clear_file_info: fd=%d\n",fd);
|
||||
//printf("clear_file_info: fd=%d\n",fd);
|
||||
file_info_cache_t* curr = file_info_cache;
|
||||
while(curr) {
|
||||
if (curr->file_descriptor==fd) {
|
||||
|
@ -1292,7 +1292,7 @@ static int clear_file_info(int fd)
|
|||
#endif
|
||||
static int clear_file_info(int fd)
|
||||
{
|
||||
/*printf("clear_file_info: fd=%d\n",fd);*/
|
||||
//printf("clear_file_info: fd=%d\n",fd);
|
||||
file_info_cache_t *curr, *prev=NULL;
|
||||
for(curr=file_info_cache; curr!=NULL; prev=curr, curr=curr->next) {
|
||||
if (curr->file_descriptor==fd) {//found it
|
||||
|
@ -1302,7 +1302,7 @@ static int clear_file_info(int fd)
|
|||
//Fix previous node's 'next' to skip over the removed node
|
||||
prev->next = curr->next;
|
||||
}
|
||||
/*printf("\t Deleting entry curr (%d,%p)\n", curr->file_descriptor,curr->file_pointer);*/
|
||||
//printf("\t Deleting entry curr (%d,%p)\n", curr->file_descriptor,curr->file_pointer);
|
||||
free(curr);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
@ -1373,17 +1373,24 @@ int grib_c_new_metar_from_file(FILE* f,int headers_only, int* gid)
|
|||
return GRIB_INVALID_FILE;
|
||||
}
|
||||
|
||||
int grib_c_new_any_from_file(FILE* f,int headers_only,int* gid)
|
||||
int grib_c_new_any_from_file(FILE* f, int fd, char* fname, int headers_only,int* gid)
|
||||
{
|
||||
grib_handle *h = NULL;
|
||||
int err = 0;
|
||||
if(f){
|
||||
h = codes_handle_new_from_file(0,f,PRODUCT_ANY, &err);
|
||||
FILE* p = retrieve_file_info(fd);
|
||||
if (p) {
|
||||
h = codes_handle_new_from_file(0,p,PRODUCT_ANY, &err);//use cached value
|
||||
} else {
|
||||
h = codes_handle_new_from_file(0,f,PRODUCT_ANY, &err);//use FILE pointer passed in
|
||||
store_file_info(fd, f); //store it for next time
|
||||
}
|
||||
if(h){
|
||||
push_handle(h,gid);
|
||||
return GRIB_SUCCESS;
|
||||
} else {
|
||||
*gid=-1;
|
||||
clear_file_info(fd);
|
||||
return GRIB_END_OF_FILE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,9 +39,7 @@ int grib_c_copy_namespace(int *gidsrc, char *name, int *giddest);
|
|||
int grib_c_count_in_file(FILE *f, int *n);
|
||||
|
||||
int grib_c_new_from_file(FILE *f, int fd, char* fname, int *gid, int headers_only);
|
||||
|
||||
int grib_c_new_any_from_file(FILE *f, int headers_only,int *gid);
|
||||
|
||||
int grib_c_new_any_from_file(FILE *f, int fd, char* fname, int headers_only,int *gid);
|
||||
int grib_c_new_bufr_from_file(FILE *f, int fd, char* fname, int headers_only,int *gid);
|
||||
|
||||
int grib_c_new_gts_from_file(FILE *f,int headers_only, int *gid);
|
||||
|
|
|
@ -234,7 +234,9 @@ def any_new_from_file(fileobj, headers_only=False):
|
|||
@return id of the message loaded in memory
|
||||
@exception GribInternalError
|
||||
"""
|
||||
err, msgid = _internal.grib_c_new_any_from_file(fileobj, headers_only, 0)
|
||||
fd = fileobj.fileno()
|
||||
fn = fileobj.name
|
||||
err, msgid = _internal.grib_c_new_any_from_file(fileobj, fd, fn, headers_only, 0)
|
||||
if err:
|
||||
if err == _internal.GRIB_END_OF_FILE:
|
||||
return None
|
||||
|
|
|
@ -42,7 +42,7 @@ import_array();
|
|||
|
||||
// creation
|
||||
int grib_c_new_from_file(FILE* f, int fd, char* fname, int* INOUT, int headers_only);
|
||||
int grib_c_new_any_from_file(FILE* f, int headers_only, int* INOUT);
|
||||
int grib_c_new_any_from_file(FILE* f, int fd, char* fname, int headers_only, int* INOUT);
|
||||
int grib_c_new_bufr_from_file(FILE* f, int fd, char* fname, int headers_only, int* INOUT);
|
||||
int grib_c_new_gts_from_file(FILE* f, int headers_only, int* INOUT);
|
||||
int grib_c_new_metar_from_file(FILE* f, int headers_only, int* INOUT);
|
||||
|
|
|
@ -5338,17 +5338,26 @@ SWIGINTERN PyObject *_wrap_grib_c_new_any_from_file(PyObject *SWIGUNUSEDPARM(sel
|
|||
PyObject *resultobj = 0;
|
||||
FILE *arg1 = (FILE *) 0 ;
|
||||
int arg2 ;
|
||||
int *arg3 = (int *) 0 ;
|
||||
char *arg3 = (char *) 0 ;
|
||||
int arg4 ;
|
||||
int *arg5 = (int *) 0 ;
|
||||
int val2 ;
|
||||
int ecode2 = 0 ;
|
||||
int temp3 ;
|
||||
int res3 = 0 ;
|
||||
int res3 ;
|
||||
char *buf3 = 0 ;
|
||||
int alloc3 = 0 ;
|
||||
int val4 ;
|
||||
int ecode4 = 0 ;
|
||||
int temp5 ;
|
||||
int res5 = 0 ;
|
||||
PyObject * obj0 = 0 ;
|
||||
PyObject * obj1 = 0 ;
|
||||
PyObject * obj2 = 0 ;
|
||||
PyObject * obj3 = 0 ;
|
||||
PyObject * obj4 = 0 ;
|
||||
int result;
|
||||
|
||||
if (!PyArg_ParseTuple(args,(char *)"OOO:grib_c_new_any_from_file",&obj0,&obj1,&obj2)) SWIG_fail;
|
||||
if (!PyArg_ParseTuple(args,(char *)"OOOOO:grib_c_new_any_from_file",&obj0,&obj1,&obj2,&obj3,&obj4)) SWIG_fail;
|
||||
{
|
||||
int fileDescriptor = PyObject_AsFileDescriptor(obj0);
|
||||
/*printf("swig.i fileDescriptor=%d\n", fileDescriptor);*/
|
||||
|
@ -5366,26 +5375,38 @@ SWIGINTERN PyObject *_wrap_grib_c_new_any_from_file(PyObject *SWIGUNUSEDPARM(sel
|
|||
SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "grib_c_new_any_from_file" "', argument " "2"" of type '" "int""'");
|
||||
}
|
||||
arg2 = (int)(val2);
|
||||
if (!(SWIG_IsOK((res3 = SWIG_ConvertPtr(obj2,SWIG_as_voidptrptr(&arg3),SWIGTYPE_p_int,0))))) {
|
||||
res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3);
|
||||
if (!SWIG_IsOK(res3)) {
|
||||
SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "grib_c_new_any_from_file" "', argument " "3"" of type '" "char *""'");
|
||||
}
|
||||
arg3 = (char *)(buf3);
|
||||
ecode4 = SWIG_AsVal_int(obj3, &val4);
|
||||
if (!SWIG_IsOK(ecode4)) {
|
||||
SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "grib_c_new_any_from_file" "', argument " "4"" of type '" "int""'");
|
||||
}
|
||||
arg4 = (int)(val4);
|
||||
if (!(SWIG_IsOK((res5 = SWIG_ConvertPtr(obj4,SWIG_as_voidptrptr(&arg5),SWIGTYPE_p_int,0))))) {
|
||||
int val;
|
||||
int ecode = SWIG_AsVal_int(obj2, &val);
|
||||
int ecode = SWIG_AsVal_int(obj4, &val);
|
||||
if (!SWIG_IsOK(ecode)) {
|
||||
SWIG_exception_fail(SWIG_ArgError(ecode), "in method '" "grib_c_new_any_from_file" "', argument " "3"" of type '" "int""'");
|
||||
SWIG_exception_fail(SWIG_ArgError(ecode), "in method '" "grib_c_new_any_from_file" "', argument " "5"" of type '" "int""'");
|
||||
}
|
||||
temp3 = (int)(val);
|
||||
arg3 = &temp3;
|
||||
res3 = SWIG_AddTmpMask(ecode);
|
||||
temp5 = (int)(val);
|
||||
arg5 = &temp5;
|
||||
res5 = SWIG_AddTmpMask(ecode);
|
||||
}
|
||||
result = (int)grib_c_new_any_from_file(arg1,arg2,arg3);
|
||||
result = (int)grib_c_new_any_from_file(arg1,arg2,arg3,arg4,arg5);
|
||||
resultobj = SWIG_From_int((int)(result));
|
||||
if (SWIG_IsTmpObj(res3)) {
|
||||
resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_From_int((*arg3)));
|
||||
if (SWIG_IsTmpObj(res5)) {
|
||||
resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_From_int((*arg5)));
|
||||
} else {
|
||||
int new_flags = SWIG_IsNewObj(res3) ? (SWIG_POINTER_OWN | 0 ) : 0 ;
|
||||
resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_NewPointerObj((void*)(arg3), SWIGTYPE_p_int, new_flags));
|
||||
int new_flags = SWIG_IsNewObj(res5) ? (SWIG_POINTER_OWN | 0 ) : 0 ;
|
||||
resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_NewPointerObj((void*)(arg5), SWIGTYPE_p_int, new_flags));
|
||||
}
|
||||
if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
|
||||
return resultobj;
|
||||
fail:
|
||||
if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -379,8 +379,8 @@ def grib_c_new_from_file(f: 'FILE *', fd: 'int', fname: 'char *', INOUT: 'int *'
|
|||
return _gribapi_swig.grib_c_new_from_file(f, fd, fname, INOUT, headers_only)
|
||||
grib_c_new_from_file = _gribapi_swig.grib_c_new_from_file
|
||||
|
||||
def grib_c_new_any_from_file(f: 'FILE *', headers_only: 'int', INOUT: 'int *') -> "int *":
|
||||
return _gribapi_swig.grib_c_new_any_from_file(f, headers_only, INOUT)
|
||||
def grib_c_new_any_from_file(f: 'FILE *', fd: 'int', fname: 'char *', headers_only: 'int', INOUT: 'int *') -> "int *":
|
||||
return _gribapi_swig.grib_c_new_any_from_file(f, fd, fname, headers_only, INOUT)
|
||||
grib_c_new_any_from_file = _gribapi_swig.grib_c_new_any_from_file
|
||||
|
||||
def grib_c_new_bufr_from_file(f: 'FILE *', fd: 'int', fname: 'char *', headers_only: 'int', INOUT: 'int *') -> "int *":
|
||||
|
|
Loading…
Reference in New Issue