comparison src/alloc.c @ 4959:bd169a24a554

merge
author Ben Wing <ben@xemacs.org>
date Thu, 28 Jan 2010 04:27:30 -0600
parents 304aebb79cd3
children e813cf16c015
comparison
equal deleted inserted replaced
4893:99f2102552d7 4959:bd169a24a554
270 do \ 270 do \
271 { \ 271 { \
272 /* Unbelievably, calling free() on 0xDEADBEEF doesn't cause an \ 272 /* Unbelievably, calling free() on 0xDEADBEEF doesn't cause an \
273 error until much later on for many system mallocs, such as \ 273 error until much later on for many system mallocs, such as \
274 the one that comes with Solaris 2.3. FMH!! */ \ 274 the one that comes with Solaris 2.3. FMH!! */ \
275 assert (block != (void *) 0xDEADBEEF); \ 275 assert (block != (void *) DEADBEEF_CONSTANT); \
276 MALLOC_BEGIN (); \ 276 MALLOC_BEGIN (); \
277 } \ 277 } \
278 while (0) 278 while (0)
279 #else /* not NEW_GC */ 279 #else /* not NEW_GC */
280 #define FREE_OR_REALLOC_BEGIN(block) \ 280 #define FREE_OR_REALLOC_BEGIN(block) \
281 do \ 281 do \
282 { \ 282 { \
283 /* Unbelievably, calling free() on 0xDEADBEEF doesn't cause an \ 283 /* Unbelievably, calling free() on 0xDEADBEEF doesn't cause an \
284 error until much later on for many system mallocs, such as \ 284 error until much later on for many system mallocs, such as \
285 the one that comes with Solaris 2.3. FMH!! */ \ 285 the one that comes with Solaris 2.3. FMH!! */ \
286 assert (block != (void *) 0xDEADBEEF); \ 286 assert (block != (void *) DEADBEEF_CONSTANT); \
287 /* You cannot free something within dumped space, because there is \ 287 /* You cannot free something within dumped space, because there is \
288 no longer any sort of malloc structure associated with the block. \ 288 no longer any sort of malloc structure associated with the block. \
289 If you are tripping this, you may need to conditionalize on \ 289 If you are tripping this, you may need to conditionalize on \
290 DUMPEDP. */ \ 290 DUMPEDP. */ \
291 assert (!DUMPEDP (block)); \ 291 assert (!DUMPEDP (block)); \
2872 } 2872 }
2873 2873
2874 /* Take some raw memory, encoded in some external data format, 2874 /* Take some raw memory, encoded in some external data format,
2875 and convert it into a Lisp string. */ 2875 and convert it into a Lisp string. */
2876 Lisp_Object 2876 Lisp_Object
2877 make_ext_string (const Extbyte *contents, EMACS_INT length, 2877 make_extstring (const Extbyte *contents, EMACS_INT length,
2878 Lisp_Object coding_system) 2878 Lisp_Object coding_system)
2879 { 2879 {
2880 Lisp_Object string; 2880 Lisp_Object string;
2881 TO_INTERNAL_FORMAT (DATA, (contents, length), 2881 TO_INTERNAL_FORMAT (DATA, (contents, length),
2882 LISP_STRING, string, 2882 LISP_STRING, string,
2883 coding_system); 2883 coding_system);
2884 return string; 2884 return string;
2885 } 2885 }
2886 2886
2887 Lisp_Object 2887 Lisp_Object
2888 build_intstring (const Ibyte *str) 2888 build_istring (const Ibyte *str)
2889 { 2889 {
2890 /* Some strlen's crash and burn if passed null. */ 2890 /* Some strlen's crash and burn if passed null. */
2891 return make_string (str, (str ? qxestrlen (str) : (Bytecount) 0)); 2891 return make_string (str, (str ? qxestrlen (str) : (Bytecount) 0));
2892 } 2892 }
2893 2893
2894 Lisp_Object 2894 Lisp_Object
2895 build_string (const CIbyte *str) 2895 build_cistring (const CIbyte *str)
2896 {
2897 return build_istring ((const Ibyte *) str);
2898 }
2899
2900 Lisp_Object
2901 build_ascstring (const Ascbyte *str)
2902 {
2903 ASSERT_ASCTEXT_ASCII (str);
2904 return build_istring ((const Ibyte *) str);
2905 }
2906
2907 Lisp_Object
2908 build_extstring (const Extbyte *str, Lisp_Object coding_system)
2896 { 2909 {
2897 /* Some strlen's crash and burn if passed null. */ 2910 /* Some strlen's crash and burn if passed null. */
2898 return make_string ((const Ibyte *) str, (str ? strlen (str) : 0)); 2911 return make_extstring ((const Extbyte *) str,
2899 }
2900
2901 Lisp_Object
2902 build_ext_string (const Extbyte *str, Lisp_Object coding_system)
2903 {
2904 /* Some strlen's crash and burn if passed null. */
2905 return make_ext_string ((const Extbyte *) str,
2906 (str ? dfc_external_data_len (str, coding_system) : 2912 (str ? dfc_external_data_len (str, coding_system) :
2907 0), 2913 0),
2908 coding_system); 2914 coding_system);
2909 } 2915 }
2910 2916
2911 Lisp_Object 2917 /* Build a string whose content is a translatable message, and translate
2912 build_msg_intstring (const Ibyte *str) 2918 the message according to the current language environment. */
2913 { 2919
2914 return build_intstring (GETTEXT (str)); 2920 Lisp_Object
2915 } 2921 build_msg_istring (const Ibyte *str)
2916 2922 {
2917 Lisp_Object 2923 return build_istring (IGETTEXT (str));
2918 build_msg_string (const CIbyte *str) 2924 }
2919 { 2925
2920 return build_string (CGETTEXT (str)); 2926 /* Build a string whose content is a translatable message, and translate
2927 the message according to the current language environment. */
2928
2929 Lisp_Object
2930 build_msg_cistring (const CIbyte *str)
2931 {
2932 return build_msg_istring ((const Ibyte *) str);
2933 }
2934
2935 /* Build a string whose content is a translatable message, and translate
2936 the message according to the current language environment.
2937 String must be pure-ASCII, and when compiled with error-checking,
2938 an abort will have if not pure-ASCII. */
2939
2940 Lisp_Object
2941 build_msg_ascstring (const Ascbyte *str)
2942 {
2943 ASSERT_ASCTEXT_ASCII (str);
2944 return build_msg_istring ((const Ibyte *) str);
2945 }
2946
2947 /* Build a string whose content is a translatable message, but don't
2948 translate the message immediately. Perhaps do something else instead,
2949 such as put a property on the string indicating that it needs to be
2950 translated.
2951
2952 This is useful for strings that are built at dump time or init time,
2953 rather than on-the-fly when the current language environment is set
2954 properly. */
2955
2956 Lisp_Object
2957 build_defer_istring (const Ibyte *str)
2958 {
2959 Lisp_Object retval = build_istring ((Ibyte *) str);
2960 /* Possibly do something to the return value */
2961 return retval;
2962 }
2963
2964 Lisp_Object
2965 build_defer_cistring (const CIbyte *str)
2966 {
2967 return build_defer_istring ((Ibyte *) str);
2968 }
2969
2970 Lisp_Object
2971 build_defer_ascstring (const Ascbyte *str)
2972 {
2973 ASSERT_ASCTEXT_ASCII (str);
2974 return build_defer_istring ((Ibyte *) str);
2921 } 2975 }
2922 2976
2923 Lisp_Object 2977 Lisp_Object
2924 make_string_nocopy (const Ibyte *contents, Bytecount length) 2978 make_string_nocopy (const Ibyte *contents, Bytecount length)
2925 { 2979 {
3241 staticpros_description_1 3295 staticpros_description_1
3242 }; 3296 };
3243 3297
3244 #ifdef DEBUG_XEMACS 3298 #ifdef DEBUG_XEMACS
3245 3299
3246 static const struct memory_description staticpro_one_name_description_1[] = {
3247 { XD_ASCII_STRING, 0 },
3248 { XD_END }
3249 };
3250
3251 static const struct sized_memory_description staticpro_one_name_description = {
3252 sizeof (char *),
3253 staticpro_one_name_description_1
3254 };
3255
3256 static const struct memory_description staticpro_names_description_1[] = {
3257 XD_DYNARR_DESC (char_ptr_dynarr, &staticpro_one_name_description),
3258 { XD_END }
3259 };
3260
3261
3262 extern const struct sized_memory_description staticpro_names_description;
3263
3264 const struct sized_memory_description staticpro_names_description = {
3265 sizeof (char_ptr_dynarr),
3266 staticpro_names_description_1
3267 };
3268
3269 /* Help debug crashes gc-marking a staticpro'ed object. */ 3300 /* Help debug crashes gc-marking a staticpro'ed object. */
3270 3301
3271 Lisp_Object_ptr_dynarr *staticpros; 3302 Lisp_Object_ptr_dynarr *staticpros;
3272 char_ptr_dynarr *staticpro_names; 3303 const_Ascbyte_ptr_dynarr *staticpro_names;
3273 3304
3274 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for 3305 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for
3275 garbage collection, and for dumping. */ 3306 garbage collection, and for dumping. */
3276 void 3307 void
3277 staticpro_1 (Lisp_Object *varaddress, char *varname) 3308 staticpro_1 (Lisp_Object *varaddress, const Ascbyte *varname)
3278 { 3309 {
3279 Dynarr_add (staticpros, varaddress); 3310 Dynarr_add (staticpros, varaddress);
3280 Dynarr_add (staticpro_names, varname); 3311 Dynarr_add (staticpro_names, varname);
3281 dump_add_root_lisp_object (varaddress); 3312 dump_add_root_lisp_object (varaddress);
3282 } 3313 }
3283 3314
3315 /* External debugging function: Return the name of the variable at offset
3316 COUNT. */
3317 const Ascbyte *
3318 staticpro_name (int count)
3319 {
3320 return Dynarr_at (staticpro_names, count);
3321 }
3284 3322
3285 Lisp_Object_ptr_dynarr *staticpros_nodump; 3323 Lisp_Object_ptr_dynarr *staticpros_nodump;
3286 char_ptr_dynarr *staticpro_nodump_names; 3324 const_Ascbyte_ptr_dynarr *staticpro_nodump_names;
3287 3325
3288 /* Mark the Lisp_Object at heap VARADDRESS as a root object for 3326 /* Mark the Lisp_Object at heap VARADDRESS as a root object for
3289 garbage collection, but not for dumping. (See below.) */ 3327 garbage collection, but not for dumping. (See below.) */
3290 void 3328 void
3291 staticpro_nodump_1 (Lisp_Object *varaddress, char *varname) 3329 staticpro_nodump_1 (Lisp_Object *varaddress, const Ascbyte *varname)
3292 { 3330 {
3293 Dynarr_add (staticpros_nodump, varaddress); 3331 Dynarr_add (staticpros_nodump, varaddress);
3294 Dynarr_add (staticpro_nodump_names, varname); 3332 Dynarr_add (staticpro_nodump_names, varname);
3333 }
3334
3335 /* External debugging function: Return the name of the variable at offset
3336 COUNT. */
3337 const Ascbyte *
3338 staticpro_nodump_name (int count)
3339 {
3340 return Dynarr_at (staticpro_nodump_names, count);
3295 } 3341 }
3296 3342
3297 #ifdef HAVE_SHLIB 3343 #ifdef HAVE_SHLIB
3298 /* Stop treating the Lisp_Object at non-heap VARADDRESS as a root object 3344 /* Stop treating the Lisp_Object at non-heap VARADDRESS as a root object
3299 for garbage collection, but not for dumping. */ 3345 for garbage collection, but not for dumping. */
3300 void 3346 void
3301 unstaticpro_nodump_1 (Lisp_Object *varaddress, char *varname) 3347 unstaticpro_nodump_1 (Lisp_Object *varaddress, const Ascbyte *varname)
3302 { 3348 {
3303 Dynarr_delete_object (staticpros, varaddress); 3349 Dynarr_delete_object (staticpros, varaddress);
3304 Dynarr_delete_object (staticpro_names, varname); 3350 Dynarr_delete_object (staticpro_names, varname);
3305 } 3351 }
3306 #endif 3352 #endif
3380 mcpros_description_1 3426 mcpros_description_1
3381 }; 3427 };
3382 3428
3383 #ifdef DEBUG_XEMACS 3429 #ifdef DEBUG_XEMACS
3384 3430
3385 static const struct memory_description mcpro_one_name_description_1[] = {
3386 { XD_ASCII_STRING, 0 },
3387 { XD_END }
3388 };
3389
3390 static const struct sized_memory_description mcpro_one_name_description = {
3391 sizeof (char *),
3392 mcpro_one_name_description_1
3393 };
3394
3395 static const struct memory_description mcpro_names_description_1[] = {
3396 XD_DYNARR_DESC (char_ptr_dynarr, &mcpro_one_name_description),
3397 { XD_END }
3398 };
3399
3400 extern const struct sized_memory_description mcpro_names_description;
3401
3402 const struct sized_memory_description mcpro_names_description = {
3403 sizeof (char_ptr_dynarr),
3404 mcpro_names_description_1
3405 };
3406
3407 /* Help debug crashes gc-marking a mcpro'ed object. */ 3431 /* Help debug crashes gc-marking a mcpro'ed object. */
3408 3432
3409 Lisp_Object_dynarr *mcpros; 3433 Lisp_Object_dynarr *mcpros;
3410 char_ptr_dynarr *mcpro_names; 3434 const_Ascbyte_ptr_dynarr *mcpro_names;
3411 3435
3412 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for 3436 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for
3413 garbage collection, and for dumping. */ 3437 garbage collection, and for dumping. */
3414 void 3438 void
3415 mcpro_1 (Lisp_Object varaddress, char *varname) 3439 mcpro_1 (Lisp_Object varaddress, const Ascbyte *varname)
3416 { 3440 {
3417 Dynarr_add (mcpros, varaddress); 3441 Dynarr_add (mcpros, varaddress);
3418 Dynarr_add (mcpro_names, varname); 3442 Dynarr_add (mcpro_names, varname);
3443 }
3444
3445 /* External debugging function: Return the name of the variable at offset
3446 COUNT. */
3447 const Ascbyte *
3448 mcpro_name (int count)
3449 {
3450 return Dynarr_at (mcpro_names, count);
3419 } 3451 }
3420 3452
3421 #else /* not DEBUG_XEMACS */ 3453 #else /* not DEBUG_XEMACS */
3422 3454
3423 Lisp_Object_dynarr *mcpros; 3455 Lisp_Object_dynarr *mcpros;
4447 4479
4448 for (i = 0; i < countof (lrecord_implementations_table); i++) 4480 for (i = 0; i < countof (lrecord_implementations_table); i++)
4449 { 4481 {
4450 if (lrecord_stats[i].instances_in_use != 0) 4482 if (lrecord_stats[i].instances_in_use != 0)
4451 { 4483 {
4452 char buf [255]; 4484 Ascbyte buf[255];
4453 const char *name = lrecord_implementations_table[i]->name; 4485 const Ascbyte *name = lrecord_implementations_table[i]->name;
4454 int len = strlen (name); 4486 int len = strlen (name);
4455 4487
4456 if (lrecord_stats[i].bytes_in_use_including_overhead != 4488 if (lrecord_stats[i].bytes_in_use_including_overhead !=
4457 lrecord_stats[i].bytes_in_use) 4489 lrecord_stats[i].bytes_in_use)
4458 { 4490 {
4491 { 4523 {
4492 if (lcrecord_stats[i].bytes_in_use != 0 4524 if (lcrecord_stats[i].bytes_in_use != 0
4493 || lcrecord_stats[i].bytes_freed != 0 4525 || lcrecord_stats[i].bytes_freed != 0
4494 || lcrecord_stats[i].instances_on_free_list != 0) 4526 || lcrecord_stats[i].instances_on_free_list != 0)
4495 { 4527 {
4496 char buf [255]; 4528 Ascbyte buf[255];
4497 const char *name = lrecord_implementations_table[i]->name; 4529 const Ascbyte *name = lrecord_implementations_table[i]->name;
4498 int len = strlen (name); 4530 int len = strlen (name);
4499 4531
4500 sprintf (buf, "%s-storage", name); 4532 sprintf (buf, "%s-storage", name);
4501 pl = gc_plist_hack (buf, lcrecord_stats[i].bytes_in_use, pl); 4533 pl = gc_plist_hack (buf, lcrecord_stats[i].bytes_in_use, pl);
4502 tgu_val += lcrecord_stats[i].bytes_in_use; 4534 tgu_val += lcrecord_stats[i].bytes_in_use;
4934 staticpros_nodump = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *); 4966 staticpros_nodump = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *);
4935 Dynarr_resize (staticpros_nodump, 100); /* merely a small optimization */ 4967 Dynarr_resize (staticpros_nodump, 100); /* merely a small optimization */
4936 #ifdef DEBUG_XEMACS 4968 #ifdef DEBUG_XEMACS
4937 if (staticpro_nodump_names) 4969 if (staticpro_nodump_names)
4938 Dynarr_free (staticpro_nodump_names); 4970 Dynarr_free (staticpro_nodump_names);
4939 staticpro_nodump_names = Dynarr_new2 (char_ptr_dynarr, char *); 4971 staticpro_nodump_names = Dynarr_new2 (const_Ascbyte_ptr_dynarr,
4972 const Ascbyte *);
4940 Dynarr_resize (staticpro_nodump_names, 100); /* ditto */ 4973 Dynarr_resize (staticpro_nodump_names, 100); /* ditto */
4941 #endif 4974 #endif
4942 4975
4943 #ifdef NEW_GC 4976 #ifdef NEW_GC
4944 mcpros = Dynarr_new2 (Lisp_Object_dynarr, Lisp_Object); 4977 mcpros = Dynarr_new2 (Lisp_Object_dynarr, Lisp_Object);
4945 Dynarr_resize (mcpros, 1410); /* merely a small optimization */ 4978 Dynarr_resize (mcpros, 1410); /* merely a small optimization */
4946 dump_add_root_block_ptr (&mcpros, &mcpros_description); 4979 dump_add_root_block_ptr (&mcpros, &mcpros_description);
4947 #ifdef DEBUG_XEMACS 4980 #ifdef DEBUG_XEMACS
4948 mcpro_names = Dynarr_new2 (char_ptr_dynarr, char *); 4981 mcpro_names = Dynarr_new2 (const_Ascbyte_ptr_dynarr, const Ascbyte *);
4949 Dynarr_resize (mcpro_names, 1410); /* merely a small optimization */ 4982 Dynarr_resize (mcpro_names, 1410); /* merely a small optimization */
4950 dump_add_root_block_ptr (&mcpro_names, &mcpro_names_description); 4983 dump_add_root_block_ptr (&mcpro_names,
4984 &const_Ascbyte_ptr_dynarr_description_1);
4951 #endif 4985 #endif
4952 #endif /* NEW_GC */ 4986 #endif /* NEW_GC */
4953 4987
4954 consing_since_gc = 0; 4988 consing_since_gc = 0;
4955 need_to_check_c_alloca = 0; 4989 need_to_check_c_alloca = 0;
5038 5072
5039 staticpros = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *); 5073 staticpros = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *);
5040 Dynarr_resize (staticpros, 1410); /* merely a small optimization */ 5074 Dynarr_resize (staticpros, 1410); /* merely a small optimization */
5041 dump_add_root_block_ptr (&staticpros, &staticpros_description); 5075 dump_add_root_block_ptr (&staticpros, &staticpros_description);
5042 #ifdef DEBUG_XEMACS 5076 #ifdef DEBUG_XEMACS
5043 staticpro_names = Dynarr_new2 (char_ptr_dynarr, char *); 5077 staticpro_names = Dynarr_new2 (const_Ascbyte_ptr_dynarr, const Ascbyte *);
5044 Dynarr_resize (staticpro_names, 1410); /* merely a small optimization */ 5078 Dynarr_resize (staticpro_names, 1410); /* merely a small optimization */
5045 dump_add_root_block_ptr (&staticpro_names, &staticpro_names_description); 5079 dump_add_root_block_ptr (&staticpro_names,
5080 &const_Ascbyte_ptr_dynarr_description);
5046 #endif 5081 #endif
5047 5082
5048 #ifdef NEW_GC 5083 #ifdef NEW_GC
5049 mcpros = Dynarr_new2 (Lisp_Object_dynarr, Lisp_Object); 5084 mcpros = Dynarr_new2 (Lisp_Object_dynarr, Lisp_Object);
5050 Dynarr_resize (mcpros, 1410); /* merely a small optimization */ 5085 Dynarr_resize (mcpros, 1410); /* merely a small optimization */
5051 dump_add_root_block_ptr (&mcpros, &mcpros_description); 5086 dump_add_root_block_ptr (&mcpros, &mcpros_description);
5052 #ifdef DEBUG_XEMACS 5087 #ifdef DEBUG_XEMACS
5053 mcpro_names = Dynarr_new2 (char_ptr_dynarr, char *); 5088 mcpro_names = Dynarr_new2 (const_Ascbyte_ptr_dynarr, const Ascbyte *);
5054 Dynarr_resize (mcpro_names, 1410); /* merely a small optimization */ 5089 Dynarr_resize (mcpro_names, 1410); /* merely a small optimization */
5055 dump_add_root_block_ptr (&mcpro_names, &mcpro_names_description); 5090 dump_add_root_block_ptr (&mcpro_names,
5091 &const_Ascbyte_ptr_dynarr_description);
5056 #endif 5092 #endif
5057 #else /* not NEW_GC */ 5093 #else /* not NEW_GC */
5058 init_lcrecord_lists (); 5094 init_lcrecord_lists ();
5059 #endif /* not NEW_GC */ 5095 #endif /* not NEW_GC */
5060 } 5096 }