1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-29 23:13:14 +02:00

C API: Keep the structure flat

See https://github.com/NixOS/nix/pull/10329
This commit is contained in:
José Luis Lafuente 2024-03-28 19:00:04 +01:00
parent d96b52bd8b
commit c57de60522
No known key found for this signature in database
GPG key ID: 8A3455EBE455489A
26 changed files with 50 additions and 32 deletions

View file

@ -1,49 +0,0 @@
#ifndef NIX_API_UTIL_INTERNAL_H
#define NIX_API_UTIL_INTERNAL_H
#include <string>
#include <optional>
#include "error.hh"
#include "nix_api_util.h"
struct nix_c_context
{
nix_err last_err_code = NIX_OK;
std::optional<std::string> last_err = {};
std::optional<nix::ErrorInfo> info = {};
std::string name = "";
};
nix_err nix_context_error(nix_c_context * context);
/**
* Internal use only.
*
* Helper to invoke nix_observe_string
* @param context optional, the context to store errors in if this function
* fails
* @param str The string to observe
* @param callback Called with the observed string.
* @param user_data optional, arbitrary data, passed to the callback when it's called.
* @return NIX_OK if there were no errors.
* @see nix_observe_string
*/
nix_err call_nix_observe_string(const std::string str, void * callback, void * user_data);
#define NIXC_CATCH_ERRS \
catch (...) \
{ \
return nix_context_error(context); \
} \
return NIX_OK;
#define NIXC_CATCH_ERRS_RES(def) \
catch (...) \
{ \
nix_context_error(context); \
return def; \
}
#define NIXC_CATCH_ERRS_NULL NIXC_CATCH_ERRS_RES(nullptr)
#endif // NIX_API_UTIL_INTERNAL_H