Skip to content

Commit

Permalink
improve cc_bstring string literal and cstring names (twitter#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevyang authored Jul 30, 2018
1 parent 0184d73 commit c9c5ee5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
13 changes: 6 additions & 7 deletions include/cc_bstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ struct bstring {
#define str2bstr(_str) (struct bstring){ sizeof(_str) - 1, (_str) }
#define null_bstring (struct bstring){ 0, NULL }

#define bstring_set_text(_str, _text) do { \
(_str)->len = (uint32_t)(sizeof(_text) - 1); \
(_str)->data = (_text); \
#define bstring_set_literal(_str, _literal) do { \
(_str)->len = (uint32_t)(sizeof(_literal) - 1); \
(_str)->data = (_literal); \
} while (0);

/* TODO(yao): rename this */
#define bstring_set_raw(_str, _raw) do { \
(_str)->len = (uint32_t)(cc_strlen(_raw)); \
(_str)->data = (char *)(_raw); \
#define bstring_set_cstr(_str, _cstr) do { \
(_str)->len = (uint32_t)(cc_strlen(_cstr)); \
(_str)->data = (char *)(_cstr); \
} while (0);

void bstring_init(struct bstring *str);
Expand Down
4 changes: 2 additions & 2 deletions rust/ccommon_rs/src/log/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
//! log_setup()
//! {
//! log_config.buf_size = 1024;
//! bstring_set_raw(&log_config.prefix, "templog");
//! bstring_set_raw(&log_config.path, PATH);
//! bstring_set_cstr(&log_config.prefix, "templog");
//! bstring_set_cstr(&log_config.path, PATH);
//! log_config.level = LOG_LEVEL_TRACE;
//!
//! log_handle = log_create_handle_rs(&log_config);
Expand Down
6 changes: 3 additions & 3 deletions src/cc_bstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
* raw sequence of character bytes - bstring_copy(). Such String's must be
* freed using bstring_deinit()
*
* We can also create String as reference to raw string - bstring_set_raw()
* or to string literal - bstring_set_text() or bstring(). Such bstrings don't
* have to be freed.
* We can also create String as reference to C string - bstring_set_cstr()
* or to string literal - bstring_set_literal() or bstring(). Such bstrings
* don't have to be freed.
*/

void
Expand Down
4 changes: 2 additions & 2 deletions test/log/check_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ START_TEST(test_most_basic_rust_logging_setup_teardown)

struct log_config_rs cfg;
cfg.buf_size = 1024;
bstring_set_raw(&cfg.prefix, "templog");
bstring_set_raw(&cfg.path, path);
bstring_set_cstr(&cfg.prefix, "templog");
bstring_set_cstr(&cfg.path, path);
cfg.level = LOG_LEVEL_TRACE;

struct log_handle_rs *handle = log_create_handle_rs(&cfg);
Expand Down

0 comments on commit c9c5ee5

Please sign in to comment.