new_node3(slang_ir_opcode op,
slang_ir_node *c0, slang_ir_node *c1, slang_ir_node *c2)
{
-#if USE_MEMPOOL
slang_ir_node *n = (slang_ir_node *) _slang_alloc(sizeof(slang_ir_node));
-#else
- slang_ir_node *n = (slang_ir_node *) calloc(1, sizeof(slang_ir_node));
-#endif
if (n) {
n->Opcode = op;
n->Children[0] = c0;
assert(fun->param_count == totalArgs);
/* allocate temporary arrays */
-#if USE_MEMPOOL
paramMode = (ParamMode *)
_slang_alloc(totalArgs * sizeof(ParamMode));
substOld = (slang_variable **)
_slang_alloc(totalArgs * sizeof(slang_variable *));
substNew = (slang_operation **)
_slang_alloc(totalArgs * sizeof(slang_operation *));
-#else
- paramMode = (ParamMode *)
- _mesa_calloc(totalArgs * sizeof(ParamMode));
- substOld = (slang_variable **)
- _mesa_calloc(totalArgs * sizeof(slang_variable *));
- substNew = (slang_operation **)
- _mesa_calloc(totalArgs * sizeof(slang_operation *));
-#endif
#if 0
printf("Inline call to %s (total vars=%d nparams=%d)\n",
}
}
-#if !USE_MEMPOOL
- _mesa_free(paramMode);
- _mesa_free(substOld);
- _mesa_free(substNew);
-#endif
+ _slang_free(paramMode);
+ _slang_free(substOld);
+ _slang_free(substNew);
#if 0
printf("Done Inline call to %s (total vars=%d nparams=%d)\n",
/* Replace the function call with the inlined block */
slang_operation_destruct(oper);
*oper = *inlined;
-#if !USE_MEMPOOL
- _mesa_free(inlined);
-#endif
+ _slang_free(inlined);
#if 0
assert(inlined->locals);
n->Store = n0->Store;
n->Writemask = writemask;
-#if !USE_MEMPOOL
- free(n0);
-#endif
+ _slang_free(n0);
}
return n;
if (n) {
n->Store = store;
}
-#if !USE_MEMPOOL
else {
- free(store);
+ _slang_free(store);
}
-#endif
}
return n;
}
select->children[2].literal_size = 1;
n = _slang_gen_select(A, select);
-
-#if !USE_MEMPOOL
- /* xxx wrong */
- free(select->children);
- free(select);
-#endif
-
return n;
}
slang_operation_copy(&select->children[2], &oper->children[1]);
n = _slang_gen_select(A, select);
-
-#if !USE_MEMPOOL
- /* xxx wrong */
- free(select->children);
- free(select);
-#endif
-
return n;
}
parse_identifier_str(C, &fractional);
parse_identifier_str(C, &exponent);
-#if USE_MEMPOOL
- whole = (char *) (_slang_alloc((_mesa_strlen(integral) +
-#else
- whole = (char *) (slang_alloc_malloc((_mesa_strlen(integral) +
-#endif
- _mesa_strlen(fractional) +
- _mesa_strlen(exponent) + 3) * sizeof(char)));
+ whole = (char *) _slang_alloc((_mesa_strlen(integral) +
+ _mesa_strlen(fractional) +
+ _mesa_strlen(exponent) + 3) * sizeof(char));
if (whole == NULL) {
slang_info_log_memory(C->L);
return 0;
*number = (float) (_mesa_strtod(whole, (char **) NULL));
-#if USE_MEMPOOL
_slang_free(whole);
-#else
- slang_alloc_free(whole);
-#endif
+
return 1;
}
* parse the expression */
var->type.specifier.type = SLANG_SPEC_ARRAY;
var->type.specifier._array = (slang_type_specifier *)
-#if USE_MEMPOOL
_slang_alloc(sizeof(slang_type_specifier));
-#else
- slang_alloc_malloc(sizeof(slang_type_specifier));
-#endif
if (var->type.specifier._array == NULL) {
slang_info_log_memory(C->L);
return GL_FALSE;
}
/* set-up a new struct */
-#if USE_MEMPOOL
*st = (slang_struct *) _slang_alloc(sizeof(slang_struct));
-#else
- *st = (slang_struct *) slang_alloc_malloc(sizeof(slang_struct));
-#endif
if (*st == NULL) {
slang_info_log_memory(C->L);
return 0;
}
if (!slang_struct_construct(*st)) {
-#if USE_MEMPOOL
_slang_free(*st);
-#else
- slang_alloc_free(*st);
-#endif
*st = NULL;
slang_info_log_memory(C->L);
return 0;
slang_struct *s;
O->structs->structs =
-#if USE_MEMPOOL
(slang_struct *) _slang_realloc(O->structs->structs,
-#else
- (slang_struct *) slang_alloc_realloc(O->structs->structs,
-#endif
- O->structs->num_structs *
- sizeof(slang_struct),
- (O->structs->num_structs +
- 1) * sizeof(slang_struct));
+ O->structs->num_structs
+ * sizeof(slang_struct),
+ (O->structs->num_structs + 1)
+ * sizeof(slang_struct));
if (O->structs->structs == NULL) {
slang_info_log_memory(C->L);
return 0;
return 0;
}
- spec->_struct =
-#if USE_MEMPOOL
- (slang_struct *) _slang_alloc(sizeof(slang_struct));
-#else
- (slang_struct *) slang_alloc_malloc(sizeof(slang_struct));
-#endif
+ spec->_struct = (slang_struct *) _slang_alloc(sizeof(slang_struct));
if (spec->_struct == NULL) {
slang_info_log_memory(C->L);
return 0;
}
if (!slang_struct_construct(spec->_struct)) {
-#if USE_MEMPOOL
_slang_free(spec->_struct);
-#else
- slang_alloc_free(spec->_struct);
-#endif
spec->_struct = NULL;
return 0;
}
*total_ops -= n;
*ops = (slang_operation *)
-#if USE_MEMPOOL
_slang_realloc(*ops,
-#else
- slang_alloc_realloc(*ops,
-#endif
- (*total_ops + n) * sizeof(slang_operation),
- *total_ops * sizeof(slang_operation));
+ (*total_ops + n) * sizeof(slang_operation),
+ *total_ops * sizeof(slang_operation));
if (*ops == NULL) {
slang_info_log_memory(C->L);
return 0;
/* allocate default operation, becomes a no-op if not used */
ops = (slang_operation *)
-#if USE_MEMPOOL
_slang_realloc(ops,
-#else
- slang_alloc_realloc(ops,
-#endif
- num_ops * sizeof(slang_operation),
- (num_ops + 1) * sizeof(slang_operation));
+ num_ops * sizeof(slang_operation),
+ (num_ops + 1) * sizeof(slang_operation));
if (ops == NULL) {
slang_info_log_memory(C->L);
return 0;
slang_operation_destruct(oper);
*oper = *ops; /* struct copy */
-#if USE_MEMPOOL
_slang_free(ops);
-#else
- slang_alloc_free(ops);
-#endif
return 1;
}
return 0;
/* create function's body operation */
- func->body =
-#if USE_MEMPOOL
- (slang_operation *) _slang_alloc(sizeof(slang_operation));
-#else
- (slang_operation *) slang_alloc_malloc(sizeof(slang_operation));
-#endif
+ func->body = (slang_operation *) _slang_alloc(sizeof(slang_operation));
if (func->body == NULL) {
slang_info_log_memory(C->L);
return 0;
}
if (!slang_operation_construct(func->body)) {
-#if USE_MEMPOOL
_slang_free(func->body);
-#else
- slang_alloc_free(func->body);
-#endif
func->body = NULL;
slang_info_log_memory(C->L);
return 0;
/* put the variable into operation's scope */
op_id.locals->variables =
-#if USE_MEMPOOL
(slang_variable **) _slang_alloc(sizeof(slang_variable *));
-#else
- (slang_variable **) slang_alloc_malloc(sizeof(slang_variable *));
-#endif
if (op_id.locals->variables == NULL) {
slang_operation_destruct(&op_id);
return GL_FALSE;
}
op_assign.type = SLANG_OPER_ASSIGN;
op_assign.children =
-#if USE_MEMPOOL
(slang_operation *) _slang_alloc(2 * sizeof(slang_operation));
-#else
- (slang_operation *) slang_alloc_malloc(2 * sizeof(slang_operation));
-#endif
if (op_assign.children == NULL) {
slang_operation_destruct(&op_assign);
op_id.locals->num_variables = 0;
/* carefully destroy the operations */
op_assign.num_children = 0;
-#if USE_MEMPOOL
_slang_free(op_assign.children);
-#else
- slang_alloc_free(op_assign.children);
-#endif
op_assign.children = NULL;
slang_operation_destruct(&op_assign);
op_id.locals->num_variables = 0;
if (!slang_type_specifier_copy(&var->type.specifier, &type->specifier))
return 0;
var->initializer =
-#if USE_MEMPOOL
(slang_operation *) _slang_alloc(sizeof(slang_operation));
-#else
- (slang_operation *) slang_alloc_malloc(sizeof(slang_operation));
-#endif
if (var->initializer == NULL) {
slang_info_log_memory(C->L);
return 0;
}
if (!slang_operation_construct(var->initializer)) {
-#if USE_MEMPOOL
_slang_free(var->initializer);
-#else
- slang_alloc_free(var->initializer);
-#endif
var->initializer = NULL;
slang_info_log_memory(C->L);
return 0;
if (found_func == NULL) {
/* New function, add it to the function list */
O->funs->functions =
-#if USE_MEMPOOL
(slang_function *) _slang_realloc(O->funs->functions,
-#else
- (slang_function *) slang_alloc_realloc(O->funs->functions,
-#endif
- O->funs->num_functions *
- sizeof(slang_function),
- (O->funs->num_functions +
- 1) * sizeof(slang_function));
+ O->funs->num_functions
+ * sizeof(slang_function),
+ (O->funs->num_functions + 1)
+ * sizeof(slang_function));
if (O->funs->functions == NULL) {
slang_info_log_memory(C->L);
slang_function_destruct(&parsed_func);
void
slang_fixup_table_free(slang_fixup_table * fix)
{
-#if USE_MEMPOOL
_slang_free(fix->table);
-#else
- slang_alloc_free(fix->table);
-#endif
slang_fixup_table_init(fix);
}
slang_fixup_save(slang_fixup_table *fixups, GLuint address)
{
fixups->table = (GLuint *)
-#if USE_MEMPOOL
_slang_realloc(fixups->table,
-#else
- slang_alloc_realloc(fixups->table,
-#endif
- fixups->count * sizeof(GLuint),
- (fixups->count + 1) * sizeof(GLuint));
+ fixups->count * sizeof(GLuint),
+ (fixups->count + 1) * sizeof(GLuint));
if (fixups->table == NULL)
return GL_FALSE;
fixups->table[fixups->count] = address;
return 0;
func->parameters = (slang_variable_scope *)
-#if USE_MEMPOOL
_slang_alloc(sizeof(slang_variable_scope));
-#else
- slang_alloc_malloc(sizeof(slang_variable_scope));
-#endif
if (func->parameters == NULL) {
slang_variable_destruct(&func->header);
return 0;
{
slang_variable_destruct(&func->header);
slang_variable_scope_destruct(func->parameters);
-#if USE_MEMPOOL
_slang_free(func->parameters);
-#else
- slang_alloc_free(func->parameters);
-#endif
if (func->body != NULL) {
slang_operation_destruct(func->body);
-#if USE_MEMPOOL
_slang_free(func->body);
-#else
- slang_alloc_free(func->body);
-#endif
}
slang_fixup_table_free(&func->fixups);
}
for (i = 0; i < scope->num_functions; i++)
slang_function_destruct(scope->functions + i);
-#if USE_MEMPOOL
_slang_free(scope->functions);
-#else
- slang_alloc_free(scope->functions);
-#endif
}
for (i = 0; i < oper->num_children; i++)
slang_operation_destruct(oper->children + i);
-#if !USE_MEMPOOL
- slang_alloc_free(oper->children);
+ _slang_free(oper->children);
slang_variable_scope_destruct(oper->locals);
- slang_alloc_free(oper->locals);
-#endif
+ _slang_free(oper->locals);
oper->children = NULL;
oper->num_children = 0;
oper->locals = NULL;
return GL_FALSE;
z.type = y->type;
z.children = (slang_operation *)
-#if USE_MEMPOOL
_slang_alloc(y->num_children * sizeof(slang_operation));
-#else
- slang_alloc_malloc(y->num_children * sizeof(slang_operation));
-#endif
if (z.children == NULL) {
slang_operation_destruct(&z);
return GL_FALSE;
slang_operation_new(GLuint count)
{
slang_operation *ops
-#if USE_MEMPOOL
= (slang_operation *) _slang_alloc(count * sizeof(slang_operation));
-#else
- = (slang_operation *) _mesa_malloc(count * sizeof(slang_operation));
-#endif
assert(count > 0);
if (ops) {
GLuint i;
slang_operation_delete(slang_operation *oper)
{
slang_operation_destruct(oper);
-#if !USE_MEMPOOL
- _mesa_free(oper);
-#endif
+ _slang_free(oper);
}
slang_operation *ops;
ops = (slang_operation *)
-#if USE_MEMPOOL
_slang_realloc(*children,
-#else
- slang_alloc_realloc(*children,
-#endif
- *numChildren * sizeof(slang_operation),
- (*numChildren + 1) * sizeof(slang_operation));
+ *numChildren * sizeof(slang_operation),
+ (*numChildren + 1) * sizeof(slang_operation));
if (ops) {
slang_operation *newOp = ops + *numChildren;
if (!slang_operation_construct(newOp)) {
-#if !USE_MEMPOOL
- _mesa_free(ops);
-#endif
+ _slang_free(ops);
*children = NULL;
return NULL;
}
assert(pos <= *numElements);
ops = (slang_operation *)
-#if USE_MEMPOOL
_slang_alloc((*numElements + 1) * sizeof(slang_operation));
-#else
- _mesa_malloc((*numElements + 1) * sizeof(slang_operation));
-#endif
if (ops) {
slang_operation *newOp;
newOp = ops + pos;
(*numElements - pos) * sizeof(slang_operation));
if (!slang_operation_construct(newOp)) {
-#if !USE_MEMPOOL
- _mesa_free(ops);
-#endif
+ _slang_free(ops);
*numElements = 0;
*array = NULL;
return NULL;
}
-#if !USE_MEMPOOL
if (*array)
- _mesa_free(*array);
-#endif
+ _slang_free(*array);
*array = ops;
(*numElements)++;
return newOp;
for (i = 0; i < scope->num_structs; i++)
slang_struct_destruct(scope->structs + i);
-#if USE_MEMPOOL
_slang_free(scope->structs);
-#else
- slang_alloc_free(scope->structs);
-#endif
/* do not free scope->outer_scope */
}
GLuint i;
_slang_struct_scope_ctr(&z);
- z.structs =
-#if USE_MEMPOOL
- (slang_struct *) _slang_alloc(y->num_structs *
-#else
- (slang_struct *) slang_alloc_malloc(y->num_structs *
-#endif
- sizeof(slang_struct));
+ z.structs = (slang_struct *)
+ _slang_alloc(y->num_structs * sizeof(slang_struct));
if (z.structs == NULL) {
slang_struct_scope_destruct(&z);
return 0;
{
stru->a_name = SLANG_ATOM_NULL;
stru->fields = (slang_variable_scope *)
-#if USE_MEMPOOL
_slang_alloc(sizeof(slang_variable_scope));
-#else
- slang_alloc_malloc(sizeof(slang_variable_scope));
-#endif
if (stru->fields == NULL)
return 0;
_slang_variable_scope_ctr(stru->fields);
stru->structs =
-#if USE_MEMPOOL
(slang_struct_scope *) _slang_alloc(sizeof(slang_struct_scope));
-#else
- (slang_struct_scope *) slang_alloc_malloc(sizeof(slang_struct_scope));
-#endif
if (stru->structs == NULL) {
slang_variable_scope_destruct(stru->fields);
-#if USE_MEMPOOL
_slang_free(stru->fields);
-#else
- slang_alloc_free(stru->fields);
-#endif
return 0;
}
_slang_struct_scope_ctr(stru->structs);
slang_struct_destruct(slang_struct * stru)
{
slang_variable_scope_destruct(stru->fields);
-#if USE_MEMPOOL
_slang_free(stru->fields);
-#else
- slang_alloc_free(stru->fields);
-#endif
slang_struct_scope_destruct(stru->structs);
-#if USE_MEMPOOL
_slang_free(stru->structs);
-#else
- slang_alloc_free(stru->structs);
-#endif
}
int
static slang_variable *
slang_variable_new(void)
{
-#if USE_MEMPOOL
slang_variable *v = (slang_variable *) _slang_alloc(sizeof(slang_variable));
-#else
- slang_variable *v = (slang_variable *) malloc(sizeof(slang_variable));
-#endif
if (v) {
if (!slang_variable_construct(v)) {
-#if !USE_MEMPOOL
- free(v);
-#endif
+ _slang_free(v);
v = NULL;
}
}
slang_variable_delete(slang_variable * var)
{
slang_variable_destruct(var);
-#if !USE_MEMPOOL
- free(var);
-#endif
+ _slang_free(var);
}
_slang_variable_scope_new(slang_variable_scope *parent)
{
slang_variable_scope *s;
-#if USE_MEMPOOL
s = (slang_variable_scope *) _slang_alloc(sizeof(slang_variable_scope));
-#else
- s = (slang_variable_scope *) _mesa_calloc(sizeof(slang_variable_scope));
-#endif
- s->outer_scope = parent;
+ if (s)
+ s->outer_scope = parent;
return s;
}
if (scope->variables[i])
slang_variable_delete(scope->variables[i]);
}
-#if USE_MEMPOOL
_slang_free(scope->variables);
-#else
- slang_alloc_free(scope->variables);
-#endif
/* do not free scope->outer_scope */
}
_slang_variable_scope_ctr(&z);
z.variables = (slang_variable **)
-#if USE_MEMPOOL
_slang_alloc(y->num_variables * sizeof(slang_variable *));
-#else
- _mesa_calloc(y->num_variables * sizeof(slang_variable *));
-#endif
if (z.variables == NULL) {
slang_variable_scope_destruct(&z);
return 0;
{
const int n = scope->num_variables;
scope->variables = (slang_variable **)
-#if USE_MEMPOOL
_slang_realloc(scope->variables,
-#else
- slang_alloc_realloc(scope->variables,
-#endif
- n * sizeof(slang_variable *),
- (n + 1) * sizeof(slang_variable *));
+ n * sizeof(slang_variable *),
+ (n + 1) * sizeof(slang_variable *));
if (!scope->variables)
return NULL;
slang_fully_specified_type_destruct(&var->type);
if (var->initializer != NULL) {
slang_operation_destruct(var->initializer);
-#if USE_MEMPOOL
_slang_free(var->initializer);
-#else
- slang_alloc_free(var->initializer);
-#endif
}
#if 0
if (var->aux) {
z.array_len = y->array_len;
if (y->initializer != NULL) {
z.initializer
-#if USE_MEMPOOL
= (slang_operation *) _slang_alloc(sizeof(slang_operation));
-#else
- = (slang_operation *) slang_alloc_malloc(sizeof(slang_operation));
-#endif
if (z.initializer == NULL) {
slang_variable_destruct(&z);
return 0;
}
if (!slang_operation_construct(z.initializer)) {
-#if !USE_MEMPOOL
- slang_alloc_free(z.initializer);
-#endif
+ _slang_free(z.initializer);
slang_variable_destruct(&z);
return 0;
}
_slang_new_ir_storage(enum register_file file, GLint index, GLint size)
{
slang_ir_storage *st;
-#if USE_MEMPOOL
st = (slang_ir_storage *) _slang_alloc(sizeof(slang_ir_storage));
-#else
- st = (slang_ir_storage *) _mesa_calloc(sizeof(slang_ir_storage));
-#endif
if (st) {
st->File = file;
st->Index = index;
if (!_slang_alloc_temp(emitInfo->vt, n->Store)) {
slang_info_log_error(emitInfo->log,
"Ran out of registers, too many temporaries");
-#if USE_MEMPOOL
_slang_free(n->Store);
-#else
- _mesa_free(n->Store);
-#endif
n->Store = NULL;
return GL_FALSE;
}
#include "imports.h"
#include "context.h"
#include "slang_ir.h"
+#include "slang_mem.h"
#include "prog_print.h"
}
+#if 0 /* no longer needed with mempool */
/**
* Since many IR nodes might point to the same IR storage info, we need
* to be careful when deleting things.
for (i = 0; i < 3; i++)
_slang_refcount_storage(n->Children[i]);
}
+#endif
static void
if (!n)
return;
+#if 0
if (n->Store) {
n->Store->RefCount--;
if (n->Store->RefCount == 0) {
-#if !USE_MEMPOOL
- free(n->Store);
-#endif
+ _slang_free(n->Store);
n->Store = NULL;
}
}
+#endif
for (i = 0; i < 3; i++)
_slang_free_ir(n->Children[i]);
/* Do not free n->List since it's a child elsewhere */
-#if !USE_MEMPOOL
- free(n);
-#endif
+ _slang_free(n);
}
{
#if 0
_slang_refcount_storage(n);
- _slang_free_ir(n);
#endif
+ _slang_free_ir(n);
}
slang_label *
_slang_label_new(const char *name)
{
-#if !USE_MEMPOOL
- slang_label *l = (slang_label *) _mesa_calloc(sizeof(slang_label));
-#else
slang_label *l = (slang_label *) _slang_alloc(sizeof(slang_label));
-#endif
if (l) {
-#if !USE_MEMPOOL
- l->Name = _mesa_strdup(name);
-#else
l->Name = _slang_strdup(name);
-#endif
l->Location = -1;
}
return l;
_slang_label_new_unique(const char *name)
{
static int id = 1;
-#if !USE_MEMPOOL
- slang_label *l = (slang_label *) _mesa_calloc(sizeof(slang_label));
-#else
slang_label *l = (slang_label *) _slang_alloc(sizeof(slang_label));
-#endif
if (l) {
-#if !USE_MEMPOOL
- l->Name = (char *) _mesa_malloc(_mesa_strlen(name) + 10);
-#else
l->Name = (char *) _slang_alloc(_mesa_strlen(name) + 10);
-#endif
if (!l->Name) {
_mesa_free(l);
return NULL;
void
_slang_label_delete(slang_label *l)
{
-#if !USE_MEMPOOL
- if (l->Name)
- _mesa_free(l->Name);
- if (l->References)
- _mesa_free(l->References);
- _mesa_free(l);
-#endif
+ if (l->Name) {
+ _slang_free(l->Name);
+ l->Name = NULL;
+ }
+ if (l->References) {
+ _slang_free(l->References);
+ l->References = NULL;
+ }
+ _slang_free(l);
}
{
const GLuint oldSize = l->NumReferences * sizeof(GLuint);
assert(l->Location < 0);
-#if !USE_MEMPOOL
- l->References = _mesa_realloc(l->References,
- oldSize, oldSize + sizeof(GLuint));
-#else
l->References = _slang_realloc(l->References,
oldSize, oldSize + sizeof(GLuint));
-#endif
if (l->References) {
l->References[l->NumReferences] = inst;
l->NumReferences++;
}
if (l->References) {
-#if !USE_MEMPOOL
- _mesa_free(l->References);
-#endif
+ _slang_free(l->References);
l->References = NULL;
}
}
_slang_free(void *addr);
-#define USE_MEMPOOL 1 /* XXX temporary */
-
#endif
{
if (arr->aggregate != NULL) {
slang_storage_aggregate_destruct(arr->aggregate);
-#if USE_MEMPOOL
_slang_free(arr->aggregate);
-#else
- slang_alloc_free(arr->aggregate);
-#endif
}
}
for (i = 0; i < agg->count; i++)
slang_storage_array_destruct(agg->arrays + i);
-#if USE_MEMPOOL
_slang_free(agg->arrays);
-#else
- slang_alloc_free(agg->arrays);
-#endif
}
static slang_storage_array *
slang_storage_array *arr = NULL;
agg->arrays = (slang_storage_array *)
-#if USE_MEMPOOL
_slang_realloc(agg->arrays,
-#else
- slang_alloc_realloc(agg->arrays,
-#endif
- agg->count * sizeof(slang_storage_array),
- (agg->count + 1) * sizeof(slang_storage_array));
+ agg->count * sizeof(slang_storage_array),
+ (agg->count + 1) * sizeof(slang_storage_array));
if (agg->arrays != NULL) {
arr = agg->arrays + agg->count;
if (!slang_storage_array_construct(arr))
return GL_FALSE;
arr->type = SLANG_STORE_AGGREGATE;
arr->length = columns;
- arr->aggregate =
- (slang_storage_aggregate *)
-#if USE_MEMPOOL
+ arr->aggregate = (slang_storage_aggregate *)
_slang_alloc(sizeof(slang_storage_aggregate));
-#else
- slang_alloc_malloc(sizeof(slang_storage_aggregate));
-#endif
if (arr->aggregate == NULL)
return GL_FALSE;
if (!slang_storage_aggregate_construct(arr->aggregate)) {
-#if USE_MEMPOOL
_slang_free(arr->aggregate);
-#else
- slang_alloc_free(arr->aggregate);
-#endif
arr->aggregate = NULL;
return GL_FALSE;
}
if (arr == NULL)
return GL_FALSE;
arr->type = SLANG_STORE_AGGREGATE;
- arr->aggregate =
- (slang_storage_aggregate *)
-#if USE_MEMPOOL
+ arr->aggregate = (slang_storage_aggregate *)
_slang_alloc(sizeof(slang_storage_aggregate));
-#else
- slang_alloc_malloc(sizeof(slang_storage_aggregate));
-#endif
if (arr->aggregate == NULL)
return GL_FALSE;
if (!slang_storage_aggregate_construct(arr->aggregate)) {
-#if USE_MEMPOOL
_slang_free(arr->aggregate);
-#else
- slang_alloc_free(arr->aggregate);
-#endif
arr->aggregate = NULL;
return GL_FALSE;
}
{
if (self->_struct != NULL) {
slang_struct_destruct(self->_struct);
-#if USE_MEMPOOL
_slang_free(self->_struct);
-#else
- slang_alloc_free(self->_struct);
-#endif
}
if (self->_array != NULL) {
slang_type_specifier_dtr(self->_array);
-#if USE_MEMPOOL
_slang_free(self->_array);
-#else
- slang_alloc_free(self->_array);
-#endif
}
}
slang_type_specifier_ctr(&z);
z.type = y->type;
if (z.type == SLANG_SPEC_STRUCT) {
-#if USE_MEMPOOL
z._struct = (slang_struct *) _slang_alloc(sizeof(slang_struct));
-#else
- z._struct = (slang_struct *) slang_alloc_malloc(sizeof(slang_struct));
-#endif
if (z._struct == NULL) {
slang_type_specifier_dtr(&z);
return GL_FALSE;
}
if (!slang_struct_construct(z._struct)) {
-#if USE_MEMPOOL
_slang_free(z._struct);
-#else
- slang_alloc_free(z._struct);
-#endif
slang_type_specifier_dtr(&z);
return GL_FALSE;
}
}
}
else if (z.type == SLANG_SPEC_ARRAY) {
- z._array =
- (slang_type_specifier *)
-#if USE_MEMPOOL
+ z._array = (slang_type_specifier *)
_slang_alloc(sizeof(slang_type_specifier));
-#else
- slang_alloc_malloc(sizeof(slang_type_specifier));
-#endif
if (z._array == NULL) {
slang_type_specifier_dtr(&z);
return GL_FALSE;
/* struct initializer */
ti->spec.type = SLANG_SPEC_STRUCT;
ti->spec._struct =
-#if USE_MEMPOOL
(slang_struct *) _slang_alloc(sizeof(slang_struct));
-#else
- (slang_struct *) slang_alloc_malloc(sizeof(slang_struct));
-#endif
if (ti->spec._struct == NULL)
return GL_FALSE;
if (!slang_struct_construct(ti->spec._struct)) {
-#if USE_MEMPOOL
_slang_free(ti->spec._struct);
-#else
- slang_alloc_free(ti->spec._struct);
-#endif
ti->spec._struct = NULL;
return GL_FALSE;
}
entry = pool->entries[i];
while (entry != NULL) {
- slang_atom_entry *next;
-
- next = entry->next;
-#if USE_MEMPOOL
+ slang_atom_entry *next = entry->next;
_slang_free(entry->id);
_slang_free(entry);
-#else
- slang_alloc_free(entry->id);
- slang_alloc_free(entry);
-#endif
entry = next;
}
}
/* Okay, we have not found an atom. Create a new entry for it.
* Note that the <entry> points to the last entry's <next> field.
*/
-#if USE_MEMPOOL
- *entry = (slang_atom_entry *) (_slang_alloc(sizeof(slang_atom_entry)));
-#else
- *entry = (slang_atom_entry *) (slang_alloc_malloc(sizeof(slang_atom_entry)));
-#endif
+ *entry = (slang_atom_entry *) _slang_alloc(sizeof(slang_atom_entry));
if (*entry == NULL)
return SLANG_ATOM_NULL;
* value.
*/
(**entry).next = NULL;
-#if USE_MEMPOOL
(**entry).id = _slang_strdup(id);
-#else
- (**entry).id = slang_string_duplicate(id);
-#endif
if ((**entry).id == NULL)
return SLANG_ATOM_NULL;
return (slang_atom) (**entry).id;
#ifndef SLANG_UTILITY_H
#define SLANG_UTILITY_H
-#include "slang_mem.h"
-
/* Compile-time assertions. If the expression is zero, try to declare an
* array of size [-1] to cause compilation error.
*/
#define static_assert(expr) do { int _array[(expr) ? 1 : -1]; (void) _array[0]; } while (0)
-#if !USE_MEMPOOL
-#define slang_alloc_free(ptr) _mesa_free (ptr)
-#define slang_alloc_malloc(size) _mesa_malloc (size)
-#define slang_alloc_realloc(ptr, old_size, size) _mesa_realloc (ptr, old_size, size)
-#endif
+
#define slang_string_compare(str1, str2) _mesa_strcmp (str1, str2)
#define slang_string_copy(dst, src) _mesa_strcpy (dst, src)
-#if !USE_MEMPOOL
-#define slang_string_duplicate(src) _mesa_strdup (src)
-#endif
#define slang_string_length(str) _mesa_strlen (str)
char *slang_string_concat (char *, const char *);
#endif
-
_slang_new_var_table(GLuint maxRegisters)
{
slang_var_table *vt
-#if USE_MEMPOOL
= (slang_var_table *) _slang_alloc(sizeof(slang_var_table));
-#else
- = (slang_var_table *) _mesa_calloc(sizeof(slang_var_table));
-#endif
if (vt) {
vt->MaxRegisters = maxRegisters;
}
_mesa_problem(NULL, "non-empty var table in _slang_delete_var_table()");
return;
}
-#if !USE_MEMPOOL
- _mesa_free(vt);
-#endif
+ _slang_free(vt);
}
void
_slang_push_var_table(slang_var_table *vt)
{
-#if USE_MEMPOOL
struct table *t = (struct table *) _slang_alloc(sizeof(struct table));
-#else
- struct table *t = (struct table *) _mesa_calloc(sizeof(struct table));
-#endif
if (t) {
t->Level = vt->CurLevel++;
t->Parent = vt->Top;
}
}
- if (t->Vars)
-#if USE_MEMPOOL
+ if (t->Vars) {
+ _slang_free(t->Vars);
t->Vars = NULL;
-#else
- free(t->Vars);
-#endif
+ }
vt->Top = t->Parent;
-#if !USE_MEMPOOL
- free(t);
-#endif
+ _slang_free(t);
vt->CurLevel--;
}
t = vt->Top;
assert(t);
if (dbg) printf("Adding var %s\n", (char *) v->a_name);
-#if USE_MEMPOOL
- t->Vars =
- (slang_variable **) _slang_realloc(t->Vars,
- t->NumVars * sizeof(slang_variable *),
- (t->NumVars + 1) * sizeof(slang_variable *));
-#else
- t->Vars = realloc(t->Vars, (t->NumVars + 1) * sizeof(slang_variable *));
-#endif
+ t->Vars = (slang_variable **)
+ _slang_realloc(t->Vars,
+ t->NumVars * sizeof(slang_variable *),
+ (t->NumVars + 1) * sizeof(slang_variable *));
t->Vars[t->NumVars] = v;
t->NumVars++;
}