Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions glslang/Include/PoolAlloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ class TAllocation {
// makes the compiler print warnings about 0 length memsets,
// even with the if() protecting them.
# ifdef GUARD_BLOCKS
memset(preGuard(), guardBlockBeginVal, guardBlockSize);
memset(preGuard(), guardBlockBeginVal, guardBlockSize());
memset(data(), userDataFill, size);
memset(postGuard(), guardBlockEndVal, guardBlockSize);
memset(postGuard(), guardBlockEndVal, guardBlockSize());
# endif
}

Expand All @@ -100,20 +100,20 @@ class TAllocation {
// Return total size needed to accommodate user buffer of 'size',
// plus our tracking data.
inline static size_t allocationSize(size_t size) {
return size + 2 * guardBlockSize + headerSize();
return size + 2 * guardBlockSize() + headerSize();
}

// Offset from surrounding buffer to get to user data buffer.
inline static unsigned char* offsetAllocation(unsigned char* m) {
return m + guardBlockSize + headerSize();
return m + guardBlockSize() + headerSize();
}

private:
void checkGuardBlock(unsigned char* blockMem, unsigned char val, const char* locText) const;

// Find offsets to pre and post guard blocks, and user data buffer
unsigned char* preGuard() const { return mem + headerSize(); }
unsigned char* data() const { return preGuard() + guardBlockSize; }
unsigned char* data() const { return preGuard() + guardBlockSize(); }
unsigned char* postGuard() const { return data() + size; }

size_t size; // size of the user data area
Expand All @@ -125,15 +125,15 @@ class TAllocation {
static inline constexpr unsigned char userDataFill = 0xcd;

# ifdef GUARD_BLOCKS
static inline constexpr size_t guardBlockSize = 16;
# else
static inline constexpr size_t guardBlockSize = 0;
# endif

# ifdef GUARD_BLOCKS
inline static size_t headerSize() { return sizeof(TAllocation); }
inline static constexpr size_t headerSize() { return sizeof(TAllocation); }
inline static constexpr size_t guardBlockSize() {
constexpr size_t kMinGuard = 16;
constexpr size_t kAlignment = 16;
return ((kMinGuard + sizeof(TAllocation) + kAlignment - 1) & ~(kAlignment - 1)) - sizeof(TAllocation);
}
# else
inline static size_t headerSize() { return 0; }
inline static constexpr size_t headerSize() { return 0; }
inline static constexpr size_t guardBlockSize() { return 0; }
# endif
};

Expand Down
4 changes: 2 additions & 2 deletions glslang/MachineIndependent/PoolAlloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void TAllocation::checkGuardBlock(unsigned char*, unsigned char, const char*) co
#endif
{
#ifdef GUARD_BLOCKS
for (size_t x = 0; x < guardBlockSize; x++) {
for (size_t x = 0; x < guardBlockSize(); x++) {
if (blockMem[x] != val) {
const int maxSize = 80;
char assertMsg[maxSize];
Expand All @@ -160,7 +160,7 @@ void TAllocation::checkGuardBlock(unsigned char*, unsigned char, const char*) co
}
}
#else
assert(guardBlockSize == 0);
assert(guardBlockSize() == 0);
#endif
}

Expand Down