Select Git revision
array.c 41.60 KiB
/*\
||| This file a part of uLPC, and is copyright by Fredrik Hubinette
||| uLPC is distributed as GPL (General Public License)
||| See the files COPYING and DISCLAIMER for more information.
\*/
#include "global.h"
#include "svalue.h"
#include "array.h"
#include "object.h"
#include "las.h"
#include "stralloc.h"
#include "interpret.h"
#include "language.h"
#include "error.h"
#include "lpc_types.h"
#include "fsort.h"
#include "builtin_efuns.h"
#include "memory.h"
struct array empty_array=
{
1, /* Never free */
&empty_array, /* Next */
&empty_array, /* previous (circular) */
0, /* Size = 0 */
0, /* malloced Size = 0 */
0, /* no types */
T_MIXED, /* mixed array */
0, /* no flags */
};
/* Allocate an array, this might be changed in the future to
* allocate linked lists or something
* NOTE: the new array have zero references
*/
struct array *allocate_array_no_init(INT32 size,INT32 extra_space,TYPE_T type)
{
struct array *v;
if(size == 0 && type == T_MIXED)
{
empty_array.refs++;
return &empty_array;
}
if(type == T_FUNCTION || type == T_MIXED)
{
v=(struct array *)malloc(sizeof(struct array_of_svalues)+
(size+extra_space-1)*sizeof(struct svalue));
if(!v)
error("Couldn't allocate array, out of memory.\n");
v->array_type=T_MIXED;
/* for now, we don't know what will go in here */
v->type_field=BIT_MIXED;
}else{
v=(struct array *)malloc(sizeof(struct array_of_short_svalues)+
(size+extra_space-1)*sizeof(union anything));
if(!v)
error("Couldn't allocate array, out of memory.\n");
v->array_type=type;
/* This array can only contain zeros and 'type' */
v->type_field=BIT_INT | (1 << type);
}
v->malloced_size=size+extra_space;
v->size=size;
v->flags=0;
v->refs=1;