Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently, the functions in mx_mysql log errors from mysql. When functions are nested, often the caller logs the error again, as do users of this module. Because mysql has a set of own error codes, these are mapped to system error codes and sometimes these get logged again via printf "%m", showing some more or less related system error string. Generally, it unclear, whether the caller or the callee is expected to log the errors, which leads to the same error logged multiple times in different forms. The functions in this module communicate the crafted system error code in both, errno and as the (negated) return value of the function. Accesses to errno are expensive (alway a call) and the duplication leads to complicated code and unclear semantics. Change the general error handling API for this module: Mysql error strings, which often contain useful information which is not encoded in any error indentifier, are captured but not logged by this module. A new function mx_mysql_error() is provided for the caller to get the lastest error string. System error code are returned as before, but errno is not set. After the change, it is the callers duty to log errors. res = mx_mysql_connect(&mx_mysql); if (res < 0) { fprintf(stderr, mx_mysql_connect: %s\n", mx_mysql_error()); _exit(1); } This change reduces the object size of mx_mxql by 28%.
- Loading branch information