+// temp string handling
+
+// all tempstrings go into this buffer consecutively, and it is reset
+// whenever PRVM_ExecuteProgram returns to the engine
+// (technically each PRVM_ExecuteProgram call saves the cursize value and
+// restores it on return, so multiple recursive calls can share the same
+// buffer)
+// the buffer size is automatically grown as needed
+
+int PRVM_SetTempString(const char *s)
+{
+ int size;
+ char *t;
+ if (!s)
+ return 0;
+ size = (int)strlen(s) + 1;
+ if (developer.integer >= 300)
+ Con_Printf("PRVM_SetTempString: cursize %i, size %i\n", vm_tempstringsbuf.cursize, size);
+ if (vm_tempstringsbuf.maxsize < vm_tempstringsbuf.cursize + size)
+ {
+ sizebuf_t old = vm_tempstringsbuf;
+ if (vm_tempstringsbuf.cursize + size >= 1<<28)
+ PRVM_ERROR("PRVM_SetTempString: ran out of tempstring memory! (refusing to grow tempstring buffer over 256MB, cursize %i, size %i)\n", vm_tempstringsbuf.cursize, size);
+ vm_tempstringsbuf.maxsize = max(vm_tempstringsbuf.maxsize, 65536);
+ while (vm_tempstringsbuf.maxsize < vm_tempstringsbuf.cursize + size)
+ vm_tempstringsbuf.maxsize *= 2;
+ if (vm_tempstringsbuf.maxsize != old.maxsize || vm_tempstringsbuf.data == NULL)
+ {
+ if (developer.integer >= 100)
+ Con_Printf("PRVM_SetTempString: enlarging tempstrings buffer (%iKB -> %iKB)\n", old.maxsize/1024, vm_tempstringsbuf.maxsize/1024);
+ vm_tempstringsbuf.data = Mem_Alloc(sv_mempool, vm_tempstringsbuf.maxsize);
+ if (old.cursize)
+ memcpy(vm_tempstringsbuf.data, old.data, old.cursize);
+ if (old.data)
+ Mem_Free(old.data);
+ }
+ }
+ t = (char *)vm_tempstringsbuf.data + vm_tempstringsbuf.cursize;
+ memcpy(t, s, size);
+ vm_tempstringsbuf.cursize += size;
+ return PRVM_SetEngineString(t);
+}
+
+int PRVM_AllocString(size_t bufferlength, char **pointer)