summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
be4c77e)
- Remove gmx_fio_setdebug() and all implementation related to it;
getting the source code location printed to stderr is not really
useful for errors that typically originate from the file system.
- Move gmx_fio_setprecision() to gmxfio-xdr, since it logically belongs
there.
- Remove bOpen, as the only case where any code could observe
bOpen==FALSE requires a use-after-free, and possibly also an ugly
race condition on top of that.
- Reduce use of iFTP member within gmxfio, where the purpose is to check
whether the fio->xdr member is not NULL.
- Remove checks from gmx_fio_open() that overlapped with those in
gmx_ffopen(). There are some corner cases that now work differently:
gmxfio no longer bypasses the check for .Z/.gz files for xdr files,
but lets things through to gmx_ffopen(), and with GMX_FAHCORE there is
no longer any kind of existence check for xdr files (it is
questionable whether the previous behavior was intentionally different
for xdr and non-xdr files, anyways).
- Remove dead code: fio->fp is always non-NULL if fio->xdr is.
Change-Id: Icd1588bfbb510543a55f57fb86e0e1e2a1fce236
printf("Going to open %s\n",fn);
fpread = open_trn(fn,"r");
fpwrite = open_tpx(NULL,"w");
printf("Going to open %s\n",fn);
fpread = open_trn(fn,"r");
fpwrite = open_tpx(NULL,"w");
- gmx_fio_setdebug(fpwrite,TRUE);
mmm=mass[0]+2*mass[1];
for(i=0; (i<5); i++)
mmm=mass[0]+2*mass[1];
for(i=0; (i<5); i++)
struct t_fileio
{
FILE *fp; /* the file pointer */
struct t_fileio
{
FILE *fp; /* the file pointer */
- gmx_bool bOpen, /* the file is open */
- bRead, /* the file is open for reading */
+ gmx_bool bRead, /* the file is open for reading */
bDouble, /* write doubles instead of floats */
bDouble, /* write doubles instead of floats */
- bDebug, /* the file ops should come with debug info */
bReadWrite; /* the file is open for reading and writing */
char *fn; /* the file name */
XDR *xdr; /* the xdr data pointer */
bReadWrite; /* the file is open for reading and writing */
char *fn; /* the file name */
XDR *xdr; /* the xdr data pointer */
+void gmx_fio_setprecision(t_fileio *fio, gmx_bool bDouble)
+{
+ gmx_fio_lock(fio);
+ fio->bDouble = bDouble;
+ gmx_fio_unlock(fio);
+}
+
XDR *gmx_fio_getxdr(t_fileio *fio)
{
XDR *ret = NULL;
XDR *gmx_fio_getxdr(t_fileio *fio)
{
XDR *ret = NULL;
default:
gmx_fio_fe(fio, eio, desc, srcfile, line);
}
default:
gmx_fio_fe(fio, eio, desc, srcfile, line);
}
- if ((res == 0) && (fio->bDebug))
- {
- fprintf(stderr, "Error in xdr I/O %s %s to file %s (source %s, line %d)\n",
- eioNames[eio], desc, fio->fn, srcfile, line);
- }
+void gmx_fio_setprecision(struct t_fileio *fio, gmx_bool bDouble);
+/* Select the floating point precision for reading and writing files */
+
XDR *gmx_fio_getxdr(struct t_fileio *fio);
/* Return the file pointer itself */
XDR *gmx_fio_getxdr(struct t_fileio *fio);
/* Return the file pointer itself */
{
rc = fflush(fio->fp);
}
{
rc = fflush(fio->fp);
}
- else if (fio->xdr)
- {
- rc = fflush((FILE *) fio->xdr->x_private);
- }
/* Check if it should be opened as a binary file */
if (!ftp_is_text(fn2ftp(fn)))
{
/* Check if it should be opened as a binary file */
if (!ftp_is_text(fn2ftp(fn)))
{
- /* Not ascii, add b to file mode */
- if ((strchr(newmode, 'b') == NULL) && (strchr(newmode, 'B') == NULL))
- {
- strcat(newmode, "b");
- }
fio->iFTP = fn2ftp(fn);
fio->fn = gmx_strdup(fn);
fio->iFTP = fn2ftp(fn);
fio->fn = gmx_strdup(fn);
+ fio->fp = gmx_ffopen(fn, newmode);
/* If this file type is in the list of XDR files, open it like that */
if (ftp_is_xdr(fio->iFTP))
{
/* If this file type is in the list of XDR files, open it like that */
if (ftp_is_xdr(fio->iFTP))
{
- /* First check whether we have to make a backup,
- * only for writing, not for read or append.
- */
- if (newmode[0] == 'w')
- {
-#ifndef GMX_FAHCORE
- /* only make backups for normal gromacs */
- make_backup(fn);
-#endif
- }
- else
- {
- /* Check whether file exists */
- if (!gmx_fexist(fn))
- {
- gmx_open(fn);
- }
- }
- /* Open the file */
- fio->fp = gmx_ffopen(fn, newmode);
-
/* determine the XDR direction */
if (newmode[0] == 'w' || newmode[0] == 'a')
{
/* determine the XDR direction */
if (newmode[0] == 'w' || newmode[0] == 'a')
{
{
fio->xdrmode = XDR_DECODE;
}
{
fio->xdrmode = XDR_DECODE;
}
snew(fio->xdr, 1);
xdrstdio_create(fio->xdr, fio->fp, fio->xdrmode);
}
snew(fio->xdr, 1);
xdrstdio_create(fio->xdr, fio->fp, fio->xdrmode);
}
- else
- {
- /* If it is not, open it as a regular file */
- fio->fp = gmx_ffopen(fn, newmode);
- }
/* for appending seek to end of file to make sure ftell gives correct position
* important for checkpointing */
/* for appending seek to end of file to make sure ftell gives correct position
* important for checkpointing */
fio->bRead = bRead;
fio->bReadWrite = bReadWrite;
fio->bDouble = (sizeof(real) == sizeof(double));
fio->bRead = bRead;
fio->bReadWrite = bReadWrite;
fio->bDouble = (sizeof(real) == sizeof(double));
- fio->bDebug = FALSE;
- fio->bOpen = TRUE;
/* and now insert this file into the list of open files. */
gmx_fio_insert(fio);
/* and now insert this file into the list of open files. */
gmx_fio_insert(fio);
- if (!fio->bOpen)
- {
- gmx_fatal(FARGS, "File %s closed twice!\n", fio->fn);
- }
-
- if (ftp_is_xdr(fio->iFTP))
{
xdr_destroy(fio->xdr);
sfree(fio->xdr);
{
xdr_destroy(fio->xdr);
sfree(fio->xdr);
rc = gmx_ffclose(fio->fp); /* fclose returns 0 if happy */
}
rc = gmx_ffclose(fio->fp); /* fclose returns 0 if happy */
}
/* We don't want two processes operating on the list at the same time */
tMPI_Thread_mutex_lock(&open_file_mutex);
/* We don't want two processes operating on the list at the same time */
tMPI_Thread_mutex_lock(&open_file_mutex);
- if (fio->iFTP == efTNG)
- {
- gmx_incons("gmx_fio_close should not be called on a TNG file");
- }
gmx_fio_lock(fio);
/* first remove it from the list */
gmx_fio_remove(fio);
gmx_fio_lock(fio);
/* first remove it from the list */
gmx_fio_remove(fio);
{
int rc = 0;
gmx_fio_lock(fio);
{
int rc = 0;
gmx_fio_lock(fio);
- if (!ftp_is_xdr(fio->iFTP))
{
rc = gmx_ffclose(fio->fp); /* fclose returns 0 if happy */
fio->fp = NULL;
{
rc = gmx_ffclose(fio->fp); /* fclose returns 0 if happy */
fio->fp = NULL;
{
/* Skip the checkpoint files themselves, since they could be open when
we call this routine... */
{
/* Skip the checkpoint files themselves, since they could be open when
we call this routine... */
- if (cur->bOpen && !cur->bRead && cur->iFTP != efCPT)
+ if (!cur->bRead && cur->iFTP != efCPT)
{
/* This is an output file currently open for writing, add it */
if (nfiles == nalloc)
{
/* This is an output file currently open for writing, add it */
if (nfiles == nalloc)
-void gmx_fio_setprecision(t_fileio *fio, gmx_bool bDouble)
-{
- gmx_fio_lock(fio);
- fio->bDouble = bDouble;
- gmx_fio_unlock(fio);
-}
-
-void gmx_fio_setdebug(t_fileio *fio, gmx_bool bDebug)
-{
- gmx_fio_lock(fio);
- fio->bDebug = bDebug;
- gmx_fio_unlock(fio);
-}
-
char *gmx_fio_getname(t_fileio *fio)
{
char *ret;
char *gmx_fio_getname(t_fileio *fio)
{
char *ret;
{
rc = gmx_fsync(fio->fp);
}
{
rc = gmx_fsync(fio->fp);
}
- else if (fio->xdr) /* this should normally not happen */
- {
- rc = gmx_fsync((FILE*) fio->xdr->x_private);
- /* ^ is this actually OK? */
- }
cur = gmx_fio_get_first();
while (cur)
{
cur = gmx_fio_get_first();
while (cur)
{
- if (cur->bOpen && !cur->bRead)
{
/* if any of them fails, return failure code */
int rc = gmx_fio_int_fsync(cur);
{
/* if any of them fails, return failure code */
int rc = gmx_fio_int_fsync(cur);
* Change properties of the open file
********************************************************/
* Change properties of the open file
********************************************************/
-void gmx_fio_setprecision(t_fileio *fio, gmx_bool bDouble);
-/* Select the floating point precision for reading and writing files */
-
char *gmx_fio_getname(t_fileio *fio);
/* Return the filename corresponding to the fio index */
char *gmx_fio_getname(t_fileio *fio);
/* Return the filename corresponding to the fio index */
was opened as a specific file type and changing that midway is most
likely an evil hack. */
was opened as a specific file type and changing that midway is most
likely an evil hack. */
-void gmx_fio_setdebug(t_fileio *fio, gmx_bool bDebug);
-/* Set the debug mode */
-
gmx_bool gmx_fio_getread(t_fileio *fio);
/* Return whether read mode is on in fio */
gmx_bool gmx_fio_getread(t_fileio *fio);
/* Return whether read mode is on in fio */
int idum = 0;
real rdum = 0;
int idum = 0;
real rdum = 0;
- gmx_fio_setdebug(fio, bDebugMode());
-
/* XDR binary topology file */
precision = sizeof(real);
if (bRead)
/* XDR binary topology file */
precision = sizeof(real);
if (bRead)