Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Add `sentry_value_new_feedback` and `sentry_capture_feedback` to allow capturing [User Feedback](https://develop.sentry.dev/sdk/data-model/envelope-items/#user-feedback). ([#1304](https://github.com/getsentry/sentry-native/pull/1304))
- Deprecate `sentry_value_new_user_feedback` and `sentry_capture_user_feedback` in favor of the new API.
- Add `sentry_envelope_read_from_file`, `sentry_envelope_get_header`, and `sentry_capture_envelope`. ([#1320](https://github.com/getsentry/sentry-native/pull/1320))
- Add `(u)int64` `sentry_value_t` type. ([#1326](https://github.com/getsentry/sentry-native/pull/1326))

**Fixes**:

Expand Down
22 changes: 22 additions & 0 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ typedef enum {
SENTRY_VALUE_TYPE_NULL,
SENTRY_VALUE_TYPE_BOOL,
SENTRY_VALUE_TYPE_INT32,
SENTRY_VALUE_TYPE_INT64,
SENTRY_VALUE_TYPE_UINT64,
SENTRY_VALUE_TYPE_DOUBLE,
SENTRY_VALUE_TYPE_STRING,
SENTRY_VALUE_TYPE_LIST,
Expand Down Expand Up @@ -250,6 +252,16 @@ SENTRY_API sentry_value_t sentry_value_new_null(void);
*/
SENTRY_API sentry_value_t sentry_value_new_int32(int32_t value);

/**
* Creates a new 64-bit signed integer value.
*/
SENTRY_API sentry_value_t sentry_value_new_int64(int64_t value);

/**
* Creates a new 64-bit unsigned integer value.
*/
SENTRY_API sentry_value_t sentry_value_new_uint64(uint64_t value);

/**
* Creates a new double value.
*/
Expand Down Expand Up @@ -388,6 +400,16 @@ SENTRY_API size_t sentry_value_get_length(sentry_value_t value);
*/
SENTRY_API int32_t sentry_value_as_int32(sentry_value_t value);

/**
* Converts a value into a 64-bit signed integer.
*/
SENTRY_API int64_t sentry_value_as_int64(sentry_value_t value);

/**
* Converts a value into a 64-bit unsigned integer.
*/
SENTRY_API uint64_t sentry_value_as_uint64(sentry_value_t value);

/**
* Converts a value into a double value.
*/
Expand Down
8 changes: 4 additions & 4 deletions ndk/lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ android {
dependencies {
compileOnly("org.jetbrains:annotations:23.0.0")

testImplementation("androidx.test.ext:junit:1.2.1")
testImplementation("androidx.test.ext:junit:1.3.0")

androidTestImplementation("androidx.test:runner:1.6.2")
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test:rules:1.6.1")
androidTestImplementation("androidx.test:runner:1.7.0")
androidTestImplementation("androidx.test.ext:junit:1.3.0")
androidTestImplementation("androidx.test:rules:1.7.0")
}

/*
Expand Down
67 changes: 57 additions & 10 deletions src/sentry_json.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -367,6 +368,30 @@ sentry__jsonwriter_write_int32(sentry_jsonwriter_t *jw, int32_t val)
}
}

void
sentry__jsonwriter_write_int64(sentry_jsonwriter_t *jw, int64_t val)
{
if (can_write_item(jw)) {
char buf[24];
snprintf(buf, sizeof(buf), "%" PRId64, val);
write_str(jw, buf);
}
}

void
sentry__jsonwriter_write_uint64(sentry_jsonwriter_t *jw, uint64_t val)
{
// TODO currently all uint64 values should be sent as strings; update when
// this changes and 64-bit unsigned integers can be ingested properly
// see
// https://github.com/getsentry/sentry-native/pull/1326#discussion_r2241965997
if (can_write_item(jw)) {
char buf[26];
snprintf(buf, sizeof(buf), "\"%" PRIu64 "\"", val);
write_str(jw, buf);
}
}

void
sentry__jsonwriter_write_double(sentry_jsonwriter_t *jw, double val)
{
Expand Down Expand Up @@ -592,17 +617,39 @@ tokens_to_value(jsmntok_t *tokens, size_t token_count, const char *buf,
rv = sentry_value_new_null();
break;
default: {
double val = sentry__strtod_c(buf + root->start, NULL);
#ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wfloat-equal"
#endif
if (val == (double)(int32_t)val) {
#ifdef __clang__
# pragma clang diagnostic pop
#endif
rv = sentry_value_new_int32((int32_t)val);
bool success = false;
char *endptr;
errno = 0;

if (buf[root->start] == '-') {
const long long ll_val
= strtoll(buf + root->start, &endptr, 10);
if (endptr == buf + root->end && errno == 0) {
if (ll_val >= INT32_MIN && ll_val <= INT32_MAX) {
rv = sentry_value_new_int32((int32_t)ll_val);
} else {
rv = sentry_value_new_int64((int64_t)ll_val);
}
success = true;
}
} else {
const unsigned long long ull_val
= strtoull(buf + root->start, &endptr, 10);
if (endptr == buf + root->end && errno == 0) {
if (ull_val <= INT32_MAX) {
rv = sentry_value_new_int32((int32_t)ull_val);
} else if (ull_val <= INT64_MAX) {
rv = sentry_value_new_int64((int64_t)ull_val);
} else {
rv = sentry_value_new_uint64((uint64_t)ull_val);
}
success = true;
}
}

// Both failed, fallback to double
if (!success) {
double val = sentry__strtod_c(buf + root->start, NULL);
rv = sentry_value_new_double(val);
}
break;
Expand Down
10 changes: 10 additions & 0 deletions src/sentry_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ void sentry__jsonwriter_write_bool(sentry_jsonwriter_t *jw, bool val);
*/
void sentry__jsonwriter_write_int32(sentry_jsonwriter_t *jw, int32_t val);

/**
* Write a 64-bit signed integer, encoded as JSON number.
*/
void sentry__jsonwriter_write_int64(sentry_jsonwriter_t *jw, int64_t val);

/**
* Write a 64-bit unsigned integer, encoded as JSON number.
*/
void sentry__jsonwriter_write_uint64(sentry_jsonwriter_t *jw, uint64_t val);

/**
* Write a 64-bit float, encoded as JSON number.
*/
Expand Down
Loading
Loading