Select Git revision
array.h 14.45 KiB
/*
|| This file is part of Pike. For copyright information see COPYRIGHT.
|| Pike is distributed under GPL, LGPL and MPL. See the file COPYING
|| for more information.
*/
#ifndef ARRAY_H
#define ARRAY_H
#include "svalue.h"
#include "dmalloc.h"
/* This debug tool writes out messages whenever arrays with unfinished
* type fields are encountered. */
/* #define TRACE_UNFINISHED_TYPE_FIELDS */
/**
* A Pike array is represented as a 'struct array' with all the
* needed svalues malloced in the same block.
*
* @see type_field
*/
struct array
{
PIKE_MEMORY_OBJECT_MEMBERS;
struct array *next; /**< we need to keep track of all arrays */
struct array *prev; /**< Another pointer, so we don't have to search
* when freeing arrays */
INT32 size; /**< number of svalues in this array */
INT32 malloced_size; /**< number of svalues that can fit in this array */
TYPE_FIELD type_field;/**< A bitfield with one bit for each type of
* data in this array.
Bits can be set that don't exist in the array. type_field is
* initialized to BIT_MIXED|BIT_UNFINISHED for newly allocated
* arrays so that they can be modified without having to update
* this. It should be set accurately when that's done, though. */
INT16 flags; /**< ARRAY_* flags */
struct svalue *item; /**< the array of svalues */
struct svalue real_item[1];
};
#define ARRAY_WEAK_FLAG 1
#define ARRAY_CYCLIC 2
#define ARRAY_LVALUE 4
PMOD_EXPORT extern struct array empty_array, weak_empty_array;
extern struct array *first_array;
extern struct array *gc_internal_array;
#if defined(DEBUG_MALLOC) && defined(PIKE_DEBUG)
#define ITEM(X) (((struct array *)(debug_malloc_pass((X))))->item)
#else
#define ITEM(X) ((X)->item)
#endif
/* These are arguments for the function 'merge' which merges two sorted
* set stored in arrays in the way you specify
*/
#define PIKE_ARRAY_OP_A 1
#define PIKE_ARRAY_OP_SKIP_A 2
#define PIKE_ARRAY_OP_TAKE_A 3
#define PIKE_ARRAY_OP_B 4
#define PIKE_ARRAY_OP_SKIP_B 8
#define PIKE_ARRAY_OP_TAKE_B 12
#define PIKE_MINTERM(X,Y,Z) (((X)<<8)+((Y)<<4)+(Z))
#define PIKE_ARRAY_OP_AND PIKE_MINTERM(PIKE_ARRAY_OP_SKIP_A,PIKE_ARRAY_OP_SKIP_A | PIKE_ARRAY_OP_TAKE_B,PIKE_ARRAY_OP_SKIP_B)
#define PIKE_ARRAY_OP_AND_LEFT PIKE_MINTERM(PIKE_ARRAY_OP_SKIP_A,PIKE_ARRAY_OP_SKIP_B | PIKE_ARRAY_OP_TAKE_A,PIKE_ARRAY_OP_SKIP_B)
#define PIKE_ARRAY_OP_OR PIKE_MINTERM(PIKE_ARRAY_OP_TAKE_A,PIKE_ARRAY_OP_SKIP_A | PIKE_ARRAY_OP_TAKE_B,PIKE_ARRAY_OP_TAKE_B)