Skip to content

Commit 12e7c88

Browse files
jpnurmiclaude
andcommitted
refactor(envelope): use sentry__value_new_path helper
Eliminates duplicated #ifdef SENTRY_PLATFORM_WINDOWS path-to-string conversion in envelope_add_attachment_ref and sentry__envelope_item_set_attachment_ref. Also switches envelope_add_attachment_ref from hand-rolled jsonwriter to sentry_value_t approach. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a209e90 commit 12e7c88

1 file changed

Lines changed: 10 additions & 25 deletions

File tree

src/sentry_envelope.c

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -654,27 +654,18 @@ envelope_add_attachment_ref(sentry_envelope_t *envelope,
654654
sentry__envelope_item_set_header(item, "attachment_length",
655655
sentry_value_new_uint64((uint64_t)file_size));
656656

657-
sentry_stringbuilder_t sb;
658-
sentry__stringbuilder_init(&sb);
659-
sentry_jsonwriter_t *jw = sentry__jsonwriter_new_sb(&sb);
660-
sentry__jsonwriter_write_object_start(jw);
661-
sentry__jsonwriter_write_key(jw, "path");
662-
#ifdef SENTRY_PLATFORM_WINDOWS
663-
char *path_str = sentry__string_from_wstr(path->path_w);
664-
sentry__jsonwriter_write_str(jw, path_str);
665-
sentry_free(path_str);
666-
#else
667-
sentry__jsonwriter_write_str(jw, path->path);
668-
#endif
657+
sentry_value_t obj = sentry_value_new_object();
658+
sentry_value_set_by_key(obj, "path", sentry__value_new_path(path));
669659
if (content_type) {
670-
sentry__jsonwriter_write_key(jw, "content_type");
671-
sentry__jsonwriter_write_str(jw, content_type);
660+
sentry_value_set_by_key(
661+
obj, "content_type", sentry_value_new_string(content_type));
672662
}
673-
sentry__jsonwriter_write_object_end(jw);
674-
sentry__jsonwriter_free(jw);
675663

676-
size_t payload_len = sentry__stringbuilder_len(&sb);
677-
char *payload = sentry__stringbuilder_into_string(&sb);
664+
sentry_jsonwriter_t *jw = sentry__jsonwriter_new_sb(NULL);
665+
sentry__jsonwriter_write_value(jw, obj);
666+
sentry_value_decref(obj);
667+
size_t payload_len = 0;
668+
char *payload = sentry__jsonwriter_into_string(jw, &payload_len);
678669
sentry__envelope_item_set_payload(item, payload, payload_len);
679670

680671
return item;
@@ -693,13 +684,7 @@ sentry__envelope_item_set_attachment_ref(
693684
obj = sentry_value_new_object();
694685
}
695686

696-
#ifdef SENTRY_PLATFORM_WINDOWS
697-
char *path_str = sentry__string_from_wstr(path->path_w);
698-
sentry_value_set_by_key(obj, "path", sentry_value_new_string(path_str));
699-
sentry_free(path_str);
700-
#else
701-
sentry_value_set_by_key(obj, "path", sentry_value_new_string(path->path));
702-
#endif
687+
sentry_value_set_by_key(obj, "path", sentry__value_new_path(path));
703688

704689
const char *ref_ct = sentry_value_as_string(
705690
sentry__envelope_item_get_header(item, "ref_content_type"));

0 commit comments

Comments
 (0)