mirror of
https://github.com/NixOS/nix.git
synced 2025-12-18 23:11:08 +01:00
For example, instead of doing
#include "nix/store-config.hh"
#include "nix/derived-path.hh"
Now do
#include "nix/store/config.hh"
#include "nix/store/derived-path.hh"
This was originally planned in the issue, and also recent requested by
Eelco.
Most of the change is purely mechanical. There is just one small
additional issue. See how, in the example above, we took this
opportunity to also turn `<comp>-config.hh` into `<comp>/config.hh`.
Well, there was already a `nix/util/config.{cc,hh}`. Even though there
is not a public configuration header for libutil (which also would be
called `nix/util/config.{cc,hh}`) that's still confusing, To avoid any
such confusion, we renamed that to `nix/util/configuration.{cc,hh}`.
Finally, note that the libflake headers already did this, so we didn't
need to do anything to them. We wouldn't want to mistakenly get
`nix/flake/flake/flake.hh`!
Progress on #7876
50 lines
1.4 KiB
C++
50 lines
1.4 KiB
C++
#ifndef NIX_API_UTIL_INTERNAL_H
|
|
#define NIX_API_UTIL_INTERNAL_H
|
|
|
|
#include <string>
|
|
#include <optional>
|
|
|
|
#include "nix/util/error.hh"
|
|
#include "nix_api_util.h"
|
|
|
|
struct nix_c_context
|
|
{
|
|
nix_err last_err_code = NIX_OK;
|
|
/** The last error message. Always check last_err_code. This may not have been cleared, so that clearing is fast. */
|
|
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_get_string_callback
|
|
* @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_get_string_callback
|
|
*/
|
|
nix_err call_nix_get_string_callback(const std::string str, nix_get_string_callback 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
|