/* see copyright notice in squirrel.h */ #include "sqpcheader.h" // --- calog patch: count every allocation against the running context's memory cap --- // Squirrel's allocator is process-global and passes exact sizes (so no per-block header is needed); // calogSquirrelMemCharge (src/squirrel/squirrelAdapter.c) tallies the running context's live bytes // via a thread-local and returns non-zero once over the cap, tripping the flag the Execute loop // checks. The allocator never refuses (Squirrel does not NULL-check allocations) -- enforcement is // the Execute-loop unwind. _calogSqTrip is defined in sqvm.cpp. extern "C" int calogSquirrelMemCharge(long long delta); extern thread_local int _calogSqTrip; // --- end calog patch --- #ifndef SQ_EXCLUDE_DEFAULT_MEMFUNCTIONS void *sq_vm_malloc(SQUnsignedInteger size){ void *p = malloc(size); if (p && calogSquirrelMemCharge((long long)size)) { _calogSqTrip = 1; } return p; } void *sq_vm_realloc(void *p, SQUnsignedInteger oldsize, SQUnsignedInteger size){ void *q = realloc(p, size); if (q && calogSquirrelMemCharge((long long)size - (long long)oldsize)) { _calogSqTrip = 1; } return q; } void sq_vm_free(void *p, SQUnsignedInteger size){ free(p); calogSquirrelMemCharge(-(long long)size); } #endif