Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decide how to pass exceptions across the C API (tracking swss-common/#932) #10

Open
erer1243 opened this issue Oct 28, 2024 · 0 comments

Comments

@erer1243
Copy link
Contributor

Main issue: sonic-net/sonic-swss-common#932

Once that issue is solved, we will need to implement that here.
Maybe it can look something like this?

// in swss-common
fn catch<T, Fn: FnOnce() -> T>(f: Fn) -> Result<T, String> {
  unsafe { SWSSTry_() };
  let ans = f();
  let err = unsafe { SWSSCatch() };
  if err.is_null() {
    Ok(ans)
  } else {
    Err(string_from_cstr(err))
  }
}

// in hamgrd/other library user code
let res = swss_common::catch(|| DBConnector::new(...));
match res {
  Ok(db_connector) => { ... }
  Err(err_msg) => { ... }
}
@erer1243 erer1243 changed the title Decide how to pass exceptions across the C API (tracking swss-common/ Decide how to pass exceptions across the C API (tracking swss-common/#932) Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant