1 /***********************************************************************/
5 /* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */
7 /* Copyright 1996 Institut National de Recherche en Informatique et */
8 /* en Automatique. All rights reserved. This file is distributed */
9 /* under the terms of the GNU Library General Public License, with */
10 /* the special exception on linking described in file ../LICENSE. */
12 /***********************************************************************/
23 int caml_failed_assert (char * expr
, char * file
, int line
)
25 fprintf (stderr
, "file %s; line %d ### Assertion failed: %s\n",
29 return 1; /* not reached */
32 void caml_set_fields (char *bp
, unsigned long start
, unsigned long filler
)
35 for (i
= start
; i
< Wosize_bp (bp
); i
++){
36 Field (Val_bp (bp
), i
) = (value
) filler
;
42 uintnat caml_verb_gc
= 0;
44 void caml_gc_message (int level
, char *msg
, uintnat arg
)
46 if (level
< 0 || (caml_verb_gc
& level
) != 0){
47 fprintf (stderr
, msg
, arg
);
52 CAMLexport
void caml_fatal_error (char *msg
)
54 fprintf (stderr
, "%s", msg
);
58 CAMLexport
void caml_fatal_error_arg (char *fmt
, char *arg
)
60 fprintf (stderr
, fmt
, arg
);
64 CAMLexport
void caml_fatal_error_arg2 (char *fmt1
, char *arg1
,
65 char *fmt2
, char *arg2
)
67 fprintf (stderr
, fmt1
, arg1
);
68 fprintf (stderr
, fmt2
, arg2
);
72 char *caml_aligned_malloc (asize_t size
, int modulo
, void **block
)
76 Assert (modulo
< Page_size
);
77 raw_mem
= (char *) malloc (size
+ Page_size
);
78 if (raw_mem
== NULL
) return NULL
;
80 raw_mem
+= modulo
; /* Address to be aligned */
81 aligned_mem
= (((uintnat
) raw_mem
/ Page_size
+ 1) * Page_size
);
85 uintnat
*p0
= (void *) *block
,
86 *p1
= (void *) (aligned_mem
- modulo
),
87 *p2
= (void *) (aligned_mem
- modulo
+ size
),
88 *p3
= (void *) ((char *) *block
+ size
+ Page_size
);
90 for (p
= p0
; p
< p1
; p
++) *p
= Debug_filler_align
;
91 for (p
= p1
; p
< p2
; p
++) *p
= Debug_uninit_align
;
92 for (p
= p2
; p
< p3
; p
++) *p
= Debug_filler_align
;
95 return (char *) (aligned_mem
- modulo
);
98 void caml_ext_table_init(struct ext_table
* tbl
, int init_capa
)
101 tbl
->capacity
= init_capa
;
102 tbl
->contents
= caml_stat_alloc(sizeof(void *) * init_capa
);
105 int caml_ext_table_add(struct ext_table
* tbl
, void * data
)
108 if (tbl
->size
>= tbl
->capacity
) {
111 caml_stat_resize(tbl
->contents
, sizeof(void *) * tbl
->capacity
);
114 tbl
->contents
[res
] = data
;
119 void caml_ext_table_free(struct ext_table
* tbl
, int free_entries
)
123 for (i
= 0; i
< tbl
->size
; i
++) caml_stat_free(tbl
->contents
[i
]);
124 caml_stat_free(tbl
->contents
);