ObjFW  Check-in [85a52c4717]

Overview
Comment:runtime/exception.m: abort() -> OBJC_ERROR()

Use OBJC_ERROR() to print an error message instead of silently aborting.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 85a52c4717ff8682e02572fda0b0a0f7d5f1f23c5f87f047d527c87e6138f6e6
User & Date: js on 2016-07-10 16:23:48
Other Links: manifest | tags
Context
2016-07-10
22:40
Add of_dl{open,sym,close} check-in: 81970b1dab user: js tags: trunk
16:23
runtime/exception.m: abort() -> OBJC_ERROR() check-in: 85a52c4717 user: js tags: trunk
15:51
OFHTTPClient: Fix wrong Host on redirect check-in: 412c005e2b user: js tags: trunk
Changes

Modified src/runtime/exception.m from [9ee77747e2] to [30cec995ef].

20
21
22
23
24
25
26

27
28
29
30
31
32
33
#include <string.h>

#ifdef HAVE_SEH_EXCEPTIONS
# include <windows.h>
#endif

#import "runtime.h"


#import "macros.h"

#if defined(HAVE_DWARF_EXCEPTIONS)
# define PERSONALITY __gnu_objc_personality_v0
#elif defined(HAVE_SJLJ_EXCEPTIONS)
# define PERSONALITY __gnu_objc_personality_sj0







>







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <string.h>

#ifdef HAVE_SEH_EXCEPTIONS
# include <windows.h>
#endif

#import "runtime.h"
#import "runtime-private.h"

#import "macros.h"

#if defined(HAVE_DWARF_EXCEPTIONS)
# define PERSONALITY __gnu_objc_personality_v0
#elif defined(HAVE_SJLJ_EXCEPTIONS)
# define PERSONALITY __gnu_objc_personality_sj0
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
		return _Unwind_GetRegionStart(ctx);
	case DW_EH_PE_datarel:
		return _Unwind_GetDataRelBase(ctx);
	case DW_EH_PE_textrel:
		return _Unwind_GetTextRelBase(ctx);
	}

	abort();
}

static size_t
size_for_encoding(uint8_t enc)
{
	if (enc == DW_EH_PE_omit)
		return 0;

	switch (enc & 0x07) {
	case DW_EH_PE_absptr:
		return sizeof(void*);
	case DW_EH_PE_udata2:
		return 2;
	case DW_EH_PE_udata4:
		return 4;
	case DW_EH_PE_udata8:
		return 8;
	}

	abort();
}

static uint64_t
read_value(uint8_t enc, const uint8_t **ptr)
{
	uint64_t value;

	if (enc == DW_EH_PE_aligned)
		/* Not implemented */
		abort();

#define READ(type)				\
	{					\
		value = *(type*)(void*)*ptr;	\
		*ptr += size_for_encoding(enc);	\
		break;				\
	}







|



















|








|
<







250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286

287
288
289
290
291
292
293
		return _Unwind_GetRegionStart(ctx);
	case DW_EH_PE_datarel:
		return _Unwind_GetDataRelBase(ctx);
	case DW_EH_PE_textrel:
		return _Unwind_GetTextRelBase(ctx);
	}

	OBJC_ERROR("Unknown encoding!")
}

static size_t
size_for_encoding(uint8_t enc)
{
	if (enc == DW_EH_PE_omit)
		return 0;

	switch (enc & 0x07) {
	case DW_EH_PE_absptr:
		return sizeof(void*);
	case DW_EH_PE_udata2:
		return 2;
	case DW_EH_PE_udata4:
		return 4;
	case DW_EH_PE_udata8:
		return 8;
	}

	OBJC_ERROR("Unknown encoding!")
}

static uint64_t
read_value(uint8_t enc, const uint8_t **ptr)
{
	uint64_t value;

	if (enc == DW_EH_PE_aligned)
		OBJC_ERROR("DW_EH_PE_aligned is not implemented!")


#define READ(type)				\
	{					\
		value = *(type*)(void*)*ptr;	\
		*ptr += size_for_encoding(enc);	\
		break;				\
	}
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
	case DW_EH_PE_sdata2:
		READ(int16_t)
	case DW_EH_PE_sdata4:
		READ(int32_t)
	case DW_EH_PE_sdata8:
		READ(int64_t)
	default:
		abort();
	}
