Skip to content

Commit

Permalink
Merge pull request #54 from SpringQL/fix/avoid-errno
Browse files Browse the repository at this point in the history
fix: avoid conflict of `errno` with the global in <errno.h>
  • Loading branch information
laysakura authored Jun 29, 2022
2 parents 4efcb0d + bf5e2e6 commit e1173a6
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 18 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ Also check the changes in springql-core: <https://github.com/SpringQL/SpringQL/b
<!-- markdownlint-disable MD024 -->
## [Unreleased]

## [v0.15.0+2] - 2022-06-30

### Fixed

- Fix name conflict of `errno` in a `spring_last_err`'s argument with `errno.h` ([#54](https://github.com/SpringQL/SpringQL-client-c/pull/54))

## [v0.15.0] - 2022-06-29

### Added
Expand Down Expand Up @@ -102,8 +108,9 @@ Depends on springql-core v0.7.1.
[Semantic Versioning]: https://semver.org/

<!-- Versions -->
[Unreleased]: https://github.com/SpringQL/SpringQL-client-c/compare/v0.15.0...HEAD
[Unreleased]: https://github.com/SpringQL/SpringQL-client-c/compare/v0.15.0+2...HEAD
[Released]: https://github.com/SpringQL/SpringQL-client-c/releases
[v0.15.0+2]: https://github.com/SpringQL/SpringQL-client-c/compare/v0.15.0...v0.15.0+2
[v0.15.0]: https://github.com/SpringQL/SpringQL-client-c/compare/v0.14.0...v0.15.0
[v0.14.0]: https://github.com/SpringQL/SpringQL-client-c/compare/v0.13.0+4...v0.14.0
[v0.13.0+4]: https://github.com/SpringQL/SpringQL-client-c/compare/v0.13.0+3...v0.13.0+4
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "springql-client-c"
version = "0.15.0"
version = "0.15.0+2"

authors = ["Sho Nakatani <lay.sakura@gmail.com>"]
license = "MIT OR Apache-2.0"
Expand Down
6 changes: 3 additions & 3 deletions c_example/doc_app1/doc_app1.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

void abort_with_report()
{
SpringErrno errno;
SpringErrno errno_;
char errmsg[1024];
spring_last_err(&errno, errmsg, 1024);
fprintf(stderr, "Error occurred (%d): %s", errno, errmsg);
spring_last_err(&errno_, errmsg, 1024);
fprintf(stderr, "Error occurred (%d): %s", errno_, errmsg);
abort();
}

Expand Down
6 changes: 3 additions & 3 deletions c_example/doc_app2/doc_app2.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

void abort_with_report()
{
SpringErrno errno;
SpringErrno errno_;
char errmsg[1024];
spring_last_err(&errno, errmsg, 1024);
fprintf(stderr, "Error occurred (%d): %s", errno, errmsg);
spring_last_err(&errno_, errmsg, 1024);
fprintf(stderr, "Error occurred (%d): %s", errno_, errmsg);
abort();
}

Expand Down
6 changes: 3 additions & 3 deletions c_example/trade_projection/trade_projection.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

void abort_with_report()
{
SpringErrno errno;
SpringErrno errno_;
char errmsg[1024];
spring_last_err(&errno, errmsg, 1024);
fprintf(stderr, "Error occurred (%d): %s", errno, errmsg);
spring_last_err(&errno_, errmsg, 1024);
fprintf(stderr, "Error occurred (%d): %s", errno_, errmsg);
abort();
}

Expand Down
4 changes: 2 additions & 2 deletions springql.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ enum SpringErrno spring_column_bool(const SpringSinkRow *row, uint16_t i_col, bo
enum SpringErrno spring_column_float(const SpringSinkRow *row, uint16_t i_col, float *out);

/**
* Write the most recent error number into `errno` and message into a caller-provided buffer as a UTF-8
* Write the most recent error number into `errno_` and message into a caller-provided buffer as a UTF-8
* string, returning the number of bytes written.
*
* # Note
Expand All @@ -433,7 +433,7 @@ enum SpringErrno spring_column_float(const SpringSinkRow *row, uint16_t i_col, f
* - `> 0`: the length of the recent error message.
* - `< 0`: SpringErrno
*/
int spring_last_err(enum SpringErrno *errno,
int spring_last_err(enum SpringErrno *errno_,
char *errmsg,
int errmsg_len);

Expand Down
8 changes: 4 additions & 4 deletions src/spring_last_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub(super) fn update_last_error(err: LastError) {
});
}

/// Write the most recent error number into `errno` and message into a caller-provided buffer as a UTF-8
/// Write the most recent error number into `errno_` and message into a caller-provided buffer as a UTF-8
/// string, returning the number of bytes written.
///
/// # Note
Expand All @@ -91,7 +91,7 @@ pub(super) fn update_last_error(err: LastError) {
/// - `< 0`: SpringErrno
#[no_mangle]
pub unsafe extern "C" fn spring_last_err(
errno: *mut SpringErrno,
errno_: *mut SpringErrno,
errmsg: *mut c_char,
errmsg_len: c_int,
) -> c_int {
Expand All @@ -103,12 +103,12 @@ pub unsafe extern "C" fn spring_last_err(
let last_error = match take_last_error() {
Some(err) => err,
None => {
*errno = SpringErrno::Ok;
*errno_ = SpringErrno::Ok;
return SpringErrno::Ok as c_int;
}
};

*errno = SpringErrno::from(&last_error);
*errno_ = SpringErrno::from(&last_error);
let error_message = last_error.to_string();

strcpy(&error_message, errmsg, errmsg_len)
Expand Down

0 comments on commit e1173a6

Please sign in to comment.