Main Page | Class List | Directories | File List | Class Members | File Members

mapping.h

Go to the documentation of this file.
00001 /*
00002 || This file is part of Pike. For copyright information see COPYRIGHT.
00003 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
00004 || for more information.
00005 || $Id: mapping.h,v 1.60 2005/04/08 16:55:53 grubba Exp $
00006 */
00007 
00008 #ifndef MAPPING_H
00009 #define MAPPING_H
00010 
00011 #include "svalue.h"
00012 #include "dmalloc.h"
00013 #include "block_alloc_h.h"
00014 
00015 /* Compatible with PIKE_WEAK_INDICES and PIKE_WEAK_VALUES. */
00016 #define MAPPING_WEAK_INDICES    2
00017 #define MAPPING_WEAK_VALUES     4
00018 #define MAPPING_WEAK            6
00019 #define MAPPING_FLAG_WEAK       6 /* Compat. */
00020 
00021 struct keypair
00022 {
00023   struct keypair *next;
00024   unsigned INT32 hval;
00025   struct svalue ind, val;
00026 };
00027 
00028 struct mapping_data
00029 {
00030   PIKE_MEMORY_OBJECT_MEMBERS;
00031   INT32 valrefs; /* lock values too */
00032   INT32 hardlinks;
00033   INT32 size, hashsize;
00034   INT32 num_keypairs;
00035   TYPE_FIELD ind_types, val_types;
00036   INT16 flags;
00037   struct keypair *free_list;
00038   struct keypair *hash[1 /* hashsize */ ];
00039   /* struct keypair data_block[ hashsize * AVG_LINK_LENGTH ] */
00040 };
00041 
00042 #undef MAPPING_SIZE_DEBUG
00043 /* This debug doesn't work with weak mappings in the gc. */
00044 
00045 struct mapping
00046 {
00047   PIKE_MEMORY_OBJECT_MEMBERS;
00048 #ifdef MAPPING_SIZE_DEBUG
00049   INT32 debug_size;
00050 #endif
00051   struct mapping_data *data;
00052   struct mapping *next, *prev;
00053 };
00054 
00055 
00056 extern struct mapping *first_mapping;
00057 extern struct mapping *gc_internal_mapping;
00058 
00059 #define map_delete(m,key) map_delete_no_free(m, key, 0)
00060 #define m_sizeof(m) ((m)->data->size)
00061 #define m_ind_types(m) ((m)->data->ind_types)
00062 #define m_val_types(m) ((m)->data->val_types)
00063 #define mapping_get_flags(m) ((m)->data->flags)
00064 #define mapping_data_is_shared(m) ((m)->data->refs > 1)
00065 
00066 #define MD_KEYPAIRS(MD, HSIZE) \
00067    ( (struct keypair *)                                                 \
00068      DO_ALIGN( PTR_TO_INT(((struct mapping_data *)(MD))->hash + HSIZE), \
00069                ALIGNOF(struct keypair)) )
00070 
00071 #ifndef PIKE_MAPPING_KEYPAIR_LOOP
00072 #define NEW_MAPPING_LOOP(md) \
00073   for((e=0) DO_IF_DMALLOC( ?0:(debug_malloc_touch(md)) ) ;e<(md)->hashsize;e++) for(k=(md)->hash[e];k;k=k->next)
00074 
00075 /* WARNING: this should not be used */
00076 #define MAPPING_LOOP(m) \
00077   for((e=0) DO_IF_DMALLOC( ?0:(debug_malloc_touch(m),debug_malloc_touch((m)->data))) ;e<(m)->data->hashsize;e++) for(k=(m)->data->hash[e];k;k=k->next)
00078 
00079 #else /* PIKE_MAPPING_KEYPAIR_LOOP */
00080 
00081 #define NEW_MAPPING_LOOP(md) \
00082   for(((k = MD_KEYPAIRS(md, (md)->hashsize)), e=0) DO_IF_DMALLOC( ?0:(debug_malloc_touch(md)) ) ; e<(md)->size; e++,k++)
00083 
00084 /* WARNING: this should not be used */
00085 #define MAPPING_LOOP(m) \
00086   for(((k = MD_KEYPAIRS((m)->data, (m)->data->hashsize)), e=0) DO_IF_DMALLOC( ?0:(debug_malloc_touch(m),debug_malloc_touch((m)->data)) ) ; e<(m)->data->size; e++,k++)
00087 
00088 #endif /* PIKE_MAPPING_KEYPAIR_LOOP */
00089 
00090 #define free_mapping(M) do{                                             \
00091     struct mapping *m_=(M);                                             \
00092     debug_malloc_touch(m_);                                             \
00093     DO_IF_DEBUG (                                                       \
00094       DO_IF_PIKE_CLEANUP (                                              \
00095         if (gc_external_refs_zapped)                                    \
00096           gc_check_zapped (m_, PIKE_T_MAPPING, __FILE__, __LINE__)));   \
00097     if(!sub_ref(m_))                                                    \
00098       really_free_mapping(m_);                                          \
00099   }while(0)
00100 
00101 #define free_mapping_data(M) do{ \
00102  struct mapping_data *md_=(M); \
00103  debug_malloc_touch(md_); \
00104  if(!sub_ref(md_)) really_free_mapping_data(md_); \
00105  /* FIXME: What about valrefs & hardlinks? */ \
00106 }while(0)
00107 
00108 PMOD_PROTO void really_free_mapping(struct mapping *md);
00109 
00110 /* Prototypes begin here */
00111 BLOCK_ALLOC_FILL_PAGES(mapping, 2);
00112 
00113 
00114 
00115 
00116 
00117 
00118 PMOD_EXPORT struct mapping *debug_allocate_mapping(int size);
00119 PMOD_EXPORT void really_free_mapping_data(struct mapping_data *md);
00120 PMOD_EXPORT void do_free_mapping(struct mapping *m);
00121 struct mapping_data *copy_mapping_data(struct mapping_data *md);
00122 PMOD_EXPORT void mapping_fix_type_field(struct mapping *m);
00123 PMOD_EXPORT void mapping_set_flags(struct mapping *m, int flags);
00124 PMOD_EXPORT void low_mapping_insert(struct mapping *m,
00125                                     const struct svalue *key,
00126                                     const struct svalue *val,
00127                                     int overwrite);
00128 PMOD_EXPORT void mapping_insert(struct mapping *m,
00129                                 const struct svalue *key,
00130                                 const struct svalue *val);
00131 PMOD_EXPORT union anything *mapping_get_item_ptr(struct mapping *m,
00132                                      struct svalue *key,
00133                                      TYPE_T t);
00134 PMOD_EXPORT void map_delete_no_free(struct mapping *m,
00135                         struct svalue *key,
00136                         struct svalue *to);
00137 PMOD_EXPORT void check_mapping_for_destruct(struct mapping *m);
00138 PMOD_EXPORT struct svalue *low_mapping_lookup(struct mapping *m,
00139                                               const struct svalue *key);
00140 PMOD_EXPORT struct svalue *low_mapping_string_lookup(struct mapping *m,
00141                                          struct pike_string *p);
00142 PMOD_EXPORT void mapping_string_insert(struct mapping *m,
00143                            struct pike_string *p,
00144                            struct svalue *val);
00145 PMOD_EXPORT void mapping_string_insert_string(struct mapping *m,
00146                                   struct pike_string *p,
00147                                   struct pike_string *val);
00148 PMOD_EXPORT struct svalue *simple_mapping_string_lookup(struct mapping *m,
00149                                                         const char *p);
00150 PMOD_EXPORT struct svalue *mapping_mapping_lookup(struct mapping *m,
00151                                       struct svalue *key1,
00152                                       struct svalue *key2,
00153                                       int create);
00154 PMOD_EXPORT struct svalue *mapping_mapping_string_lookup(struct mapping *m,
00155                                       struct pike_string *key1,
00156                                       struct pike_string *key2,
00157                                       int create);
00158 PMOD_EXPORT void mapping_index_no_free(struct svalue *dest,
00159                            struct mapping *m,
00160                            struct svalue *key);
00161 PMOD_EXPORT struct array *mapping_indices(struct mapping *m);
00162 PMOD_EXPORT struct array *mapping_values(struct mapping *m);
00163 PMOD_EXPORT struct array *mapping_to_array(struct mapping *m);
00164 PMOD_EXPORT void mapping_replace(struct mapping *m,struct svalue *from, struct svalue *to);
00165 PMOD_EXPORT struct mapping *mkmapping(struct array *ind, struct array *val);
00166 PMOD_EXPORT struct mapping *copy_mapping(struct mapping *m);
00167 PMOD_EXPORT struct mapping *copy_mapping(struct mapping *m);
00168 PMOD_EXPORT struct mapping *merge_mappings(struct mapping *a, struct mapping *b, INT32 op);
00169 PMOD_EXPORT struct mapping *merge_mapping_array_ordered(struct mapping *a, 
00170                                             struct array *b, INT32 op);
00171 PMOD_EXPORT struct mapping *merge_mapping_array_unordered(struct mapping *a, 
00172                                               struct array *b, INT32 op);
00173 PMOD_EXPORT struct mapping *add_mappings(struct svalue *argp, INT32 args);
00174 PMOD_EXPORT int mapping_equal_p(struct mapping *a, struct mapping *b, struct processing *p);
00175 void describe_mapping(struct mapping *m,struct processing *p,int indent);
00176 node *make_node_from_mapping(struct mapping *m);
00177 PMOD_EXPORT void f_aggregate_mapping(INT32 args);
00178 PMOD_EXPORT struct mapping *copy_mapping_recursively(struct mapping *m,
00179                                                      struct mapping *p);
00180 PMOD_EXPORT void mapping_search_no_free(struct svalue *to,
00181                             struct mapping *m,
00182                             struct svalue *look_for,
00183                             struct svalue *key );
00184 void check_mapping(struct mapping *m);
00185 void check_all_mappings(void);
00186 void gc_mark_mapping_as_referenced(struct mapping *m);
00187 void real_gc_cycle_check_mapping(struct mapping *m, int weak);
00188 unsigned gc_touch_all_mappings(void);
00189 void gc_check_all_mappings(void);
00190 void gc_mark_all_mappings(void);
00191 void gc_cycle_check_all_mappings(void);
00192 void gc_zap_ext_weak_refs_in_mappings(void);
00193 size_t gc_free_all_unreferenced_mappings(void);
00194 void simple_describe_mapping(struct mapping *m);
00195 void debug_dump_mapping(struct mapping *m);
00196 int mapping_is_constant(struct mapping *m,
00197                         struct processing *p);
00198 /* Prototypes end here */
00199 
00200 #define allocate_mapping(X) dmalloc_touch(struct mapping *,debug_allocate_mapping(X))
00201 
00202 #define gc_cycle_check_mapping(X, WEAK) \
00203   gc_cycle_enqueue((gc_cycle_check_cb *) real_gc_cycle_check_mapping, (X), (WEAK))
00204 
00205 #endif /* MAPPING_H */

Generated on Fri Jul 22 23:44:26 2005 for Pike by  doxygen 1.3.9.1