#undef READ

	return value;
}

#ifndef HAVE_ARM_EHABI_EXCEPTIONS







|







309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
	case DW_EH_PE_sdata2:
		READ(int16_t)
	case DW_EH_PE_sdata4:
		READ(int32_t)
	case DW_EH_PE_sdata8:
		READ(int64_t)
	default:
		OBJC_ERROR("Unknown encoding!")
	}
#undef READ

	return value;
}

#ifndef HAVE_ARM_EHABI_EXCEPTIONS
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512

			if (class_matches(class, e->object)) {
				*filtervalue = filter;
				return HANDLER_FOUND;
			}
		} else if (filter == 0)
			return CLEANUP_FOUND;
		else
			abort();
	} while (displacement != 0);

	return 0;
}

#ifndef HAVE_ARM_EHABI_EXCEPTIONS
# ifdef HAVE_SEH_EXCEPTIONS







|
|







497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512

			if (class_matches(class, e->object)) {
				*filtervalue = filter;
				return HANDLER_FOUND;
			}
		} else if (filter == 0)
			return CLEANUP_FOUND;
		else if (filter < 0)
			OBJC_ERROR("Invalid filter!")
	} while (displacement != 0);

	return 0;
}

#ifndef HAVE_ARM_EHABI_EXCEPTIONS
# ifdef HAVE_SEH_EXCEPTIONS
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
		    (uintptr_t)ex);
		_Unwind_SetGR(ctx, __builtin_eh_return_data_regno(1), filter);
		_Unwind_SetIP(ctx, landingpad);

		return _URC_INSTALL_CONTEXT;
	}

	abort();
}

static void
cleanup(_Unwind_Reason_Code reason, struct _Unwind_Exception *ex)
{
	free(ex);
}

void
objc_exception_throw(id object)
{
	struct objc_exception *e;

	if ((e = malloc(sizeof(*e))) == NULL)
		abort();

	memset(e, 0, sizeof(*e));
	e->exception.class = objc_exception_class;
	e->exception.cleanup = cleanup;
	e->object = object;

	if (_Unwind_RaiseException(&e->exception) == _URC_END_OF_STACK &&
	    uncaught_exception_handler != NULL)
		uncaught_exception_handler(object);

	abort();
}

objc_uncaught_exception_handler
objc_setUncaughtExceptionHandler(objc_uncaught_exception_handler handler)
{
	objc_uncaught_exception_handler old = uncaught_exception_handler;
	uncaught_exception_handler = handler;







|














|










|







620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
		    (uintptr_t)ex);
		_Unwind_SetGR(ctx, __builtin_eh_return_data_regno(1), filter);
		_Unwind_SetIP(ctx, landingpad);

		return _URC_INSTALL_CONTEXT;
	}

	OBJC_ERROR("Neither _UA_SEARCH_PHASE nor _UA_CLEANUP_PHASE in actions!")
}

static void
cleanup(_Unwind_Reason_Code reason, struct _Unwind_Exception *ex)
{
	free(ex);
}

void
objc_exception_throw(id object)
{
	struct objc_exception *e;

	if ((e = malloc(sizeof(*e))) == NULL)
		OBJC_ERROR("Not enough memory to allocate exception!")

	memset(e, 0, sizeof(*e));
	e->exception.class = objc_exception_class;
	e->exception.cleanup = cleanup;
	e->object = object;

	if (_Unwind_RaiseException(&e->exception) == _URC_END_OF_STACK &&
	    uncaught_exception_handler != NULL)
		uncaught_exception_handler(object);

	OBJC_ERROR("_Unwind_RaiseException() returned!")
}

objc_uncaught_exception_handler
objc_setUncaughtExceptionHandler(objc_uncaught_exception_handler handler)
{
	objc_uncaught_exception_handler old = uncaught_exception_handler;
	uncaught_exception_handler = handler;