cb22561995-10-11Fredrik Hübinette (Hubbe) /*\
06983f1996-09-22Fredrik Hübinette (Hubbe) ||| This file a part of Pike, and is copyright by Fredrik Hubinette ||| Pike is distributed as GPL (General Public License)
cb22561995-10-11Fredrik Hübinette (Hubbe) ||| See the files COPYING and DISCLAIMER for more information. \*/
24ddc71998-03-28Henrik Grubbström (Grubba)  /*
e2d9e62000-06-10Martin Stjernholm  * $Id: array.h,v 1.20 2000/06/09 22:43:04 mast Exp $
24ddc71998-03-28Henrik Grubbström (Grubba)  */
5267b71995-08-09Fredrik Hübinette (Hubbe) #ifndef ARRAY_H #define ARRAY_H #include "las.h" struct array { INT32 refs; /* Reference count */
7e97c31999-01-21Fredrik Hübinette (Hubbe) #ifdef PIKE_SECURITY struct object *prot; #endif
5267b71995-08-09Fredrik Hübinette (Hubbe)  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 items in this array */ INT32 malloced_size; /* number of elements that can fit in this array */ TYPE_FIELD type_field;/* A bitfield with one bit for each type. * Bits can be set that don't exist in the array * though. */
fc33451997-10-02Fredrik Hübinette (Hubbe)  INT16 flags; /* ARRAY_* flags */
5267b71995-08-09Fredrik Hübinette (Hubbe)  struct svalue item[1]; };
5f06241999-04-11Fredrik Hübinette (Hubbe) #define ARRAY_WEAK_FLAG 1 #define ARRAY_CYCLIC 2 #define ARRAY_LVALUE 4 #define ARRAY_WEAK_SHRINK 8
5267b71995-08-09Fredrik Hübinette (Hubbe) 
c94c371996-03-28Fredrik Hübinette (Hubbe) extern struct array empty_array;
e2d9e62000-06-10Martin Stjernholm extern struct array *gc_internal_array;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
71f3a21998-11-22Fredrik Hübinette (Hubbe) #if defined(DEBUG_MALLOC) && defined(PIKE_DEBUG)
aa366d1998-04-16Fredrik Hübinette (Hubbe) #define ITEM(X) (((struct array *)(debug_malloc_pass((X))))->item) #else
fc76951996-02-17Fredrik Hübinette (Hubbe) #define ITEM(X) ((X)->item)
aa366d1998-04-16Fredrik Hübinette (Hubbe) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe) 
e2d9e62000-06-10Martin Stjernholm #define LINK_ARRAY(a) do { \ (a)->prev = &empty_array; \ (a)->next = empty_array.next; \ empty_array.next = (a); \ (a)->next->prev = (a); \ } while (0) #define UNLINK_ARRAY(a) do { \ struct array *next = (a)->next, *prev = (a)->prev; \ prev->next = next; \ next->prev = prev; \ } while (0)
5267b71995-08-09Fredrik Hübinette (Hubbe) /* These are arguments for the function 'merge' which merges two sorted * set stored in arrays in the way you specify */
71f3a21998-11-22Fredrik Hübinette (Hubbe) #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))
5267b71995-08-09Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe) 
a3c6ad1998-01-29Fredrik Hübinette (Hubbe) #define free_array(V) do{ struct array *v_=(V); debug_malloc_touch(v_); if(!--v_->refs) really_free_array(v_); }while(0)
5267b71995-08-09Fredrik Hübinette (Hubbe) 
2a129b1996-03-24Fredrik Hübinette (Hubbe) #define allocate_array(X) low_allocate_array((X),0) #define allocate_array_no_init(X,Y) low_allocate_array((X),(Y))
5267b71995-08-09Fredrik Hübinette (Hubbe)  typedef int (*cmpfun)(struct svalue *,struct svalue *); typedef int (*short_cmpfun)(union anything *, union anything *); typedef short_cmpfun (*cmpfun_getter)(TYPE_T); /* Prototypes begin here */
2a129b1996-03-24Fredrik Hübinette (Hubbe) struct array *low_allocate_array(INT32 size,INT32 extra_space);
5267b71995-08-09Fredrik Hübinette (Hubbe) void really_free_array(struct array *v);
2a32691998-01-31Fredrik Hübinette (Hubbe) void do_free_array(struct array *a);
5267b71995-08-09Fredrik Hübinette (Hubbe) void array_index_no_free(struct svalue *s,struct array *v,INT32 index); void array_index(struct svalue *s,struct array *v,INT32 index);
61e9a01998-01-25Fredrik Hübinette (Hubbe) void simple_array_index_no_free(struct svalue *s, struct array *a,struct svalue *ind);
5267b71995-08-09Fredrik Hübinette (Hubbe) void array_free_index(struct array *v,INT32 index); void array_set_index(struct array *v,INT32 index, struct svalue *s); void simple_set_index(struct array *a,struct svalue *ind,struct svalue *s); struct array *array_insert(struct array *v,struct svalue *s,INT32 index);
9649491998-02-27Fredrik Hübinette (Hubbe) struct array *resize_array(struct array *a, INT32 size);
5267b71995-08-09Fredrik Hübinette (Hubbe) struct array *array_shrink(struct array *v,INT32 size); struct array *array_remove(struct array *v,INT32 index); INT32 array_search(struct array *v, struct svalue *s,INT32 start); struct array *slice_array(struct array *v,INT32 start,INT32 end);
0e124e1998-02-19Fredrik Hübinette (Hubbe) struct array *friendly_slice_array(struct array *v,INT32 start,INT32 end);
5267b71995-08-09Fredrik Hübinette (Hubbe) struct array *copy_array(struct array *v); void check_array_for_destruct(struct array *v); INT32 array_find_destructed_object(struct array *v);
99946c1996-02-17Fredrik Hübinette (Hubbe) INT32 *get_order(struct array *v, cmpfun fun);
f5f7b11996-06-21Fredrik Hübinette (Hubbe) void sort_array_destructively(struct array *v);
5267b71995-08-09Fredrik Hübinette (Hubbe) INT32 *get_set_order(struct array *a); INT32 *get_switch_order(struct array *a);
71b72b1996-06-09Fredrik Hübinette (Hubbe) INT32 *get_alpha_order(struct array *a);
5267b71995-08-09Fredrik Hübinette (Hubbe) INT32 set_lookup(struct array *a, struct svalue *s); INT32 switch_lookup(struct array *a, struct svalue *s); struct array *order_array(struct array *v, INT32 *order); struct array *reorder_and_copy_array(struct array *v, INT32 *order); void array_fix_type_field(struct array *v);
e3c6e11996-05-16Fredrik Hübinette (Hubbe) void array_check_type_field(struct array *v);
5267b71995-08-09Fredrik Hübinette (Hubbe) struct array *compact_array(struct array *v); union anything *low_array_get_item_ptr(struct array *a, INT32 ind, TYPE_T t); union anything *array_get_item_ptr(struct array *a, struct svalue *ind, TYPE_T t); INT32 * merge(struct array *a,struct array *b,INT32 opcode); struct array *array_zip(struct array *a, struct array *b,INT32 *zipper); struct array *add_arrays(struct svalue *argp, INT32 args); int array_equal_p(struct array *a, struct array *b, struct processing *p); struct array *merge_array_with_order(struct array *a, struct array *b,INT32 op);
6ba8fa1999-03-05Fredrik Hübinette (Hubbe) struct array *merge_array_without_order2(struct array *a, struct array *b,INT32 op);
5267b71995-08-09Fredrik Hübinette (Hubbe) struct array *merge_array_without_order(struct array *a, struct array *b, INT32 op); struct array *subtract_arrays(struct array *a, struct array *b); struct array *and_arrays(struct array *a, struct array *b); int check_that_array_is_constant(struct array *a); node *make_node_from_array(struct array *a); void push_array_items(struct array *a); void describe_array_low(struct array *a, struct processing *p, int indent); void simple_describe_array(struct array *a); void describe_index(struct array *a, int e, struct processing *p, int indent); void describe_array(struct array *a,struct processing *p,int indent);
99946c1996-02-17Fredrik Hübinette (Hubbe) struct array *aggregate_array(INT32 args);
9649491998-02-27Fredrik Hübinette (Hubbe) struct array *append_array(struct array *a, struct svalue *s);
06983f1996-09-22Fredrik Hübinette (Hubbe) struct array *explode(struct pike_string *str, struct pike_string *del); struct pike_string *implode(struct array *a,struct pike_string *del);
5267b71995-08-09Fredrik Hübinette (Hubbe) struct array *copy_array_recursively(struct array *a,struct processing *p); void apply_array(struct array *a, INT32 args); struct array *reverse_array(struct array *a); void array_replace(struct array *a, struct svalue *from, struct svalue *to);
624d091996-02-24Fredrik Hübinette (Hubbe) void check_array(struct array *a);
be478c1997-08-30Henrik Grubbström (Grubba) void check_all_arrays(void);
c94c371996-03-28Fredrik Hübinette (Hubbe) void gc_mark_array_as_referenced(struct array *a);
e2d9e62000-06-10Martin Stjernholm unsigned gc_touch_all_arrays(void);
be478c1997-08-30Henrik Grubbström (Grubba) void gc_check_all_arrays(void); void gc_mark_all_arrays(void);
e2d9e62000-06-10Martin Stjernholm void real_gc_cycle_check_array(struct array *a); void real_gc_cycle_check_array_weak(struct array *a); void gc_cycle_check_all_arrays(void);
be478c1997-08-30Henrik Grubbström (Grubba) void gc_free_all_unreferenced_arrays(void);
c3c7031996-12-04Fredrik Hübinette (Hubbe) void debug_dump_type_field(TYPE_FIELD t); void debug_dump_array(struct array *a);
be478c1997-08-30Henrik Grubbström (Grubba) void zap_all_arrays(void);
c3c7031996-12-04Fredrik Hübinette (Hubbe) void count_memory_in_arrays(INT32 *num_, INT32 *size_);
f5466b1997-02-18Fredrik Hübinette (Hubbe) struct array *explode_array(struct array *a, struct array *b); struct array *implode_array(struct array *a, struct array *b);
5267b71995-08-09Fredrik Hübinette (Hubbe) /* Prototypes end here */
e2d9e62000-06-10Martin Stjernholm #define gc_cycle_check_array(X) \ enqueue_lifo(&gc_mark_queue, (queue_call) real_gc_cycle_check_array, (X)) #define gc_cycle_check_array_weak(X) \ enqueue_lifo(&gc_mark_queue, (queue_call) real_gc_cycle_check_array_weak, (X))
5267b71995-08-09Fredrik Hübinette (Hubbe) 
e2d9e62000-06-10Martin Stjernholm #endif /* ARRAY_H */