Mercurial > hg > xemacs-beta
comparison src/lrecord.h @ 5169:6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
-------------------- ChangeLog entries follow: --------------------
src/ChangeLog addition:
2010-03-24 Ben Wing <ben@xemacs.org>
* array.h:
* array.h (XD_LISP_DYNARR_DESC):
* dumper.c (pdump_register_sub):
* dumper.c (pdump_store_new_pointer_offsets):
* dumper.c (pdump_reloc_one_mc):
* elhash.c:
* gc.c (lispdesc_one_description_line_size):
* gc.c (kkcc_marking):
* lrecord.h:
* lrecord.h (IF_NEW_GC):
* lrecord.h (enum memory_description_type):
* lrecord.h (enum data_description_entry_flags):
* lrecord.h (struct opaque_convert_functions):
Rename XD_LISP_OBJECT_BLOCK_PTR to XD_INLINE_LISP_OBJECT_BLOCK_PTR
and document it in lrecord.h.
* data.c:
* data.c (finish_marking_weak_lists):
* data.c (continue_marking_ephemerons):
* data.c (finish_marking_ephemerons):
* elhash.c (MARK_OBJ):
* gc.c:
* gc.c (lispdesc_indirect_count_1):
* gc.c (struct):
* gc.c (kkcc_bt_push):
* gc.c (kkcc_gc_stack_push):
* gc.c (kkcc_gc_stack_push_lisp_object):
* gc.c (kkcc_gc_stack_repush_dirty_object):
* gc.c (KKCC_DO_CHECK_FREE):
* gc.c (mark_object_maybe_checking_free):
* gc.c (mark_struct_contents):
* gc.c (mark_lisp_object_block_contents):
* gc.c (register_for_finalization):
* gc.c (mark_object):
* gc.h:
* lisp.h:
* profile.c:
* profile.c (mark_profiling_info_maphash):
Clean up KKCC code related to DEBUG_XEMACS. Rename
kkcc_backtrace() to kkcc_backtrace_1() and add two params: a
`size' arg to control how many stack elements to print and a
`detailed' arg to control whether Lisp objects are printed using
`debug_print()'. Create front-ends to kkcc_backtrace_1() --
kkcc_detailed_backtrace(), kkcc_short_backtrace(),
kkcc_detailed_backtrace_full(), kkcc_short_backtrace_full(), as
well as shortened versions kbt(), kbts(), kbtf(), kbtsf() -- to
call it with various parameter values. Add an `is_lisp' field to
the stack and backtrace structures and use it to keep track of
whether an object pushed onto the stack is a Lisp object or a
non-Lisp structure; in kkcc_backtrace_1(), don't try to print a
non-Lisp structure as a Lisp object.
* elhash.c:
* extents.c:
* file-coding.c:
* lrecord.h:
* lrecord.h (IF_NEW_GC):
* marker.c:
* marker.c (Fmarker_buffer):
* mule-coding.c:
* number.c:
* rangetab.c:
* specifier.c:
New macros IF_OLD_GC(), IF_NEW_GC() to simplify declaration of
Lisp objects when a finalizer may exist in one but not the other.
Use them appropriately.
* extents.c (finalize_extent_info):
Don't zero out data->soe and data->extents before trying to free,
else we get memory leaks.
* lrecord.h (enum lrecord_type):
Make the first lrecord type have value 1 not 0 so that 0 remains
without implementation and attempts to interpret zeroed memory
as a Lisp object will be more obvious.
* array.c (Dynarr_free):
* device-msw.c (msprinter_delete_device):
* device-tty.c (free_tty_device_struct):
* device-tty.c (tty_delete_device):
* dialog-msw.c (handle_directory_dialog_box):
* dialog-x.c:
* emacs.c (free_argc_argv):
* emodules.c (attempt_module_delete):
* file-coding.c (chain_finalize_coding_stream_1):
* file-coding.c (chain_finalize_coding_stream):
* glyphs-eimage.c:
* glyphs-eimage.c (jpeg_instantiate_unwind):
* glyphs-eimage.c (gif_instantiate_unwind):
* glyphs-eimage.c (png_instantiate_unwind):
* glyphs-eimage.c (tiff_instantiate_unwind):
* imgproc.c:
* imgproc.c (build_EImage_quantable):
* insdel.c (uninit_buffer_text):
* mule-coding.c (iso2022_finalize_detection_state):
* objects-tty.c (tty_finalize_color_instance):
* objects-tty.c (tty_finalize_font_instance):
* objects-tty.c (tty_font_list):
* process.c:
* process.c (finalize_process):
* redisplay.c (add_propagation_runes):
* scrollbar-gtk.c:
* scrollbar-gtk.c (gtk_free_scrollbar_instance):
* scrollbar-gtk.c (gtk_release_scrollbar_instance):
* scrollbar-msw.c:
* scrollbar-msw.c (mswindows_free_scrollbar_instance):
* scrollbar-msw.c (unshow_that_mofo):
* scrollbar-x.c (x_free_scrollbar_instance):
* scrollbar-x.c (x_release_scrollbar_instance):
* select-x.c:
* select-x.c (x_handle_selection_request):
* syntax.c:
* syntax.c (uninit_buffer_syntax_cache):
* text.h (eifree):
If possible, whenever we call xfree() on a field in a structure,
set the field to 0 afterwards. A lot of code is written so that
it checks the value being freed to see if it is non-zero before
freeing it -- doing this and setting the value to 0 afterwards
ensures (a) we won't try to free twice if the cleanup code is
called twice; (b) if the object itself stays around, KKCC won't
crash when attempting to mark the freed field.
* rangetab.c:
Add a finalization method when not NEW_GC to avoid memory leaks.
(#### We still get memory leaks when NEW_GC; need to convert gap
array to Lisp object).
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 24 Mar 2010 01:22:51 -0500 |
parents | ab9ee10a53e4 |
children | 5ddbab03b0e6 |
comparison
equal
deleted
inserted
replaced
5168:cf900a2f1fa3 | 5169:6c6d78781d59 |
---|---|
185 #define ALLOC_SIZED_LISP_OBJECT(size, type) \ | 185 #define ALLOC_SIZED_LISP_OBJECT(size, type) \ |
186 alloc_sized_lrecord (size, &lrecord_##type) | 186 alloc_sized_lrecord (size, &lrecord_##type) |
187 #define NORMAL_LISP_OBJECT_HEADER struct lrecord_header | 187 #define NORMAL_LISP_OBJECT_HEADER struct lrecord_header |
188 #define FROB_BLOCK_LISP_OBJECT_HEADER struct lrecord_header | 188 #define FROB_BLOCK_LISP_OBJECT_HEADER struct lrecord_header |
189 #define LISP_OBJECT_FROB_BLOCK_P(obj) 0 | 189 #define LISP_OBJECT_FROB_BLOCK_P(obj) 0 |
190 #define IF_NEW_GC(x) x | |
191 #define IF_OLD_GC(x) 0 | |
190 #else /* not NEW_GC */ | 192 #else /* not NEW_GC */ |
191 #define ALLOC_NORMAL_LISP_OBJECT(type) alloc_automanaged_lcrecord (&lrecord_##type) | 193 #define ALLOC_NORMAL_LISP_OBJECT(type) alloc_automanaged_lcrecord (&lrecord_##type) |
192 #define ALLOC_SIZED_LISP_OBJECT(size, type) \ | 194 #define ALLOC_SIZED_LISP_OBJECT(size, type) \ |
193 old_alloc_sized_lcrecord (size, &lrecord_##type) | 195 old_alloc_sized_lcrecord (size, &lrecord_##type) |
194 #define NORMAL_LISP_OBJECT_HEADER struct old_lcrecord_header | 196 #define NORMAL_LISP_OBJECT_HEADER struct old_lcrecord_header |
195 #define FROB_BLOCK_LISP_OBJECT_HEADER struct lrecord_header | 197 #define FROB_BLOCK_LISP_OBJECT_HEADER struct lrecord_header |
196 #define LISP_OBJECT_FROB_BLOCK_P(obj) (XRECORD_LHEADER_IMPLEMENTATION(obj)->frob_block_p) | 198 #define LISP_OBJECT_FROB_BLOCK_P(obj) (XRECORD_LHEADER_IMPLEMENTATION(obj)->frob_block_p) |
199 #define IF_NEW_GC(x) 0 | |
200 #define IF_OLD_GC(x) x | |
197 #endif /* not NEW_GC */ | 201 #endif /* not NEW_GC */ |
198 | 202 |
199 #define LISP_OBJECT_UID(obj) (XRECORD_LHEADER (obj)->uid) | 203 #define LISP_OBJECT_UID(obj) (XRECORD_LHEADER (obj)->uid) |
200 | 204 |
201 BEGIN_C_DECLS | 205 BEGIN_C_DECLS |
308 enum lrecord_type | 312 enum lrecord_type |
309 { | 313 { |
310 /* Symbol value magic types come first to make SYMBOL_VALUE_MAGIC_P fast. | 314 /* Symbol value magic types come first to make SYMBOL_VALUE_MAGIC_P fast. |
311 #### This should be replaced by a symbol_value_magic_p flag | 315 #### This should be replaced by a symbol_value_magic_p flag |
312 in the Lisp_Symbol lrecord_header. */ | 316 in the Lisp_Symbol lrecord_header. */ |
313 lrecord_type_symbol_value_forward, /* 0 */ | 317 /* Don't assign any type to 0, so in case we come across zeroed memory |
318 it will be more obvious when printed */ | |
319 lrecord_type_symbol_value_forward = 1, | |
314 lrecord_type_symbol_value_varalias, | 320 lrecord_type_symbol_value_varalias, |
315 lrecord_type_symbol_value_lisp_magic, | 321 lrecord_type_symbol_value_lisp_magic, |
316 lrecord_type_symbol_value_buffer_local, | 322 lrecord_type_symbol_value_buffer_local, |
317 lrecord_type_max_symbol_value_magic = lrecord_type_symbol_value_buffer_local, | 323 lrecord_type_max_symbol_value_magic = lrecord_type_symbol_value_buffer_local, |
318 lrecord_type_symbol, | 324 lrecord_type_symbol, |
972 The existing types : | 978 The existing types : |
973 | 979 |
974 | 980 |
975 XD_LISP_OBJECT | 981 XD_LISP_OBJECT |
976 | 982 |
977 A Lisp object. This is also the type to use for pointers to other lrecords | 983 A Lisp_Object. This is also the type to use for pointers to other lrecords |
978 (e.g. struct frame *). | 984 (e.g. struct frame *). |
979 | 985 |
980 XD_LISP_OBJECT_ARRAY | 986 XD_LISP_OBJECT_ARRAY |
981 | 987 |
982 An array of Lisp objects or (equivalently) pointers to lrecords. | 988 An array of Lisp_Objects or (equivalently) pointers to lrecords. |
983 The parameter (i.e. third element) is the count. This would be declared | 989 The parameter (i.e. third element) is the count. This would be declared |
984 as Lisp_Object foo[666]. For something declared as Lisp_Object *foo, | 990 as Lisp_Object foo[666]. For something declared as Lisp_Object *foo, |
985 use XD_BLOCK_PTR, whose description parameter is a sized_memory_description | 991 use XD_BLOCK_PTR, whose description parameter is a sized_memory_description |
986 consisting of only XD_LISP_OBJECT and XD_END. | 992 consisting of only XD_LISP_OBJECT and XD_END. |
993 | |
994 XD_INLINE_LISP_OBJECT_BLOCK_PTR | |
995 | |
996 An pointer to a contiguous block of inline Lisp objects -- i.e., the Lisp | |
997 object itself rather than a Lisp_Object pointer is stored in the block. | |
998 This is used only under NEW_GC and is useful for increased efficiency when | |
999 an array of the same kind of object is needed. Examples of the use of this | |
1000 type are Lisp dynarrs, where the array elements are inline Lisp objects | |
1001 rather than non-Lisp structures, as is normally the case; and hash tables, | |
1002 where the key/value pairs are encapsulated as hash-table-entry objects and | |
1003 an array of inline hash-table-entry objects is stored. | |
987 | 1004 |
988 XD_LO_LINK | 1005 XD_LO_LINK |
989 | 1006 |
990 Weak link in a linked list of objects of the same type. This is a | 1007 Weak link in a linked list of objects of the same type. This is a |
991 link that does NOT generate a GC reference. Thus the pdumper will | 1008 link that does NOT generate a GC reference. Thus the pdumper will |
1148 enum memory_description_type | 1165 enum memory_description_type |
1149 { | 1166 { |
1150 XD_LISP_OBJECT_ARRAY, | 1167 XD_LISP_OBJECT_ARRAY, |
1151 XD_LISP_OBJECT, | 1168 XD_LISP_OBJECT, |
1152 #ifdef NEW_GC | 1169 #ifdef NEW_GC |
1153 XD_LISP_OBJECT_BLOCK_PTR, | 1170 XD_INLINE_LISP_OBJECT_BLOCK_PTR, |
1154 #endif /* NEW_GC */ | 1171 #endif /* NEW_GC */ |
1155 XD_LO_LINK, | 1172 XD_LO_LINK, |
1156 XD_OPAQUE_PTR, | 1173 XD_OPAQUE_PTR, |
1157 XD_OPAQUE_PTR_CONVERTIBLE, | 1174 XD_OPAQUE_PTR_CONVERTIBLE, |
1158 XD_OPAQUE_DATA_CONVERTIBLE, | 1175 XD_OPAQUE_DATA_CONVERTIBLE, |
1198 /* Indicates that this is a free Lisp object we're marking. | 1215 /* Indicates that this is a free Lisp object we're marking. |
1199 Only relevant for ERROR_CHECK_GC. This occurs when we're marking | 1216 Only relevant for ERROR_CHECK_GC. This occurs when we're marking |
1200 lcrecord-lists, where the objects have had their type changed to | 1217 lcrecord-lists, where the objects have had their type changed to |
1201 lrecord_type_free and also have had their free bit set, but we mark | 1218 lrecord_type_free and also have had their free bit set, but we mark |
1202 them as normal. */ | 1219 them as normal. */ |
1203 XD_FLAG_FREE_LISP_OBJECT = 8 | 1220 XD_FLAG_FREE_LISP_OBJECT = 8, |
1204 #endif /* not NEW_GC */ | 1221 #endif /* not NEW_GC */ |
1205 #if 0 | 1222 #if 0 |
1206 , | |
1207 /* Suggestions for other possible flags: */ | 1223 /* Suggestions for other possible flags: */ |
1208 | 1224 |
1209 /* Eliminate XD_UNION_DYNAMIC_SIZE and replace it with a flag, like this. */ | 1225 /* Eliminate XD_UNION_DYNAMIC_SIZE and replace it with a flag, like this. */ |
1210 XD_FLAG_UNION_DYNAMIC_SIZE = 16, | 1226 XD_FLAG_UNION_DYNAMIC_SIZE = 16, |
1211 /* Require that everyone who uses a description map has to flag it, so | 1227 /* Require that everyone who uses a description map has to flag it, so |
1213 description maps are and who's using them. This might also become | 1229 description maps are and who's using them. This might also become |
1214 necessary if for some reason the format of the description map is | 1230 necessary if for some reason the format of the description map is |
1215 expanded and we need to stick a pointer in the second slot (although | 1231 expanded and we need to stick a pointer in the second slot (although |
1216 we could still ensure that the second slot in the first entry was NULL | 1232 we could still ensure that the second slot in the first entry was NULL |
1217 or <0). */ | 1233 or <0). */ |
1218 XD_FLAG_DESCRIPTION_MAP = 32 | 1234 XD_FLAG_DESCRIPTION_MAP = 32, |
1219 #endif | 1235 #endif |
1220 }; | 1236 }; |
1221 | 1237 |
1222 union memory_contents_description | 1238 union memory_contents_description |
1223 { | 1239 { |
1256 because they contain pointers. This is called at dump time to | 1272 because they contain pointers. This is called at dump time to |
1257 convert to an opaque, pointer-less representation. | 1273 convert to an opaque, pointer-less representation. |
1258 | 1274 |
1259 This function must put a pointer to the opaque result in *data | 1275 This function must put a pointer to the opaque result in *data |
1260 and its size in *size. */ | 1276 and its size in *size. */ |
1261 void (*convert)(const void *object, void **data, Bytecount *size); | 1277 void (*convert) (const void *object, void **data, Bytecount *size); |
1262 | 1278 |
1263 /* Post-conversion cleanup. Optional (null if not provided). | 1279 /* Post-conversion cleanup. Optional (null if not provided). |
1264 | 1280 |
1265 When provided it will be called post-dumping to free any storage | 1281 When provided it will be called post-dumping to free any storage |
1266 allocated for the conversion results. */ | 1282 allocated for the conversion results. */ |
1267 void (*convert_free)(const void *object, void *data, Bytecount size); | 1283 void (*convert_free) (const void *object, void *data, Bytecount size); |
1268 | 1284 |
1269 /* De-conversion. | 1285 /* De-conversion. |
1270 | 1286 |
1271 At reload time, rebuilds the object from the converted form. | 1287 At reload time, rebuilds the object from the converted form. |
1272 "object" is 0 for the PTR case, return is ignored in the DATA | 1288 "object" is 0 for the PTR case, return is ignored in the DATA |
1273 case. */ | 1289 case. */ |
1274 void *(*deconvert)(void *object, void *data, Bytecount size); | 1290 void *(*deconvert) (void *object, void *data, Bytecount size); |
1275 | 1291 |
1276 }; | 1292 }; |
1277 | 1293 |
1278 extern const struct sized_memory_description lisp_object_description; | 1294 extern const struct sized_memory_description lisp_object_description; |
1279 | 1295 |