This is an automated email from the ASF dual-hosted git repository.
github-bot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-nanoarrow.git
The following commit(s) were added to refs/heads/main by this push:
new ff15814 Update dist/ for commit
9447c63715d4ec371b81d6bcb5d34b1a869efd2c
ff15814 is described below
commit ff158147099a3c32c77b5c92437f38de4ff50b66
Author: GitHub Actions <[email protected]>
AuthorDate: Wed Mar 1 13:51:44 2023 +0000
Update dist/ for commit 9447c63715d4ec371b81d6bcb5d34b1a869efd2c
---
dist/nanoarrow.c | 105 ++++++++++++++++++++++++-------------------------------
dist/nanoarrow.h | 4 +--
2 files changed, 48 insertions(+), 61 deletions(-)
diff --git a/dist/nanoarrow.c b/dist/nanoarrow.c
index d96e6e9..8fb7994 100644
--- a/dist/nanoarrow.c
+++ b/dist/nanoarrow.c
@@ -24,9 +24,9 @@
#include "nanoarrow.h"
-const char* ArrowNanoarrowVersion() { return NANOARROW_VERSION; }
+const char* ArrowNanoarrowVersion(void) { return NANOARROW_VERSION; }
-int ArrowNanoarrowVersionInt() { return NANOARROW_VERSION_INT; }
+int ArrowNanoarrowVersionInt(void) { return NANOARROW_VERSION_INT; }
int ArrowErrorSet(struct ArrowError* error, const char* fmt, ...) {
if (error == NULL) {
@@ -1413,6 +1413,24 @@ static int64_t ArrowSchemaTypeToStringInternal(struct
ArrowSchemaView* schema_vi
}
}
+// Helper for bookeeping to emulate sprintf()-like behaviour spread
+// among multiple sprintf calls.
+static inline void ArrowToStringLogChars(char** out, int64_t n_chars_last,
+ int64_t* n_remaining, int64_t*
n_chars) {
+ *n_chars += n_chars_last;
+ *n_remaining -= n_chars_last;
+
+ // n_remaining is never less than 0
+ if (*n_remaining < 0) {
+ *n_remaining = 0;
+ }
+
+ // Can't do math on a NULL pointer
+ if (*out != NULL) {
+ *out += n_chars_last;
+ }
+}
+
int64_t ArrowSchemaToString(struct ArrowSchema* schema, char* out, int64_t n,
char recursive) {
if (schema == NULL) {
@@ -1439,90 +1457,59 @@ int64_t ArrowSchemaToString(struct ArrowSchema* schema,
char* out, int64_t n,
// Uncommon but not technically impossible that both are true
if (is_extension && is_dictionary) {
- n_chars_last = snprintf(out + n_chars, n, "%.*s{dictionary(%s)<",
- (int)schema_view.extension_name.size_bytes,
- schema_view.extension_name.data,
- ArrowTypeString(schema_view.storage_type));
+ n_chars_last = snprintf(
+ out, n, "%.*s{dictionary(%s)<",
(int)schema_view.extension_name.size_bytes,
+ schema_view.extension_name.data,
ArrowTypeString(schema_view.storage_type));
} else if (is_extension) {
- n_chars_last =
- snprintf(out + n_chars, n, "%.*s{",
(int)schema_view.extension_name.size_bytes,
- schema_view.extension_name.data);
+ n_chars_last = snprintf(out, n, "%.*s{",
(int)schema_view.extension_name.size_bytes,
+ schema_view.extension_name.data);
} else if (is_dictionary) {
- n_chars_last = snprintf(out + n_chars, n, "dictionary(%s)<",
- ArrowTypeString(schema_view.storage_type));
+ n_chars_last =
+ snprintf(out, n, "dictionary(%s)<",
ArrowTypeString(schema_view.storage_type));
}
- n_chars += n_chars_last;
- n -= n_chars_last;
- if (n < 0) {
- n = 0;
- }
+ ArrowToStringLogChars(&out, n_chars_last, &n, &n_chars);
if (!is_dictionary) {
- n_chars_last = ArrowSchemaTypeToStringInternal(&schema_view, out +
n_chars, n);
+ n_chars_last = ArrowSchemaTypeToStringInternal(&schema_view, out, n);
} else {
- n_chars_last = ArrowSchemaToString(schema->dictionary, out + n_chars, n,
recursive);
+ n_chars_last = ArrowSchemaToString(schema->dictionary, out, n, recursive);
}
- n_chars += n_chars_last;
- n -= n_chars_last;
- if (n < 0) {
- n = 0;
- }
+ ArrowToStringLogChars(&out, n_chars_last, &n, &n_chars);
if (recursive && schema->format[0] == '+') {
- n_chars_last = snprintf(out + n_chars, n, "<");
- n_chars += n_chars_last;
- n -= n_chars_last;
- if (n < 0) {
- n = 0;
- }
+ n_chars_last = snprintf(out, n, "<");
+ ArrowToStringLogChars(&out, n_chars_last, &n, &n_chars);
for (int64_t i = 0; i < schema->n_children; i++) {
if (i > 0) {
- n_chars_last = snprintf(out + n_chars, n, ", ");
- n_chars += n_chars_last;
- n -= n_chars_last;
- if (n < 0) {
- n = 0;
- }
+ n_chars_last = snprintf(out, n, ", ");
+ ArrowToStringLogChars(&out, n_chars_last, &n, &n_chars);
}
// ArrowSchemaToStringInternal() will validate the child and print the
error,
// but we need the name first
if (schema->children[i] != NULL && schema->children[i]->release != NULL
&&
schema->children[i]->name != NULL) {
- n_chars_last = snprintf(out + n_chars, n, "%s: ",
schema->children[i]->name);
- n_chars += n_chars_last;
- n -= n_chars_last;
- if (n < 0) {
- n = 0;
- }
+ n_chars_last = snprintf(out, n, "%s: ", schema->children[i]->name);
+ ArrowToStringLogChars(&out, n_chars_last, &n, &n_chars);
}
- n_chars_last =
- ArrowSchemaToString(schema->children[i], out + n_chars, n,
recursive);
- n_chars += n_chars_last;
- n -= n_chars_last;
- if (n < 0) {
- n = 0;
- }
+ n_chars_last = ArrowSchemaToString(schema->children[i], out, n,
recursive);
+ ArrowToStringLogChars(&out, n_chars_last, &n, &n_chars);
}
- n_chars_last = snprintf(out + n_chars, n, ">");
- n_chars += n_chars_last;
- n -= n_chars_last;
- if (n < 0) {
- n = 0;
- }
+ n_chars_last = snprintf(out, n, ">");
+ ArrowToStringLogChars(&out, n_chars_last, &n, &n_chars);
}
if (is_extension && is_dictionary) {
- n_chars += snprintf(out + n_chars, n, ">}");
+ n_chars += snprintf(out, n, ">}");
} else if (is_extension) {
- n_chars += snprintf(out + n_chars, n, "}");
+ n_chars += snprintf(out, n, "}");
} else if (is_dictionary) {
- n_chars += snprintf(out + n_chars, n, ">");
+ n_chars += snprintf(out, n, ">");
}
return n_chars;
@@ -2160,8 +2147,8 @@ static ArrowErrorCode ArrowArrayCheckInternalBufferSizes(
if (actual_size < expected_size) {
ArrowErrorSet(
error,
- "Expected buffer %d to size >= %ld bytes but found buffer with %ld
bytes", i,
- (long)expected_size, (long)actual_size);
+ "Expected buffer %d to size >= %ld bytes but found buffer with %ld
bytes",
+ (int)i, (long)expected_size, (long)actual_size);
return EINVAL;
}
}
diff --git a/dist/nanoarrow.h b/dist/nanoarrow.h
index 8fd74a0..c895063 100644
--- a/dist/nanoarrow.h
+++ b/dist/nanoarrow.h
@@ -774,10 +774,10 @@ const char* ArrowErrorMessage(struct ArrowError* error);
/// @{
/// \brief Return a version string in the form "major.minor.patch"
-const char* ArrowNanoarrowVersion();
+const char* ArrowNanoarrowVersion(void);
/// \brief Return an integer that can be used to compare versions sequentially
-int ArrowNanoarrowVersionInt();
+int ArrowNanoarrowVersionInt(void);
/// \brief Initialize a description of buffer arrangements from a storage type
void ArrowLayoutInit(struct ArrowLayout* layout, enum ArrowType storage_type);