MT#55283 modernise STR_DUP()

Change-Id: Ifb614cb75c05dfc574c122533d78c4c649ef76a1
rfuchs/gh1842
Richard Fuchs 2 years ago
parent ba9a6465ce
commit 43af67755c

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

@ -851,7 +851,7 @@ static const char *janus_videoroom_configure(struct websocket_message *wm, struc
if (strcmp(jsep_type, "offer")) if (strcmp(jsep_type, "offer"))
return "Not an 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_ng_flags) flags;
g_auto(sdp_sessions_q) parsed = TYPED_GQUEUE_INIT; 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")) if (strcmp(jsep_type, "answer"))
return "Not an 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_ng_flags) flags;
g_auto(sdp_sessions_q) parsed = TYPED_GQUEUE_INIT; g_auto(sdp_sessions_q) parsed = TYPED_GQUEUE_INIT;

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

@ -41,7 +41,7 @@ TYPED_GQUEUE(str, str)
#define STR_GS(s) ((str) { (s)->str, (s)->len }) #define STR_GS(s) ((str) { (s)->str, (s)->len })
#define STR_LEN(s, len) ((str) { (char *) (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_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) }) #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))) __attribute__((nonnull(1)))
ACCESS(write_only, 1) ACCESS(write_only, 1)
ACCESS(read_only, 2) 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 str *str_init_dup_str(str *out, const str *s);
INLINE void str_free_dup(str *out); INLINE void str_free_dup(str *out);
/* returns new str object with uninitialized buffer large enough to hold `len` characters (+1 for null byte) */ /* 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); 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) { INLINE str *str_init_dup_str(str *out, const str *s) {
if (!s) { if (!s) {
*out = STR_NULL; *out = STR_NULL;

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

Loading…
Cancel
Save