Skip to content

Commit

Permalink
Rust: Fix Send and Sync regression in 2.6.0 (#259)
Browse files Browse the repository at this point in the history
* rust: add semver check to github workflow

* rust: mark StanLibrary as Send and Sync to restore previous behavior

* c: mark version numbers as const
  • Loading branch information
aseyboldt authored Dec 23, 2024
1 parent 17bcd55 commit 116f436
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,7 @@ jobs:
# run all tests with feature download-bridgestan-src
cargo test --verbose --all-features
cargo test --verbose model_compiling -- --ignored
- name: Check semver for rust interface
uses: obi1kenobi/cargo-semver-checks-action@v2
with:
manifest-path: ./rust/Cargo.toml
4 changes: 4 additions & 0 deletions rust/src/bs_safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ pub struct StanLibrary {
id: u64,
}

// Stan libraries are thread safe.
unsafe impl Send for StanLibrary {}
unsafe impl Sync for StanLibrary {}

// To work around a bug where unloading a library
// can lead to deadlocks.
//
Expand Down
6 changes: 3 additions & 3 deletions src/bridgestan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "callback_stream.hpp"
#include <sstream>

int bs_major_version = BRIDGESTAN_MAJOR;
int bs_minor_version = BRIDGESTAN_MINOR;
int bs_patch_version = BRIDGESTAN_PATCH;
const int bs_major_version = BRIDGESTAN_MAJOR;
const int bs_minor_version = BRIDGESTAN_MINOR;
const int bs_patch_version = BRIDGESTAN_PATCH;

bs_model* bs_model_construct(const char* data, unsigned int seed,
char** error_msg) {
Expand Down
6 changes: 3 additions & 3 deletions src/bridgestan.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ typedef void (*STREAM_CALLBACK)(const char* data, size_t size);
* @note These were not available pre-2.0.0, so their absence
* implies the library is in the 1.0.x series
*/
BS_PUBLIC extern int bs_major_version;
BS_PUBLIC extern int bs_minor_version;
BS_PUBLIC extern int bs_patch_version;
BS_PUBLIC extern const int bs_major_version;
BS_PUBLIC extern const int bs_minor_version;
BS_PUBLIC extern const int bs_patch_version;

/**
* Construct an instance of a model wrapper.
Expand Down

0 comments on commit 116f436

Please sign in to comment.