I have been doing some work on the LMDB bindings (https://github.com/iraikov/chicken-lmdb) and submitted a patch for it's error-handling. Ivan and I are not 100% sure what I've done is safe, so I'd appreciate your expertise.
Normally, I have my C bindings return an error code and then in scheme I would create a condition and call (abort ...). The LMDB binding, however, does more work in C. Currently, the LMDB error handling looks like this: ``` static void chicken_ThrowException(C_word value) C_noret; static void chicken_ThrowException(C_word value) { char *aborthook = C_text("\003sysabort"); C_word *a = C_alloc(C_SIZEOF_STRING(strlen(aborthook))); C_word abort = C_intern2(&a, aborthook); abort = C_block_item(abort, 0); if (C_immediatep(abort)) Chicken_Panic(C_text("`##sys#abort' is not defined")); #if defined(C_BINARY_VERSION) && (C_BINARY_VERSION >= 8) C_word rval[3] = { abort, C_SCHEME_UNDEFINED, value }; C_do_apply(3, rval); #else C_save(value); C_do_apply(1, abort, C_SCHEME_UNDEFINED); #endif } void chicken_lmdb_exception (int code, int msglen, const char *msg) { C_word *a; C_word scmmsg; C_word list; a = C_alloc (C_SIZEOF_STRING (msglen) + C_SIZEOF_LIST(2)); scmmsg = C_string2 (&a, (char *) msg); list = C_list(&a, 2, C_fix(code), scmmsg); chicken_ThrowException(list); } ``` Where error codes from LMDB functions are passed to `chicken_lmdb_exception` from C. I wanted to update this to create a composite condition that could be used with condition-case and friends. I replaced the two functions above with a define-external: ``` (define-external (chicken_lmdb_exception (int code)) void (abort (make-composite-condition (make-property-condition 'exn 'message (error-code-string code)) (make-property-condition 'lmdb) (make-property-condition (error-code-symbol code))))) ``` The rest of the C code still calls `chicken_lmdb_exception` as before. My question: Is this functionally equivalent to the original C implementation in terms of calling abort? -- Caolan _______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users