miniDSP
A small C library for audio DSP
Loading...
Searching...
No Matches
minidsp_error.c File Reference

Configurable error handler for precondition violations. More...

#include "minidsp.h"

Go to the source code of this file.

Functions

static void default_error_handler (MD_ErrorCode code, const char *func_name, const char *message)
void MD_set_error_handler (MD_ErrorHandler handler)
 Install a custom error handler.
void md_report_error (MD_ErrorCode code, const char *func_name, const char *message)
 Report a precondition violation to the active error handler.

Variables

static MD_ErrorHandler current_handler = default_error_handler

Detailed Description

Configurable error handler for precondition violations.

Author
Chuck Wooters woote.nosp@m.rs@h.nosp@m.ey.co.nosp@m.m

Definition in file minidsp_error.c.

Function Documentation

◆ default_error_handler()

void default_error_handler ( MD_ErrorCode code,
const char * func_name,
const char * message )
static

Definition at line 13 of file minidsp_error.c.

◆ md_report_error()

void md_report_error ( MD_ErrorCode code,
const char * func_name,
const char * message )

Report a precondition violation to the active error handler.

Definition at line 36 of file minidsp_error.c.

◆ MD_set_error_handler()

void MD_set_error_handler ( MD_ErrorHandler handler)

Install a custom error handler.

When a miniDSP function detects a precondition violation (NULL pointer, invalid size, etc.) it calls the active handler instead of aborting. The default handler prints a message to stderr.

Pass NULL to restore the default handler.

Thread safety
This function must be called once, before any other MD_* call. It must not be called concurrently with any other miniDSP function.
// Example: redirect miniDSP errors to an application log
static void my_handler(MD_ErrorCode code, const char *fn, const char *msg) {
app_log(LOG_WARN, "miniDSP error %d in %s: %s", code, fn, msg);
}
int main(void) {
MD_set_error_handler(my_handler);
// ... use miniDSP ...
}
MD_ErrorCode
Error codes reported by miniDSP when a precondition is violated.
Definition minidsp.h:61
void MD_set_error_handler(MD_ErrorHandler handler)
Install a custom error handler.

Definition at line 27 of file minidsp_error.c.

Variable Documentation

◆ current_handler

MD_ErrorHandler current_handler = default_error_handler
static

Definition at line 25 of file minidsp_error.c.