mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-14 05:12:33 +00:00
runtime/mercury_overflow.c: As above: compiling this function in high-level C grades will fail since it refers to fields of the MR_Context structure that do not exist in those grades.
89 lines
2.3 KiB
C
89 lines
2.3 KiB
C
/*
|
|
** vim: ts=4 sw=4 expandtab
|
|
*/
|
|
/*
|
|
** Copyright (C) 2014 The Mercury team
|
|
** This file may only be copied under the terms of the GNU Library General
|
|
** Public License - see the file COPYING.LIB in the Mercury distribution.
|
|
*/
|
|
|
|
#include "mercury_imp.h"
|
|
#include "mercury_overflow.h"
|
|
#include "mercury_memory_zones.h" /* for MR_MemoryZone */
|
|
#include "mercury_debug.h" /* for MR_print_zone() etc */
|
|
#include "mercury_misc.h" /* for MR_fatal_error() */
|
|
|
|
#if !defined(MR_HIGHLEVEL_CODE)
|
|
void
|
|
MR_nondetstack_inclusion_check(MR_Word *maxfr,
|
|
const char *error, const char *where)
|
|
{
|
|
MR_MemoryZone *cur_zone;
|
|
MR_MemoryZones *prev_zones;
|
|
|
|
cur_zone = MR_CONTEXT(MR_ctxt_nondetstack_zone);
|
|
prev_zones = MR_CONTEXT(MR_ctxt_prev_nondetstack_zones);
|
|
while (MR_TRUE) {
|
|
if (MR_in_zone(maxfr, cur_zone)) {
|
|
if (maxfr > cur_zone->MR_zone_max) {
|
|
cur_zone->MR_zone_max = maxfr;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (prev_zones == NULL) {
|
|
MR_fatal_zone_error(MR_OVERFLOW_ZONE_NONDETSTACK,
|
|
"MR_maxfr", maxfr, "nondetstack_zone",
|
|
MR_CONTEXT(MR_ctxt_nondetstack_zone),
|
|
MR_CONTEXT(MR_ctxt_prev_nondetstack_zones),
|
|
error, where);
|
|
}
|
|
|
|
cur_zone = prev_zones->MR_zones_head;
|
|
prev_zones = prev_zones->MR_zones_tail;
|
|
}
|
|
}
|
|
#endif /* !MR_HIGHLEVEL_CODE */
|
|
|
|
void
|
|
MR_fatal_zone_error(MR_OverflowZone ptr_kind,
|
|
const char *ptr_name, const void *ptr,
|
|
const char *zone_name,
|
|
const MR_MemoryZone *zone, const MR_MemoryZones *zones,
|
|
const char *error, const char *where)
|
|
{
|
|
#ifdef MR_LOWLEVEL_DEBUG
|
|
fprintf(stderr, "fatal zone error\n%s: ", ptr_name);
|
|
switch (ptr_kind) {
|
|
|
|
case MR_OZONE_DETSTACK:
|
|
MR_print_detstackptr(stderr, ptr);
|
|
break;
|
|
|
|
case MR_OZONE_NONDETSTACK:
|
|
MR_print_nondetstackptr(stderr, ptr);
|
|
break;
|
|
|
|
case MR_OZONE_HEAP:
|
|
MR_print_heapptr(stderr, ptr);
|
|
break;
|
|
|
|
case MR_OZONE_OTHER:
|
|
default:
|
|
fprintf(stderr, "%p", ptr);
|
|
break;
|
|
}
|
|
|
|
fprintf(stderr, "\n%s: ", zone_name);
|
|
MR_print_zone(stderr, zone);
|
|
MR_print_zones(stderr, zones);
|
|
|
|
if (where != NULL) {
|
|
fprintf(stderr, "error occurred in %s\n", where);
|
|
}
|
|
#endif
|
|
|
|
MR_fatal_error(error);
|
|
}
|