From d6ce63e9124b297ebb1b0d1a97403149024ed801 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 28 Mar 2009 16:15:03 -0400 Subject: [PATCH] Added PHYSFS_getAllocator(). --- src/physfs.c | 7 +++++++ src/physfs.h | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/physfs.c b/src/physfs.c index 8b47a361..4a5dc11f 100644 --- a/src/physfs.c +++ b/src/physfs.c @@ -2153,6 +2153,13 @@ int PHYSFS_setAllocator(const PHYSFS_Allocator *a) } /* PHYSFS_setAllocator */ +const PHYSFS_Allocator *PHYSFS_getAllocator(void) +{ + BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL); + return &allocator; +} /* PHYSFS_getAllocator */ + + static void *mallocAllocatorMalloc(PHYSFS_uint64 s) { BAIL_IF_MACRO(__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL); diff --git a/src/physfs.h b/src/physfs.h index f0893829..635db6ac 100644 --- a/src/physfs.h +++ b/src/physfs.h @@ -2380,6 +2380,44 @@ __EXPORT__ void PHYSFS_utf8FromLatin1(const char *src, char *dst, /* Everything above this line is part of the PhysicsFS 2.0 API. */ +/** + * \fn const PHYSFS_Allocator *PHYSFS_getAllocator(void) + * \brief Discover the current allocator. + * + * (This is for limited, hardcore use. If you don't immediately see a need + * for it, you can probably ignore this forever.) + * + * This function exposes the function pointers that make up the currently-used + * allocator. This can be useful for apps that want to access PhysicsFS's + * internal, default allocation routines, as well as for external code that + * wants to share the same allocator, even if the application specified their + * own. + * + * This call is only valid between PHYSFS_init() and PHYSFS_deinit() calls; + * it will return NULL if the library isn't initialized. As we can't + * guarantee the state of the internal allocators unless the library is + * initialized, you shouldn't use any allocator returned here after a call + * to PHYSFS_deinit(). + * + * Do not call the returned allocator's Init() or Deinit() methods under any + * circumstances. + * + * If you aren't immediately sure what to do with this function, you can + * safely ignore it altogether. + * + * \return Current allocator, as set by PHYSFS_setAllocator(), or PhysicsFS's + * internal, default allocator if no application-defined allocator + * is currently set. Will return NULL if the library is not + * initialized. + * + * \sa PHYSFS_Allocator + * \sa PHYSFS_setAllocator + */ +__EXPORT__ const PHYSFS_Allocator *PHYSFS_getAllocator(void); + + +/* Everything above this line is part of the PhysicsFS 2.1 API. */ + #ifdef __cplusplus }