Skip to content

Commit

Permalink
Remove __PHYSFS_setError(), use the new public API instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Nov 30, 2012
1 parent 7824a09 commit 697c31e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/archiver_dir.c
Expand Up @@ -94,7 +94,7 @@ static PHYSFS_Io *doOpen(void *opaque, const char *name, const int mode)
const PHYSFS_ErrorCode err = PHYSFS_getLastErrorCode();
PHYSFS_Stat statbuf;
__PHYSFS_platformStat(f, &statbuf);
__PHYSFS_setError(err);
PHYSFS_setErrorCode(err);
} /* if */

__PHYSFS_smallFree(f);
Expand Down
14 changes: 7 additions & 7 deletions src/archiver_lzma.c
Expand Up @@ -291,25 +291,25 @@ static int lzma_err(SZ_RESULT rc)
case SZ_OK: /* Same as LZMA_RESULT_OK */
break;
case SZE_DATA_ERROR: /* Same as LZMA_RESULT_DATA_ERROR */
__PHYSFS_setError(PHYSFS_ERR_CORRUPT); /*!!!FIXME: was "PHYSFS_ERR_DATA_ERROR" */
PHYSFS_setErrorCode(PHYSFS_ERR_CORRUPT); /*!!!FIXME: was "PHYSFS_ERR_DATA_ERROR" */
break;
case SZE_OUTOFMEMORY:
__PHYSFS_setError(PHYSFS_ERR_OUT_OF_MEMORY);
PHYSFS_setErrorCode(PHYSFS_ERR_OUT_OF_MEMORY);
break;
case SZE_CRC_ERROR:
__PHYSFS_setError(PHYSFS_ERR_CORRUPT);
PHYSFS_setErrorCode(PHYSFS_ERR_CORRUPT);
break;
case SZE_NOTIMPL:
__PHYSFS_setError(PHYSFS_ERR_UNSUPPORTED);
PHYSFS_setErrorCode(PHYSFS_ERR_UNSUPPORTED);
break;
case SZE_FAIL:
__PHYSFS_setError(PHYSFS_ERR_OTHER_ERROR); /* !!! FIXME: right? */
PHYSFS_setErrorCode(PHYSFS_ERR_OTHER_ERROR); /* !!! FIXME: right? */
break;
case SZE_ARCHIVE_ERROR:
__PHYSFS_setError(PHYSFS_ERR_CORRUPT); /* !!! FIXME: right? */
PHYSFS_setErrorCode(PHYSFS_ERR_CORRUPT); /* !!! FIXME: right? */
break;
default:
__PHYSFS_setError(PHYSFS_ERR_OTHER_ERROR);
PHYSFS_setErrorCode(PHYSFS_ERR_OTHER_ERROR);
} /* switch */

return rc;
Expand Down
2 changes: 1 addition & 1 deletion src/archiver_zip.c
Expand Up @@ -163,7 +163,7 @@ static PHYSFS_ErrorCode zlib_error_code(int rc)
*/
static int zlib_err(const int rc)
{
__PHYSFS_setError(zlib_error_code(rc));
PHYSFS_setErrorCode(zlib_error_code(rc));
return rc;
} /* zlib_err */

Expand Down
64 changes: 29 additions & 35 deletions src/physfs.c
Expand Up @@ -585,7 +585,7 @@ static char **doEnumStringList(void (*func)(PHYSFS_StringCallback, void *))

if (ecd.errcode)
{
__PHYSFS_setError(ecd.errcode);
PHYSFS_setErrorCode(ecd.errcode);
return NULL;
} /* if */

Expand Down Expand Up @@ -697,37 +697,6 @@ static ErrState *findErrorForCurrentThread(void)
} /* findErrorForCurrentThread */


void __PHYSFS_setError(const PHYSFS_ErrorCode errcode)
{
ErrState *err;

if (!errcode)
return;

err = findErrorForCurrentThread();
if (err == NULL)
{
err = (ErrState *) allocator.Malloc(sizeof (ErrState));
if (err == NULL)
return; /* uhh...? */

memset(err, '\0', sizeof (ErrState));
err->tid = __PHYSFS_platformGetThreadID();

if (errorLock != NULL)
__PHYSFS_platformGrabMutex(errorLock);

err->next = errorStates;
errorStates = err;

if (errorLock != NULL)
__PHYSFS_platformReleaseMutex(errorLock);
} /* if */

err->code = errcode;
} /* __PHYSFS_setError */


/* this doesn't reset the error state. */
static inline PHYSFS_ErrorCode currentErrorCode(void)
{
Expand Down Expand Up @@ -784,9 +753,34 @@ PHYSFS_DECL const char *PHYSFS_getErrorByCode(PHYSFS_ErrorCode code)
} /* PHYSFS_getErrorByCode */


