From c1e07693558eb94855b97ae44e01f51909d9fdac Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 4 Apr 2024 15:24:42 -0400 Subject: [PATCH] Fix some portability issues with the new C bindings Build without GC is unbroken Fix #10403 Also building tests with Windows (assuming rest of Windows fixes) is unbroken. --- src/libexpr-c/local.mk | 2 +- src/libexpr-c/nix_api_expr.cc | 4 ++-- src/libexpr-c/nix_api_external.cc | 6 +++--- src/libexpr-c/nix_api_value.cc | 8 ++++---- src/libstore-c/local.mk | 2 +- src/libutil-c/local.mk | 2 +- tests/unit/libstore-support/tests/nix_api_store.hh | 14 +++++++++++++- 7 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/libexpr-c/local.mk b/src/libexpr-c/local.mk index ce5d321d6..51b02562e 100644 --- a/src/libexpr-c/local.mk +++ b/src/libexpr-c/local.mk @@ -17,7 +17,7 @@ libexprc_CXXFLAGS += $(INCLUDE_libutil) $(INCLUDE_libutilc) \ libexprc_LIBS = libutil libutilc libstore libstorec libexpr -libexprc_LDFLAGS += -pthread +libexprc_LDFLAGS += $(THREAD_LDFLAGS) $(eval $(call install-file-in, $(d)/nix-expr-c.pc, $(libdir)/pkgconfig, 0644)) diff --git a/src/libexpr-c/nix_api_expr.cc b/src/libexpr-c/nix_api_expr.cc index f18ef399b..a5c03d5aa 100644 --- a/src/libexpr-c/nix_api_expr.cc +++ b/src/libexpr-c/nix_api_expr.cc @@ -155,13 +155,13 @@ void nix_gc_now() } #else -void nix_gc_incref(nix_c_context * context, const void *) +nix_err nix_gc_incref(nix_c_context * context, const void *) { if (context) context->last_err_code = NIX_OK; return NIX_OK; } -void nix_gc_decref(nix_c_context * context, const void *) +nix_err nix_gc_decref(nix_c_context * context, const void *) { if (context) context->last_err_code = NIX_OK; diff --git a/src/libexpr-c/nix_api_external.cc b/src/libexpr-c/nix_api_external.cc index c237cfb70..3c3dd6ca9 100644 --- a/src/libexpr-c/nix_api_external.cc +++ b/src/libexpr-c/nix_api_external.cc @@ -1,7 +1,6 @@ #include "attr-set.hh" #include "config.hh" #include "eval.hh" -#include "gc/gc.h" #include "globals.hh" #include "value.hh" @@ -16,8 +15,9 @@ #include #ifdef HAVE_BOEHMGC -#define GC_INCLUDE_NEW 1 -#include "gc_cpp.h" +# include "gc/gc.h" +# define GC_INCLUDE_NEW 1 +# include "gc_cpp.h" #endif void nix_set_string_return(nix_string_return * str, const char * c) diff --git a/src/libexpr-c/nix_api_value.cc b/src/libexpr-c/nix_api_value.cc index 80e853b87..02bd154b3 100644 --- a/src/libexpr-c/nix_api_value.cc +++ b/src/libexpr-c/nix_api_value.cc @@ -1,7 +1,6 @@ #include "attr-set.hh" #include "config.hh" #include "eval.hh" -#include "gc/gc.h" #include "globals.hh" #include "primops.hh" #include "value.hh" @@ -13,8 +12,9 @@ #include "nix_api_value.h" #ifdef HAVE_BOEHMGC -#define GC_INCLUDE_NEW 1 -#include "gc_cpp.h" +# include "gc/gc.h" +# define GC_INCLUDE_NEW 1 +# include "gc_cpp.h" #endif // Helper function to throw an exception if value is null @@ -444,7 +444,7 @@ void nix_list_builder_free(ListBuilder * list_builder) #if HAVE_BOEHMGC GC_FREE(list_builder); #else - delete bb; + delete list_builder; #endif } diff --git a/src/libstore-c/local.mk b/src/libstore-c/local.mk index 36a8e77a4..5e3eff06a 100644 --- a/src/libstore-c/local.mk +++ b/src/libstore-c/local.mk @@ -8,7 +8,7 @@ libstorec_SOURCES := $(wildcard $(d)/*.cc) libstorec_LIBS = libutil libstore libutilc -libstorec_LDFLAGS += -pthread +libstorec_LDFLAGS += $(THREAD_LDFLAGS) # Not just for this library itself, but also for downstream libraries using this library diff --git a/src/libutil-c/local.mk b/src/libutil-c/local.mk index 342dc2d8b..f2df1ef43 100644 --- a/src/libutil-c/local.mk +++ b/src/libutil-c/local.mk @@ -13,6 +13,6 @@ libutilc_CXXFLAGS += $(INCLUDE_libutil) $(INCLUDE_libutilc) libutilc_LIBS = libutil -libutilc_LDFLAGS += -pthread +libutilc_LDFLAGS += $(THREAD_LDFLAGS) libutilc_FORCE_INSTALL := 1 diff --git a/tests/unit/libstore-support/tests/nix_api_store.hh b/tests/unit/libstore-support/tests/nix_api_store.hh index a8b60fbc3..a2d35d083 100644 --- a/tests/unit/libstore-support/tests/nix_api_store.hh +++ b/tests/unit/libstore-support/tests/nix_api_store.hh @@ -2,6 +2,8 @@ ///@file #include "tests/nix_api_util.hh" +#include "file-system.hh" + #include "nix_api_store.h" #include "nix_api_store_internal.h" @@ -37,8 +39,18 @@ public: protected: void init_local_store() { - auto tmpl = nix::getEnv("TMPDIR").value_or("/tmp") + "/tests_nix-store.XXXXXX"; +#ifdef _WIN32 + // no `mkdtemp` with MinGW + auto tmpl = nix::defaultTempDir() + "/tests_nix-store."; + for (size_t i = 0; true; ++i) { + nixDir = tmpl + std::string { i }; + if (fs::create_directory(nixDir)) break; + } +#else + auto tmpl = nix::defaultTempDir() + "/tests_nix-store.XXXXXX"; nixDir = mkdtemp((char *) tmpl.c_str()); +#endif + nixStoreDir = nixDir + "/my_nix_store"; // Options documented in `nix help-stores`