From 7ff4e130bceac2cb23fc76693271f776cc6bdfcf Mon Sep 17 00:00:00 2001 From: Roland Kaminski Date: Wed, 11 Dec 2024 11:38:50 +0100 Subject: [PATCH] cleanup pass --- libclingo/clingo.h | 6 ++++-- libclingo/src/control.cc | 11 +++++++---- libpyclingo/clingo/control.py | 2 ++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/libclingo/clingo.h b/libclingo/clingo.h index e7a77731b..9412c817b 100644 --- a/libclingo/clingo.h +++ b/libclingo/clingo.h @@ -2838,7 +2838,7 @@ CLINGO_VISIBILITY_DEFAULT bool clingo_control_load(clingo_control_t *control, ch //! @return whether the call was successful; might set one of the following error codes: //! - ::clingo_error_bad_alloc //! - ::clingo_error_runtime if parsing or checking fails -CLINGO_VISIBILITY_DEFAULT bool clingo_control_load_aspif(clingo_control_t *ctl, char const **files, size_t size); +CLINGO_VISIBILITY_DEFAULT bool clingo_control_load_aspif(clingo_control_t *control, char const **files, size_t size); //! Extend the logic program with the given non-ground logic program in string form. //! @@ -3138,7 +3138,9 @@ CLINGO_VISIBILITY_DEFAULT bool clingo_control_register_observer(clingo_control_t //! @param[in] type the kind of backend to register //! @param[in] file the file to write the result to //! @param[in] replace just pass the grounding to the backend but not the solver -//! @return whether the call was successful +//! @return whether the call was successful; might set one of the following error codes: +//! - ::clingo_error_bad_alloc +//! - ::clingo_error_runtime (for example if the file could not be opened) CLINGO_VISIBILITY_DEFAULT bool clingo_control_register_backend(clingo_control_t *control, clingo_backend_type_t type, char const *file, bool replace); //! @} diff --git a/libclingo/src/control.cc b/libclingo/src/control.cc index 0b1802c52..0a7b663e3 100644 --- a/libclingo/src/control.cc +++ b/libclingo/src/control.cc @@ -2204,17 +2204,20 @@ extern "C" bool clingo_control_register_observer(clingo_control_t *control, clin extern "C" bool clingo_control_register_backend(clingo_control_t *control, clingo_backend_type_t type, char const *file, bool replace) { GRINGO_CLINGO_TRY { auto out = gringo_make_unique(file); - auto backend = UBackend{}; //Output::make_backend(out, OutputFormat::reify, false, false); + if (!out->is_open()) { + throw std::runtime_error("file could not be opened"); + } + auto backend = UBackend{}; switch (type & 0xFFFFFFFC) { - case clingo_backend_type_e::clingo_backend_type_reify: { + case clingo_backend_type_reify: { backend = Output::make_backend(std::move(out), Output::OutputFormat::REIFY, (type & 1) == 1, (type &2) == 2); break; } - case clingo_backend_type_e::clingo_backend_type_smodels: { + case clingo_backend_type_smodels: { backend = Output::make_backend(std::move(out), Output::OutputFormat::SMODELS, false, false); break; } - case clingo_backend_type_e::clingo_backend_type_aspif: { + case clingo_backend_type_aspif: { backend = Output::make_backend(std::move(out), Output::OutputFormat::INTERMEDIATE, false, false); break; } diff --git a/libpyclingo/clingo/control.py b/libpyclingo/clingo/control.py index 62e8e3356..3225649c5 100644 --- a/libpyclingo/clingo/control.py +++ b/libpyclingo/clingo/control.py @@ -716,6 +716,8 @@ def register_backend( ---------- type The type of backend to register. + file: + The path of the file to write to. replace If set to true, the output is just passed to the backend and no longer to the underlying solver (or any previously registered backends/observers).