void PHYSFS_setErrorCode(PHYSFS_ErrorCode code)
void PHYSFS_setErrorCode(PHYSFS_ErrorCode errcode)
{
__PHYSFS_setError(code);
ErrState *err;

if (!errcode)
return;

err = findErrorForCurrentThread();
if (err == NULL)
{
err = (ErrState *) allocator.Malloc(sizeof (ErrState));
if (err == NULL)
return; /* uhh...? */

memset(err, '\0', sizeof (ErrState));
err->tid = __PHYSFS_platformGetThreadID();

if (errorLock != NULL)
__PHYSFS_platformGrabMutex(errorLock);

err->next = errorStates;
errorStates = err;

if (errorLock != NULL)
__PHYSFS_platformReleaseMutex(errorLock);
} /* if */

err->code = errcode;
} /* PHYSFS_setErrorCode */


Expand Down Expand Up @@ -1191,7 +1185,7 @@ int PHYSFS_init(const char *argv0)
initialized = 1;

/* This makes sure that the error subsystem is initialized. */
__PHYSFS_setError(PHYSFS_getLastErrorCode());
PHYSFS_setErrorCode(PHYSFS_getLastErrorCode());

return 1;

Expand Down
46 changes: 18 additions & 28 deletions src/physfs_internal.h
Expand Up @@ -127,16 +127,6 @@ void __PHYSFS_smallFree(void *ptr);
/* The latest supported PHYSFS_Archiver::version value. */
#define CURRENT_PHYSFS_ARCHIVER_API_VERSION 0

/* !!! FIXME: update this documentation.
* Call this to set the message returned by PHYSFS_getLastError().
* Please only use the ERR_* constants above, or add new constants to the
* above group, but I want these all in one place.
*
* Calling this with a NULL argument is a safe no-op.
*/
void __PHYSFS_setError(const PHYSFS_ErrorCode err);


/* This byteorder stuff was lifted from SDL. http://www.libsdl.org/ */
#define PHYSFS_LIL_ENDIAN 1234
#define PHYSFS_BIG_ENDIAN 4321
Expand Down Expand Up @@ -186,14 +176,14 @@ void __PHYSFS_sort(void *entries, size_t max,
#define ERRPASS PHYSFS_ERR_OK

/* These get used all over for lessening code clutter. */
#define BAIL_MACRO(e, r) do { if (e) __PHYSFS_setError(e); return r; } while (0)
#define BAIL_IF_MACRO(c, e, r) do { if (c) { if (e) __PHYSFS_setError(e); return r; } } while (0)
#define BAIL_MACRO_MUTEX(e, m, r) do { if (e) __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); return r; } while (0)
#define BAIL_IF_MACRO_MUTEX(c, e, m, r) do { if (c) { if (e) __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); return r; } } while (0)
#define GOTO_MACRO(e, g) do { if (e) __PHYSFS_setError(e); goto g; } while (0)
#define GOTO_IF_MACRO(c, e, g) do { if (c) { if (e) __PHYSFS_setError(e); goto g; } } while (0)
#define GOTO_MACRO_MUTEX(e, m, g) do { if (e) __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); goto g; } while (0)
#define GOTO_IF_MACRO_MUTEX(c, e, m, g) do { if (c) { if (e) __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); goto g; } } while (0)
#define BAIL_MACRO(e, r) do { if (e) PHYSFS_setErrorCode(e); return r; } while (0)
#define BAIL_IF_MACRO(c, e, r) do { if (c) { if (e) PHYSFS_setErrorCode(e); return r; } } while (0)
#define BAIL_MACRO_MUTEX(e, m, r) do { if (e) PHYSFS_setErrorCode(e); __PHYSFS_platformReleaseMutex(m); return r; } while (0)
#define BAIL_IF_MACRO_MUTEX(c, e, m, r) do { if (c) { if (e) PHYSFS_setErrorCode(e); __PHYSFS_platformReleaseMutex(m); return r; } } while (0)
#define GOTO_MACRO(e, g) do { if (e) PHYSFS_setErrorCode(e); goto g; } while (0)
#define GOTO_IF_MACRO(c, e, g) do { if (c) { if (e) PHYSFS_setErrorCode(e); goto g; } } while (0)
#define GOTO_MACRO_MUTEX(e, m, g) do { if (e) PHYSFS_setErrorCode(e); __PHYSFS_platformReleaseMutex(m); goto g; } while (0)
#define GOTO_IF_MACRO_MUTEX(c, e, m, g) do { if (c) { if (e) PHYSFS_setErrorCode(e); __PHYSFS_platformReleaseMutex(m); goto g; } } while (0)

#define __PHYSFS_ARRAYLEN(x) ( (sizeof (x)) / (sizeof (x[0])) )

Expand Down Expand Up @@ -365,7 +355,7 @@ int __PHYSFS_platformDeinit(void);
* a unique file handle; this is frequently employed to prevent race
* conditions in the archivers.
*
* Call __PHYSFS_setError() and return (NULL) if the file can't be opened.
* Call PHYSFS_setErrorCode() and return (NULL) if the file can't be opened.
*/
void *__PHYSFS_platformOpenRead(const char *filename);

Expand All @@ -382,7 +372,7 @@ void *__PHYSFS_platformOpenRead(const char *filename);
*
* Opening a file for write multiple times has undefined results.
*
* Call __PHYSFS_setError() and return (NULL) if the file can't be opened.
* Call PHYSFS_setErrorCode() and return (NULL) if the file can't be opened.
*/
void *__PHYSFS_platformOpenWrite(const char *filename);

Expand All @@ -400,7 +390,7 @@ void *__PHYSFS_platformOpenWrite(const char *filename);
*
* Opening a file for append multiple times has undefined results.
*
* Call __PHYSFS_setError() and return (NULL) if the file can't be opened.
* Call PHYSFS_setErrorCode() and return (NULL) if the file can't be opened.
*/
void *__PHYSFS_platformOpenAppend(const char *filename);

Expand All @@ -412,7 +402,7 @@ void *__PHYSFS_platformOpenAppend(const char *filename);
* immediately after those bytes.
* On success, return (len) and position the file pointer immediately past
* the end of the last read byte. Return (-1) if there is a catastrophic
* error, and call __PHYSFS_setError() to describe the problem; the file
* error, and call PHYSFS_setErrorCode() to describe the problem; the file
* pointer should not move in such a case. A partial read is success; only
* return (-1) on total failure; presumably, the next read call after a
* partial read will fail as such.
Expand All @@ -425,7 +415,7 @@ PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buf, PHYSFS_uint64 len);
* 8-bit bytes from the area pointed to by (buffer). If there is a problem,
* return the number of bytes written, and position the file pointer
* immediately after those bytes. Return (-1) if there is a catastrophic
* error, and call __PHYSFS_setError() to describe the problem; the file
* error, and call PHYSFS_setErrorCode() to describe the problem; the file
* pointer should not move in such a case. A partial write is success; only
* return (-1) on total failure; presumably, the next write call after a
* partial write will fail as such.
Expand All @@ -441,7 +431,7 @@ PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
*
* Not all file types can seek; this is to be expected by the caller.
*
* On error, call __PHYSFS_setError() and return zero. On success, return
* On error, call PHYSFS_setErrorCode() and return zero. On success, return
* a non-zero value.
*/
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos);
Expand All @@ -454,7 +444,7 @@ int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos);
*
* Not all file types can "tell"; this is to be expected by the caller.
*
* On error, call __PHYSFS_setError() and return -1. On success, return >= 0.
* On error, call PHYSFS_setErrorCode() and return -1. On success, return >= 0.
*/
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque);

