IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23305 for trunk/psLib


Ignore:
Timestamp:
Mar 12, 2009, 2:25:59 PM (17 years ago)
Author:
eugene
Message:

added psMemTypeEqual to compare types for two (psAlloc-ed) pointers

Location:
trunk/psLib/src/sys
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psMemory.c

    r21346 r23305  
    10691069                   memBlock->func, memBlock->file, memBlock->lineno, (unsigned long)memBlock->tid);
    10701070}
     1071
     1072bool psMemTypeEqual (void *ptr1, void *ptr2) {
     1073
     1074    // if ptr is a psAlloc()'d memory, find the actual address of the memBlock
     1075    psMemBlock *memBlock1 = ((psMemBlock *)ptr1) - 1;
     1076    HANDLE_BAD_BLOCK(memBlock1, __FILE__, __LINE__, __func__);
     1077    if (!memBlock1->freeFunc) return false;
     1078
     1079    // if ptr is a psAlloc()'d memory, find the actual address of the memBlock
     1080    psMemBlock *memBlock2 = ((psMemBlock *)ptr2) - 1;
     1081    HANDLE_BAD_BLOCK(memBlock2, __FILE__, __LINE__, __func__);
     1082    if (!memBlock2->freeFunc) return false;
     1083
     1084    return (memBlock1->freeFunc == memBlock2->freeFunc);
     1085}
  • trunk/psLib/src/sys/psMemory.h

    r15047 r23305  
    636636);
    637637
     638/** test for matching types (equal free functions)
     639 *
     640 * This function returns true if the two pointers have matching, non-NULL free functions.
     641 * Supplied pointers must have been allocated within the psLib memory system (ie, with a psAlloc) or the function will abort. (XXX just return false?)
     642 * Supplied pointers must have been provided with free function or the function returns false.
     643 */
     644bool psMemTypeEqual (void *ptr1, ///< pointer to first psMemory object
     645                     void *ptr2 ///< pointer to second psMemory object
     646  );
     647
    638648// Ensure this is a psLib pointer
    639649#define PS_ASSERT_PTR_HEAVY(PTR, RVAL) \
Note: See TracChangeset for help on using the changeset viewer.