polar-objc 5.44
An Objective-C runtime library
Loading...
Searching...
No Matches
polar-runtime-error.c
1/* Internal API: runtime error handling for polar-objc.
2 Copyright (C) 2022-2025 Michael Malicoat <[email protected]>
3
4 This file is part of polar-objc.
5
6 polar-objc is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
8
9 polar-objc is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
10 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 details.
12
13 You should have received a copy of the GNU General Public License along with this program; see the file LICENSE. If
14 not, see <http://www.gnu.org/licenses/>.
15*/
16
17// Private =============================================================================================================
18
19#define POLAR_STRING_BANNER_RUNTIME_ERROR "** FATAL ** runtime error ***\n"
20
21// Default routines ----------------------------------------------------------------------------------------------------
22
23POLAR_FUNCTION_INTERNAL OBJC_NORETURN void
24_polar_runtime_error_assertion_failed_default( const char *expr_text, const char *expr_source, intptr_t idx_expr )
25{
26 polar_error_printf( POLAR_STRING_BANNER_DEBUG, "%s: %D: assertion failed: %s",
27 expr_source, idx_expr, expr_text );
28
30}
31
32POLAR_FUNCTION_INTERNAL OBJC_NORETURN void
33_polar_runtime_error_class_missing_default( const char *name_class_missing )
34{
35 polar_error_printf( POLAR_STRING_BANNER_RUNTIME_ERROR, "%s: unknown class name",
36 name_class_missing );
37
39}
40
41POLAR_FUNCTION_INTERNAL OBJC_NORETURN void
42_polar_runtime_error_exception_invalid_throw_default( const char *name_exception_source, intptr_t idx_exception_source )
43{
44 polar_error_printf( POLAR_STRING_BANNER_RUNTIME_ERROR, "%s: %D: invalid @throw() statement",
45 name_exception_source, idx_exception_source );
46
48}
49
50POLAR_FUNCTION_INTERNAL OBJC_NORETURN void
51_polar_runtime_error_exception_unhandled_default( id inst_exception_unhandled )
52{
53 polar_error_printf( POLAR_STRING_BANNER_RUNTIME_ERROR, "%o: unhandled exception",
54 inst_exception_unhandled );
55
57}
58
59POLAR_FUNCTION_INTERNAL OBJC_NORETURN void
60_polar_runtime_error_foreach_enum_mutated_default( id inst_collection_mutated )
61{
62 polar_error_printf( POLAR_STRING_BANNER_RUNTIME_ERROR,
63 "%o: collection instance mutated during fast enumeration",
64 inst_collection_mutated );
65
67}
68
69POLAR_FUNCTION_INTERNAL OBJC_NORETURN void
70_polar_runtime_error_memory_exhausted_default( size_t count_bytes_needed )
71{
72 polar_error_printf( POLAR_STRING_BANNER_RUNTIME_ERROR,
73 "virtual memory exhausted; failed to allocate %z bytes",
74 count_bytes_needed );
75
77}
78
79POLAR_FUNCTION_INTERNAL OBJC_NORETURN void
80_polar_runtime_error_message_unrecognized_default( SEL sel_message, id id_recipient )
81{
82 polar_error_printf( POLAR_STRING_BANNER_RUNTIME_ERROR,
83 "%m: failed to locate method implementation",
84 id_recipient, sel_message );
85
87}
88
89POLAR_FUNCTION_INTERNAL OBJC_NORETURN void
90_polar_runtime_error_module_init_failed_default( struct objc_module *module_failed )
91{
92 polar_error_printf( POLAR_STRING_BANNER_RUNTIME_ERROR, "%M: module initialization failed",
93 module_failed );
94
96}
97
98POLAR_FUNCTION_INTERNAL OBJC_NORETURN void
99_polar_runtime_error_module_version_mismatch_default( struct objc_module *module_failed, ulong version_expected )
100{
101 polar_error_printf( POLAR_STRING_BANNER_RUNTIME_ERROR,
102 "%M: module version mismatch; expected %u, got %u",
103 version_expected, module_failed->version_module );
104
106}
107
108POLAR_FUNCTION_INTERNAL OBJC_NORETURN void
109_polar_runtime_error_protocol_version_mismatch_default( struct objc_protocol_static *protocol_failed,
110 uintptr_t version_expected )
111{
112 polar_error_printf( POLAR_STRING_BANNER_RUNTIME_ERROR,
113 "%P: protocol version mismatch; expected %U, got %U",
114 version_expected, protocol_failed->version_protocol );
115
117}
118
119POLAR_FUNCTION_INTERNAL OBJC_NORETURN void
120_polar_runtime_error_subsystem_init_failed_default( const char *name_subsystem_failed )
121{
122 polar_error_printf( POLAR_STRING_BANNER_RUNTIME_ERROR, "%s: initialization failed",
123 name_subsystem_failed );
124
126}
127
128POLAR_FUNCTION_INTERNAL OBJC_NORETURN void
129_polar_runtime_error_thread_operation_failed_default( const char *str_description )
130{
131 polar_error_printf( POLAR_STRING_BANNER_RUNTIME_ERROR, "thread operation failed: %s",
132 str_description );
133
135}
136
137POLAR_FUNCTION_INTERNAL OBJC_NORETURN void
138_polar_runtime_error_type_init_failed_default( const char *name_type_failed )
139{
140 polar_error_printf( POLAR_STRING_BANNER_RUNTIME_ERROR, "%s: type initialization failed",
141 name_type_failed );
142
144}
145
146static struct polar_vmt_runtime_error_handlers polar_runtime_error_handlers_default =
147{
148 _polar_runtime_error_assertion_failed_default,
149 _polar_runtime_error_class_missing_default,
150 _polar_runtime_error_exception_invalid_throw_default,
151 _polar_runtime_error_exception_unhandled_default,
152 _polar_runtime_error_foreach_enum_mutated_default,
153 _polar_runtime_error_memory_exhausted_default,
154 _polar_runtime_error_message_unrecognized_default,
155 _polar_runtime_error_module_init_failed_default,
156 _polar_runtime_error_module_version_mismatch_default,
157 _polar_runtime_error_protocol_version_mismatch_default,
158 _polar_runtime_error_subsystem_init_failed_default,
159 _polar_runtime_error_thread_operation_failed_default,
160 _polar_runtime_error_type_init_failed_default
161};
162
163struct polar_vmt_runtime_error_handlers *POLAR_RUNTIME_ERROR = &polar_runtime_error_handlers_default;
164
165// Public ==============================================================================================================
166
167POLAR_FUNCTION_INTERNAL struct polar_vmt_runtime_error_handlers *
168polar_runtime_error_set_handlers( struct polar_vmt_runtime_error_handlers *vmt_handlers_new )
169{
170 void *result;
171
172 if( vmt_handlers_new != NULL )
173 result = objc_atomic_exchange_pointer( (void **)(&POLAR_RUNTIME_ERROR), vmt_handlers_new );
174
175 else
176 result = objc_atomic_exchange_pointer( (void **)(&POLAR_RUNTIME_ERROR),&polar_runtime_error_handlers_default );
177
178 return (struct polar_vmt_runtime_error_handlers *)result;
179}
static void thrd_process_abort(void)
Definition polar-windows-platform-threading.h:153
Definition polar-runtime-error.h:25