/** Clear all registered {{ trait_pascal }} implementations. */
public static void clearAll{{ trait_pascal }}() throws Exception {
try {
try (var arena = Arena.ofConfined()) {
MemorySegment outErr = arena.allocate(ValueLayout.ADDRESS);
int rc = (int) NativeLib.{{ prefix_upper }}_CLEAR_{{ trait_snake_upper }}.invoke(outErr);
if (rc != 0) {
MemorySegment errPtr = outErr.get(ValueLayout.ADDRESS, 0);
String msg = errPtr.equals(MemorySegment.NULL) ? "clear failed (rc=" + rc + ")" : errPtr.reinterpret(Long.MAX_VALUE).getString(0);
throw new RuntimeException("clearAll{{ trait_pascal }}: " + msg);
}
}
} catch (Throwable t) {
if (t instanceof Exception e) {
throw e;
} else {
throw new RuntimeException("Unexpected error during clear", t);
}
}
{{ registry_field }}.values().forEach({{ bridge_class }}::close);
{{ registry_field }}.clear();
}