Expand All @@ -465,7 +455,7 @@ PHYSFS_sint64 __PHYSFS_platformTell(void *opaque);
* The caller expects that this information may not be available for all
* file types on all platforms.
*
* Return -1 if you can't do it, and call __PHYSFS_setError(). Otherwise,
* Return -1 if you can't do it, and call PHYSFS_setErrorCode(). Otherwise,
* return the file length in 8-bit bytes.
*/
PHYSFS_sint64 __PHYSFS_platformFileLength(void *handle);
Expand Down Expand Up @@ -609,7 +599,7 @@ void __PHYSFS_platformDestroyMutex(void *mutex);
* timing out! We're talking major system errors; block until the mutex
* is available otherwise.)
*
* _DO NOT_ call __PHYSFS_setError() in here! Since setError calls this
* _DO NOT_ call PHYSFS_setErrorCode() in here! Since setErrorCode calls this
* function, you'll cause an infinite recursion. This means you can't
* use the BAIL_*MACRO* macros, either.
*/
Expand All @@ -621,7 +611,7 @@ int __PHYSFS_platformGrabMutex(void *mutex);
* been released, the next thread in line to grab the mutex (if any) may
* proceed.
*
* _DO NOT_ call __PHYSFS_setError() in here! Since setError calls this
* _DO NOT_ call PHYSFS_setErrorCode() in here! Since setErrorCode calls this
* function, you'll cause an infinite recursion. This means you can't
* use the BAIL_*MACRO* macros, either.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/platform_windows.c
Expand Up @@ -369,7 +369,7 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0)
} /* while */

if ((ptr == modpath) && (*ptr != '\\'))
__PHYSFS_setError(PHYSFS_ERR_OTHER_ERROR); /* oh well. */
PHYSFS_setErrorCode(PHYSFS_ERR_OTHER_ERROR); /* oh well. */
else
{
*(ptr+1) = '\0'; /* chop off filename. */
Expand Down

0 comments on commit 697c31e

Please sign in to comment.