Browse Source

MT#55283 modernise STR_DUP()

Change-Id: Ifb614cb75c05dfc574c122533d78c4c649ef76a1
rfuchs/gh1842
Richard Fuchs 1 year ago
parent
commit
43af67755c
5 changed files with 10 additions and 19 deletions
  1. +3
    -3
      daemon/codec.c
  2. +2
    -2
      daemon/janus.c
  3. +2
    -2
      daemon/main.c
  4. +1
    -10
      lib/str.h
  5. +2
    -2
      t/test-amr-encode.c

+ 3
- 3
daemon/codec.c View File

@ -2560,9 +2560,9 @@ void codec_init_payload_type(rtp_payload_type *pt, enum media_type type) {
// allocate strings
str_init_dup_str(&pt->encoding, &pt->encoding);
str_init_dup(&pt->encoding_with_params, full_encoding);
str_init_dup(&pt->encoding_with_full_params, full_full_encoding);
str_init_dup(&pt->encoding_parameters, params);
pt->encoding_with_params = STR_DUP(full_encoding);
pt->encoding_with_full_params = STR_DUP(full_full_encoding);
pt->encoding_parameters = STR_DUP(params);
str_init_dup_str(&pt->format_parameters, &pt->format_parameters);
str_init_dup_str(&pt->codec_opts, &pt->codec_opts);


+ 2
- 2
daemon/janus.c View File

@ -851,7 +851,7 @@ static const char *janus_videoroom_configure(struct websocket_message *wm, struc
if (strcmp(jsep_type, "offer"))
return "Not an offer";
g_auto(str) sdp_in = STR_INIT_DUP(jsep_sdp);
g_auto(str) sdp_in = STR_DUP(jsep_sdp);
g_auto(sdp_ng_flags) flags;
g_auto(sdp_sessions_q) parsed = TYPED_GQUEUE_INIT;
@ -956,7 +956,7 @@ static const char *janus_videoroom_start(struct websocket_message *wm, struct ja
if (strcmp(jsep_type, "answer"))
return "Not an answer";
g_auto(str) sdp_in = STR_INIT_DUP(jsep_sdp);
g_auto(str) sdp_in = STR_DUP(jsep_sdp);
g_auto(sdp_ng_flags) flags;
g_auto(sdp_sessions_q) parsed = TYPED_GQUEUE_INIT;


+ 2
- 2
daemon/main.c View File

@ -286,7 +286,7 @@ static int if_addr_parse(intf_config_q *q, char *s, struct ifaddrs *ifas) {
// foo=bar
ifa = g_slice_alloc0(sizeof(*ifa));
str_init_dup_str(&ifa->name, &name);
str_init_dup(&ifa->alias, s);
ifa->alias = STR_DUP(s);
t_queue_push_tail(q, ifa);
return 0;
}
@ -396,7 +396,7 @@ static int redis_ep_parse(endpoint_t *ep, int *db, char **auth, const char *auth
static void parse_cn_payload(str *out, char **in, const char *def, const char *name) {
if (!in || !*in) {
if (def)
str_init_dup(out, def);
*out = STR_DUP(def);
return;
}


+ 1
- 10
lib/str.h View File

@ -41,7 +41,7 @@ TYPED_GQUEUE(str, str)
#define STR_GS(s) ((str) { (s)->str, (s)->len })
#define STR_LEN(s, len) ((str) { (char *) (s), len })
#define STR_LEN_ASSERT(s, len) ({ assert(sizeof(s) >= len); (str) { (char *) (s), len }; })
#define STR_INIT_DUP(s) ((str) { g_strdup(s), strlen(s) })
#define STR_DUP(s) ((str) { g_strdup(s), strlen(s) })
#define STR_CONST_BUF(buf) ((str) { (char *) &buf, sizeof(buf) })
@ -86,10 +86,6 @@ INLINE int str_cmp_str0(const str *a, const str *b);
__attribute__((nonnull(1)))
ACCESS(write_only, 1)
ACCESS(read_only, 2)
INLINE str *str_init_dup(str *out, const char *s);
__attribute__((nonnull(1)))
ACCESS(write_only, 1)
ACCESS(read_only, 2)
INLINE str *str_init_dup_str(str *out, const str *s);
INLINE void str_free_dup(str *out);
/* returns new str object with uninitialized buffer large enough to hold `len` characters (+1 for null byte) */
@ -295,11 +291,6 @@ INLINE int str_cmp_str0(const str *a, const str *b) {
}
return str_cmp_str(a, b);
}
INLINE str *str_init_dup(str *out, const char *s) {
out->s = s ? g_strdup(s) : NULL;
out->len = s ? strlen(s) : 0;
return out;
}
INLINE str *str_init_dup_str(str *out, const str *s) {
if (!s) {
*out = STR_NULL;


+ 2
- 2
t/test-amr-encode.c View File

@ -62,7 +62,7 @@ static void do_test_amr_xx(const char *file, int line,
const format_t fmt = { .clockrate = clockrate, .channels = 1, .format = 0 };
str fmtp = STR_NULL;
if (fmtp_s)
str_init_dup(&fmtp, fmtp_s);
fmtp = STR_DUP(fmtp_s);
encoder_t *e = encoder_new();
assert(e);
format_t actual_fmt;
@ -88,7 +88,7 @@ static void do_test_amr_xx(const char *file, int line,
assert(expect_s == NULL);
encoder_free(e);
free(fmtp.s);
g_free(fmtp.s);
av_frame_free(&frame);
printf("test ok: %s:%i\n", file, line);


Loading…
Cancel
Save