int edict;
} prvm_eval_t;
-typedef struct prvm_required_field_s
+typedef struct prvm_required_field_s
{
int type;
const char *name;
// However, the first one should be preferred.
} priv;
// QuakeC fields (stored in dynamically resized array)
- union
+ union
{
void *vp;
entvars_t *server;
const char *PRVM_GetString(int num);
int PRVM_SetQCString(const char *s);
int PRVM_SetEngineString(const char *s);
-char *PRVM_AllocString(int bufferlength);
-void PRVM_FreeString(char *s);
+int PRVM_AllocString(int bufferlength, char **pointer);
+void PRVM_FreeString(int num);
//============================================================================
VM_SAFEPARMCOUNT(1,VM_strzone);
in = PRVM_G_STRING(OFS_PARM0);
- out = PRVM_AllocString(strlen(in) + 1);
+ PRVM_G_INT(OFS_RETURN) = PRVM_AllocString(strlen(in) + 1, &out);
strcpy(out, in);
- PRVM_G_INT(OFS_RETURN) = PRVM_SetQCString(out);
}
/*
void VM_strunzone(void)
{
VM_SAFEPARMCOUNT(1,VM_strunzone);
- PRVM_FreeString((char *)PRVM_G_STRING(OFS_PARM0));
+ PRVM_FreeString(PRVM_G_INT(OFS_PARM0));
}
/*
for( count = 0, pos = altstr ; *pos ; pos++ ) {
if( *pos == '\\' ) {
if( !*++pos ) {
- break;
+ break;
}
} else if( *pos == '\'' ) {
count++;
{
case ev_string:
l = strlen(s) + 1;
- new_p = PRVM_AllocString(l);
- val->string = PRVM_SetQCString(new_p);
+ val->string = PRVM_AllocString(l, &new_p);
for (i = 0;i < l;i++)
{
if (s[i] == '\\' && i < l-1)
return -1 - i;
}
-char *PRVM_AllocString(int bufferlength)
+int PRVM_AllocString(int bufferlength, char **pointer)
{
int i;
if (!bufferlength)
}
prog->numknownstrings++;
}
- return (char *)(prog->knownstrings[i] = PRVM_Alloc(bufferlength));
+ (char *)(prog->knownstrings[i]) = PRVM_Alloc(bufferlength);
+ if (pointer)
+ *pointer = (char *)(prog->knownstrings[i]);
+ return -1 - i;
}
-void PRVM_FreeString(char *s)
+void PRVM_FreeString(int num)
{
- int i;
- if (!s)
+ if (num == 0)
Host_Error("PRVM_FreeString: attempt to free a NULL string\n");
- if (s >= prog->strings && s <= prog->strings + prog->stringssize)
+ else if (num >= 0 && num < prog->stringssize)
Host_Error("PRVM_FreeString: attempt to free a constant string\n");
- for (i = 0;i < prog->numknownstrings;i++)
- if (prog->knownstrings[i] == s)
- break;
- if (i == prog->numknownstrings)
- Host_Error("PRVM_FreeString: attempt to free a non-existent or already freed string\n");
- PRVM_Free((char *)prog->knownstrings[i]);
- prog->knownstrings[i] = NULL;
+ else if (num < 0 && num >= -prog->numknownstrings)
+ {
+ num = -1 - num;
+ if (!prog->knownstrings[num])
+ Host_Error("PRVM_FreeString: attempt to free a non-existent or already freed string\n");
+ PRVM_Free((char *)prog->knownstrings[num]);
+ prog->knownstrings[num] = NULL;
+ }
+ else
+ Host_Error("PRVM_FreeString: invalid string offset %i\n", num);
}