This is an automated email from the ASF dual-hosted git repository.
paleolimbot 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 4744498 fix: Add `const` qualifier where appropriate in struct fields
and declarations (#327)
4744498 is described below
commit 4744498daf166bc3ae8d34d157a2598002447d4e
Author: Dewey Dunnington <[email protected]>
AuthorDate: Wed Nov 29 16:53:44 2023 -0400
fix: Add `const` qualifier where appropriate in struct fields and
declarations (#327)
A number of functions accept pointers (e.g., `ArrowSchema*`) but do not
take ownership of the argument or modify it in any way. To better
communicate this, this PR adds `const` before all possible parameters
that are not modified by the function.
Closes #215.
---
r/src/materialize.c | 8 +++---
src/nanoarrow/array.c | 12 ++++-----
src/nanoarrow/array_inline.h | 51 +++++++++++++++++++-------------------
src/nanoarrow/array_stream.c | 2 +-
src/nanoarrow/nanoarrow.h | 55 ++++++++++++++++++++++-------------------
src/nanoarrow/nanoarrow_types.h | 9 ++++---
src/nanoarrow/schema.c | 7 +++---
7 files changed, 75 insertions(+), 69 deletions(-)
diff --git a/r/src/materialize.c b/r/src/materialize.c
index b86b54d..f1c89db 100644
--- a/r/src/materialize.c
+++ b/r/src/materialize.c
@@ -285,13 +285,13 @@ static int nanoarrow_materialize_other(struct RConverter*
converter,
// the underlying array to be released and invalidate the converter. The R
code in
// convert_fallback_other() takes care of ensuring an independent copy with
the correct
// offset/length.
- SEXP schema_xptr =
- PROTECT(R_MakeExternalPtr(converter->schema_view.schema, R_NilValue,
R_NilValue));
+ SEXP schema_xptr = PROTECT(R_MakeExternalPtr(
+ (struct ArrowSchema*)converter->schema_view.schema, R_NilValue,
R_NilValue));
Rf_setAttrib(schema_xptr, R_ClassSymbol, nanoarrow_cls_schema);
// We do need to set the protected member of the array external pointer to
signal that
// it is not an independent array (i.e., force a shallow copy).
- SEXP array_xptr = PROTECT(
- R_MakeExternalPtr(converter->array_view.array, schema_xptr,
converter_xptr));
+ SEXP array_xptr = PROTECT(R_MakeExternalPtr(
+ (struct ArrowArray*)converter->array_view.array, schema_xptr,
converter_xptr));
Rf_setAttrib(array_xptr, R_ClassSymbol, nanoarrow_cls_array);
SEXP offset_sexp =
diff --git a/src/nanoarrow/array.c b/src/nanoarrow/array.c
index a0e711e..366b8bf 100644
--- a/src/nanoarrow/array.c
+++ b/src/nanoarrow/array.c
@@ -166,7 +166,7 @@ ArrowErrorCode ArrowArrayInitFromType(struct ArrowArray*
array,
}
ArrowErrorCode ArrowArrayInitFromArrayView(struct ArrowArray* array,
- struct ArrowArrayView* array_view,
+ const struct ArrowArrayView*
array_view,
struct ArrowError* error) {
NANOARROW_RETURN_NOT_OK_WITH_ERROR(
ArrowArrayInitFromType(array, array_view->storage_type), error);
@@ -212,7 +212,7 @@ ArrowErrorCode ArrowArrayInitFromArrayView(struct
ArrowArray* array,
}
ArrowErrorCode ArrowArrayInitFromSchema(struct ArrowArray* array,
- struct ArrowSchema* schema,
+ const struct ArrowSchema* schema,
struct ArrowError* error) {
struct ArrowArrayView array_view;
NANOARROW_RETURN_NOT_OK(ArrowArrayViewInitFromSchema(&array_view, schema,
error));
@@ -535,7 +535,7 @@ ArrowErrorCode ArrowArrayViewAllocateDictionary(struct
ArrowArrayView* array_vie
}
ArrowErrorCode ArrowArrayViewInitFromSchema(struct ArrowArrayView* array_view,
- struct ArrowSchema* schema,
+ const struct ArrowSchema* schema,
struct ArrowError* error) {
struct ArrowSchemaView schema_view;
int result = ArrowSchemaViewInit(&schema_view, schema, error);
@@ -669,7 +669,7 @@ void ArrowArrayViewSetLength(struct ArrowArrayView*
array_view, int64_t length)
// This version recursively extracts information from the array and stores it
// in the array view, performing any checks that require the original array.
static int ArrowArrayViewSetArrayInternal(struct ArrowArrayView* array_view,
- struct ArrowArray* array,
+ const struct ArrowArray* array,
struct ArrowError* error) {
array_view->array = array;
array_view->offset = array->offset;
@@ -1008,7 +1008,7 @@ static int ArrowArrayViewValidateDefault(struct
ArrowArrayView* array_view,
}
ArrowErrorCode ArrowArrayViewSetArray(struct ArrowArrayView* array_view,
- struct ArrowArray* array,
+ const struct ArrowArray* array,
struct ArrowError* error) {
// Extract information from the array into the array view
NANOARROW_RETURN_NOT_OK(ArrowArrayViewSetArrayInternal(array_view, array,
error));
@@ -1021,7 +1021,7 @@ ArrowErrorCode ArrowArrayViewSetArray(struct
ArrowArrayView* array_view,
}
ArrowErrorCode ArrowArrayViewSetArrayMinimal(struct ArrowArrayView* array_view,
- struct ArrowArray* array,
+ const struct ArrowArray* array,
struct ArrowError* error) {
// Extract information from the array into the array view
NANOARROW_RETURN_NOT_OK(ArrowArrayViewSetArrayInternal(array_view, array,
error));
diff --git a/src/nanoarrow/array_inline.h b/src/nanoarrow/array_inline.h
index c089d2b..1a844c0 100644
--- a/src/nanoarrow/array_inline.h
+++ b/src/nanoarrow/array_inline.h
@@ -530,7 +530,7 @@ static inline ArrowErrorCode ArrowArrayAppendString(struct
ArrowArray* array,
}
static inline ArrowErrorCode ArrowArrayAppendInterval(struct ArrowArray* array,
- struct ArrowInterval*
value) {
+ const struct
ArrowInterval* value) {
struct ArrowArrayPrivateData* private_data =
(struct ArrowArrayPrivateData*)array->private_data;
@@ -573,7 +573,7 @@ static inline ArrowErrorCode
ArrowArrayAppendInterval(struct ArrowArray* array,
}
static inline ArrowErrorCode ArrowArrayAppendDecimal(struct ArrowArray* array,
- struct ArrowDecimal*
value) {
+ const struct
ArrowDecimal* value) {
struct ArrowArrayPrivateData* private_data =
(struct ArrowArrayPrivateData*)array->private_data;
struct ArrowBuffer* data_buffer = ArrowArrayBuffer(array, 1);
@@ -705,7 +705,8 @@ static inline void ArrowArrayViewMove(struct
ArrowArrayView* src,
ArrowArrayViewInitFromType(src, NANOARROW_TYPE_UNINITIALIZED);
}
-static inline int8_t ArrowArrayViewIsNull(struct ArrowArrayView* array_view,
int64_t i) {
+static inline int8_t ArrowArrayViewIsNull(const struct ArrowArrayView*
array_view,
+ int64_t i) {
const uint8_t* validity_buffer = array_view->buffer_views[0].data.as_uint8;
i += array_view->offset;
switch (array_view->storage_type) {
@@ -720,7 +721,7 @@ static inline int8_t ArrowArrayViewIsNull(struct
ArrowArrayView* array_view, int
}
}
-static inline int8_t ArrowArrayViewUnionTypeId(struct ArrowArrayView*
array_view,
+static inline int8_t ArrowArrayViewUnionTypeId(const struct ArrowArrayView*
array_view,
int64_t i) {
switch (array_view->storage_type) {
case NANOARROW_TYPE_DENSE_UNION:
@@ -731,8 +732,8 @@ static inline int8_t ArrowArrayViewUnionTypeId(struct
ArrowArrayView* array_view
}
}
-static inline int8_t ArrowArrayViewUnionChildIndex(struct ArrowArrayView*
array_view,
- int64_t i) {
+static inline int8_t ArrowArrayViewUnionChildIndex(
+ const struct ArrowArrayView* array_view, int64_t i) {
int8_t type_id = ArrowArrayViewUnionTypeId(array_view, i);
if (array_view->union_type_id_map == NULL) {
return type_id;
@@ -741,8 +742,8 @@ static inline int8_t ArrowArrayViewUnionChildIndex(struct
ArrowArrayView* array_
}
}
-static inline int64_t ArrowArrayViewUnionChildOffset(struct ArrowArrayView*
array_view,
- int64_t i) {
+static inline int64_t ArrowArrayViewUnionChildOffset(
+ const struct ArrowArrayView* array_view, int64_t i) {
switch (array_view->storage_type) {
case NANOARROW_TYPE_DENSE_UNION:
return array_view->buffer_views[1].data.as_int32[i];
@@ -753,8 +754,8 @@ static inline int64_t ArrowArrayViewUnionChildOffset(struct
ArrowArrayView* arra
}
}
-static inline int64_t ArrowArrayViewListChildOffset(struct ArrowArrayView*
array_view,
- int64_t i) {
+static inline int64_t ArrowArrayViewListChildOffset(
+ const struct ArrowArrayView* array_view, int64_t i) {
switch (array_view->storage_type) {
case NANOARROW_TYPE_LIST:
return array_view->buffer_views[1].data.as_int32[i];
@@ -765,9 +766,9 @@ static inline int64_t ArrowArrayViewListChildOffset(struct
ArrowArrayView* array
}
}
-static inline int64_t ArrowArrayViewGetIntUnsafe(struct ArrowArrayView*
array_view,
+static inline int64_t ArrowArrayViewGetIntUnsafe(const struct ArrowArrayView*
array_view,
int64_t i) {
- struct ArrowBufferView* data_view = &array_view->buffer_views[1];
+ const struct ArrowBufferView* data_view = &array_view->buffer_views[1];
i += array_view->offset;
switch (array_view->storage_type) {
case NANOARROW_TYPE_INT64:
@@ -797,10 +798,10 @@ static inline int64_t ArrowArrayViewGetIntUnsafe(struct
ArrowArrayView* array_vi
}
}
-static inline uint64_t ArrowArrayViewGetUIntUnsafe(struct ArrowArrayView*
array_view,
- int64_t i) {
+static inline uint64_t ArrowArrayViewGetUIntUnsafe(
+ const struct ArrowArrayView* array_view, int64_t i) {
i += array_view->offset;
- struct ArrowBufferView* data_view = &array_view->buffer_views[1];
+ const struct ArrowBufferView* data_view = &array_view->buffer_views[1];
switch (array_view->storage_type) {
case NANOARROW_TYPE_INT64:
return data_view->data.as_int64[i];
@@ -829,10 +830,10 @@ static inline uint64_t ArrowArrayViewGetUIntUnsafe(struct
ArrowArrayView* array_
}
}
-static inline double ArrowArrayViewGetDoubleUnsafe(struct ArrowArrayView*
array_view,
- int64_t i) {
+static inline double ArrowArrayViewGetDoubleUnsafe(
+ const struct ArrowArrayView* array_view, int64_t i) {
i += array_view->offset;
- struct ArrowBufferView* data_view = &array_view->buffer_views[1];
+ const struct ArrowBufferView* data_view = &array_view->buffer_views[1];
switch (array_view->storage_type) {
case NANOARROW_TYPE_INT64:
return (double)data_view->data.as_int64[i];
@@ -862,9 +863,9 @@ static inline double ArrowArrayViewGetDoubleUnsafe(struct
ArrowArrayView* array_
}
static inline struct ArrowStringView ArrowArrayViewGetStringUnsafe(
- struct ArrowArrayView* array_view, int64_t i) {
+ const struct ArrowArrayView* array_view, int64_t i) {
i += array_view->offset;
- struct ArrowBufferView* offsets_view = &array_view->buffer_views[1];
+ const struct ArrowBufferView* offsets_view = &array_view->buffer_views[1];
const char* data_view = array_view->buffer_views[2].data.as_char;
struct ArrowStringView view;
@@ -895,9 +896,9 @@ static inline struct ArrowStringView
ArrowArrayViewGetStringUnsafe(
}
static inline struct ArrowBufferView ArrowArrayViewGetBytesUnsafe(
- struct ArrowArrayView* array_view, int64_t i) {
+ const struct ArrowArrayView* array_view, int64_t i) {
i += array_view->offset;
- struct ArrowBufferView* offsets_view = &array_view->buffer_views[1];
+ const struct ArrowBufferView* offsets_view = &array_view->buffer_views[1];
const uint8_t* data_view = array_view->buffer_views[2].data.as_uint8;
struct ArrowBufferView view;
@@ -928,8 +929,8 @@ static inline struct ArrowBufferView
ArrowArrayViewGetBytesUnsafe(
return view;
}
-static inline void ArrowArrayViewGetIntervalUnsafe(struct ArrowArrayView*
array_view,
- int64_t i, struct
ArrowInterval* out) {
+static inline void ArrowArrayViewGetIntervalUnsafe(
+ const struct ArrowArrayView* array_view, int64_t i, struct ArrowInterval*
out) {
const uint8_t* data_view = array_view->buffer_views[1].data.as_uint8;
switch (array_view->storage_type) {
case NANOARROW_TYPE_INTERVAL_MONTHS: {
@@ -955,7 +956,7 @@ static inline void ArrowArrayViewGetIntervalUnsafe(struct
ArrowArrayView* array_
}
}
-static inline void ArrowArrayViewGetDecimalUnsafe(struct ArrowArrayView*
array_view,
+static inline void ArrowArrayViewGetDecimalUnsafe(const struct ArrowArrayView*
array_view,
int64_t i, struct
ArrowDecimal* out) {
i += array_view->offset;
const uint8_t* data_view = array_view->buffer_views[1].data.as_uint8;
diff --git a/src/nanoarrow/array_stream.c b/src/nanoarrow/array_stream.c
index b230d18..fc311ba 100644
--- a/src/nanoarrow/array_stream.c
+++ b/src/nanoarrow/array_stream.c
@@ -129,7 +129,7 @@ void ArrowBasicArrayStreamSetArray(struct ArrowArrayStream*
array_stream, int64_
ArrowArrayMove(array, &private_data->arrays[i]);
}
-ArrowErrorCode ArrowBasicArrayStreamValidate(struct ArrowArrayStream*
array_stream,
+ArrowErrorCode ArrowBasicArrayStreamValidate(const struct ArrowArrayStream*
array_stream,
struct ArrowError* error) {
struct BasicArrayStreamPrivate* private_data =
(struct BasicArrayStreamPrivate*)array_stream->private_data;
diff --git a/src/nanoarrow/nanoarrow.h b/src/nanoarrow/nanoarrow.h
index 11bf6bb..f49ba5e 100644
--- a/src/nanoarrow/nanoarrow.h
+++ b/src/nanoarrow/nanoarrow.h
@@ -276,7 +276,7 @@ ArrowErrorCode ArrowSchemaInitFromType(struct ArrowSchema*
schema, enum ArrowTyp
/// and returns the number of characters required for the output if
/// n were sufficiently large. If recursive is non-zero, the result will
/// also include children.
-int64_t ArrowSchemaToString(struct ArrowSchema* schema, char* out, int64_t n,
+int64_t ArrowSchemaToString(const struct ArrowSchema* schema, char* out,
int64_t n,
char recursive);
/// \brief Set the format field of a schema from an ArrowType
@@ -338,7 +338,7 @@ ArrowErrorCode ArrowSchemaSetTypeUnion(struct ArrowSchema*
schema, enum ArrowTyp
/// \brief Make a (recursive) copy of a schema
///
/// Allocates and copies fields of schema into schema_out.
-ArrowErrorCode ArrowSchemaDeepCopy(struct ArrowSchema* schema,
+ArrowErrorCode ArrowSchemaDeepCopy(const struct ArrowSchema* schema,
struct ArrowSchema* schema_out);
/// \brief Copy format into schema->format
@@ -453,7 +453,7 @@ ArrowErrorCode ArrowMetadataBuilderRemove(struct
ArrowBuffer* buffer,
/// compatibility.
struct ArrowSchemaView {
/// \brief A pointer to the schema represented by this view
- struct ArrowSchema* schema;
+ const struct ArrowSchema* schema;
/// \brief The data type represented by the schema
///
@@ -536,7 +536,8 @@ struct ArrowSchemaView {
/// \brief Initialize an ArrowSchemaView
ArrowErrorCode ArrowSchemaViewInit(struct ArrowSchemaView* schema_view,
- struct ArrowSchema* schema, struct
ArrowError* error);
+ const struct ArrowSchema* schema,
+ struct ArrowError* error);
/// @}
@@ -765,7 +766,7 @@ ArrowErrorCode ArrowArrayInitFromType(struct ArrowArray*
array,
/// Caller is responsible for calling the array->release callback if
/// NANOARROW_OK is returned.
ArrowErrorCode ArrowArrayInitFromSchema(struct ArrowArray* array,
- struct ArrowSchema* schema,
+ const struct ArrowSchema* schema,
struct ArrowError* error);
/// \brief Initialize the contents of an ArrowArray from an ArrowArrayView
@@ -773,7 +774,7 @@ ArrowErrorCode ArrowArrayInitFromSchema(struct ArrowArray*
array,
/// Caller is responsible for calling the array->release callback if
/// NANOARROW_OK is returned.
ArrowErrorCode ArrowArrayInitFromArrayView(struct ArrowArray* array,
- struct ArrowArrayView* array_view,
+ const struct ArrowArrayView*
array_view,
struct ArrowError* error);
/// \brief Allocate the array->children array
@@ -886,14 +887,14 @@ static inline ArrowErrorCode
ArrowArrayAppendString(struct ArrowArray* array,
/// Returns NANOARROW_OK if value can be exactly represented by
/// the underlying storage type or EINVAL otherwise.
static inline ArrowErrorCode ArrowArrayAppendInterval(struct ArrowArray* array,
- struct ArrowInterval*
value);
+ const struct
ArrowInterval* value);
/// \brief Append a decimal value to an array
///
/// Returns NANOARROW_OK if array is a decimal array with the appropriate
/// bitwidth or EINVAL otherwise.
static inline ArrowErrorCode ArrowArrayAppendDecimal(struct ArrowArray* array,
- struct ArrowDecimal*
value);
+ const struct
ArrowDecimal* value);
/// \brief Finish a nested array element
///
@@ -961,7 +962,7 @@ static inline void ArrowArrayViewMove(struct
ArrowArrayView* src,
/// \brief Initialize the contents of an ArrowArrayView from an ArrowSchema
ArrowErrorCode ArrowArrayViewInitFromSchema(struct ArrowArrayView* array_view,
- struct ArrowSchema* schema,
+ const struct ArrowSchema* schema,
struct ArrowError* error);
/// \brief Allocate the array_view->children array
@@ -978,12 +979,13 @@ void ArrowArrayViewSetLength(struct ArrowArrayView*
array_view, int64_t length);
/// \brief Set buffer sizes and data pointers from an ArrowArray
ArrowErrorCode ArrowArrayViewSetArray(struct ArrowArrayView* array_view,
- struct ArrowArray* array, struct
ArrowError* error);
+ const struct ArrowArray* array,
+ struct ArrowError* error);
/// \brief Set buffer sizes and data pointers from an ArrowArray except for
those
/// that require dereferencing buffer content.
ArrowErrorCode ArrowArrayViewSetArrayMinimal(struct ArrowArrayView* array_view,
- struct ArrowArray* array,
+ const struct ArrowArray* array,
struct ArrowError* error);
/// \brief Performs checks on the content of an ArrowArrayView
@@ -1002,59 +1004,60 @@ ArrowErrorCode ArrowArrayViewValidate(struct
ArrowArrayView* array_view,
void ArrowArrayViewReset(struct ArrowArrayView* array_view);
/// \brief Check for a null element in an ArrowArrayView
-static inline int8_t ArrowArrayViewIsNull(struct ArrowArrayView* array_view,
int64_t i);
+static inline int8_t ArrowArrayViewIsNull(const struct ArrowArrayView*
array_view,
+ int64_t i);
/// \brief Get the type id of a union array element
-static inline int8_t ArrowArrayViewUnionTypeId(struct ArrowArrayView*
array_view,
+static inline int8_t ArrowArrayViewUnionTypeId(const struct ArrowArrayView*
array_view,
int64_t i);
/// \brief Get the child index of a union array element
-static inline int8_t ArrowArrayViewUnionChildIndex(struct ArrowArrayView*
array_view,
- int64_t i);
+static inline int8_t ArrowArrayViewUnionChildIndex(
+ const struct ArrowArrayView* array_view, int64_t i);
/// \brief Get the index to use into the relevant union child array
-static inline int64_t ArrowArrayViewUnionChildOffset(struct ArrowArrayView*
array_view,
- int64_t i);
+static inline int64_t ArrowArrayViewUnionChildOffset(
+ const struct ArrowArrayView* array_view, int64_t i);
/// \brief Get an element in an ArrowArrayView as an integer
///
/// This function does not check for null values, that values are actually
integers, or
/// that values are within a valid range for an int64.
-static inline int64_t ArrowArrayViewGetIntUnsafe(struct ArrowArrayView*
array_view,
+static inline int64_t ArrowArrayViewGetIntUnsafe(const struct ArrowArrayView*
array_view,
int64_t i);
/// \brief Get an element in an ArrowArrayView as an unsigned integer
///
/// This function does not check for null values, that values are actually
integers, or
/// that values are within a valid range for a uint64.
-static inline uint64_t ArrowArrayViewGetUIntUnsafe(struct ArrowArrayView*
array_view,
- int64_t i);
+static inline uint64_t ArrowArrayViewGetUIntUnsafe(
+ const struct ArrowArrayView* array_view, int64_t i);
/// \brief Get an element in an ArrowArrayView as a double
///
/// This function does not check for null values, or
/// that values are within a valid range for a double.
-static inline double ArrowArrayViewGetDoubleUnsafe(struct ArrowArrayView*
array_view,
- int64_t i);
+static inline double ArrowArrayViewGetDoubleUnsafe(
+ const struct ArrowArrayView* array_view, int64_t i);
/// \brief Get an element in an ArrowArrayView as an ArrowStringView
///
/// This function does not check for null values.
static inline struct ArrowStringView ArrowArrayViewGetStringUnsafe(
- struct ArrowArrayView* array_view, int64_t i);
+ const struct ArrowArrayView* array_view, int64_t i);
/// \brief Get an element in an ArrowArrayView as an ArrowBufferView
///
/// This function does not check for null values.
static inline struct ArrowBufferView ArrowArrayViewGetBytesUnsafe(
- struct ArrowArrayView* array_view, int64_t i);
+ const struct ArrowArrayView* array_view, int64_t i);
/// \brief Get an element in an ArrowArrayView as an ArrowDecimal
///
/// This function does not check for null values. The out parameter must
/// be initialized with ArrowDecimalInit() with the proper parameters for this
/// type before calling this for the first time.
-static inline void ArrowArrayViewGetDecimalUnsafe(struct ArrowArrayView*
array_view,
+static inline void ArrowArrayViewGetDecimalUnsafe(const struct ArrowArrayView*
array_view,
int64_t i, struct
ArrowDecimal* out);
/// @}
@@ -1091,7 +1094,7 @@ void ArrowBasicArrayStreamSetArray(struct
ArrowArrayStream* array_stream, int64_
/// array_stream must have been initialized with ArrowBasicArrayStreamInit().
/// This function uses ArrowArrayStreamInitFromSchema() and
ArrowArrayStreamSetArray()
/// to validate the contents of the arrays.
-ArrowErrorCode ArrowBasicArrayStreamValidate(struct ArrowArrayStream*
array_stream,
+ArrowErrorCode ArrowBasicArrayStreamValidate(const struct ArrowArrayStream*
array_stream,
struct ArrowError* error);
/// @}
diff --git a/src/nanoarrow/nanoarrow_types.h b/src/nanoarrow/nanoarrow_types.h
index 2ea16b2..c4b9d0e 100644
--- a/src/nanoarrow/nanoarrow_types.h
+++ b/src/nanoarrow/nanoarrow_types.h
@@ -594,7 +594,7 @@ struct ArrowLayout {
struct ArrowArrayView {
/// \brief The underlying ArrowArray or NULL if it has not been set or
/// if the buffers in this ArrowArrayView are not backed by an ArrowArray.
- struct ArrowArray* array;
+ const struct ArrowArray* array;
/// \brief The number of elements from the physical start of the buffers.
int64_t offset;
@@ -736,19 +736,20 @@ static inline void ArrowDecimalInit(struct ArrowDecimal*
decimal, int32_t bitwid
/// This does not check if the decimal's precision sufficiently small to fit
/// within the signed 64-bit integer range (A precision less than or equal
/// to 18 is sufficiently small).
-static inline int64_t ArrowDecimalGetIntUnsafe(struct ArrowDecimal* decimal) {
+static inline int64_t ArrowDecimalGetIntUnsafe(const struct ArrowDecimal*
decimal) {
return (int64_t)decimal->words[decimal->low_word_index];
}
/// \brief Copy the bytes of this decimal into a sufficiently large buffer
/// \ingroup nanoarrow-utils
-static inline void ArrowDecimalGetBytes(struct ArrowDecimal* decimal, uint8_t*
out) {
+static inline void ArrowDecimalGetBytes(const struct ArrowDecimal* decimal,
+ uint8_t* out) {
memcpy(out, decimal->words, decimal->n_words * sizeof(uint64_t));
}
/// \brief Returns 1 if the value represented by decimal is >= 0 or -1
otherwise
/// \ingroup nanoarrow-utils
-static inline int64_t ArrowDecimalSign(struct ArrowDecimal* decimal) {
+static inline int64_t ArrowDecimalSign(const struct ArrowDecimal* decimal) {
return 1 | ((int64_t)(decimal->words[decimal->high_word_index]) >> 63);
}
diff --git a/src/nanoarrow/schema.c b/src/nanoarrow/schema.c
index 75b078f..a2b59db 100644
--- a/src/nanoarrow/schema.c
+++ b/src/nanoarrow/schema.c
@@ -483,7 +483,7 @@ ArrowErrorCode ArrowSchemaAllocateDictionary(struct
ArrowSchema* schema) {
return NANOARROW_OK;
}
-ArrowErrorCode ArrowSchemaDeepCopy(struct ArrowSchema* schema,
+ArrowErrorCode ArrowSchemaDeepCopy(const struct ArrowSchema* schema,
struct ArrowSchema* schema_out) {
ArrowSchemaInit(schema_out);
@@ -1103,7 +1103,8 @@ static ArrowErrorCode ArrowSchemaViewValidate(struct
ArrowSchemaView* schema_vie
}
ArrowErrorCode ArrowSchemaViewInit(struct ArrowSchemaView* schema_view,
- struct ArrowSchema* schema, struct
ArrowError* error) {
+ const struct ArrowSchema* schema,
+ struct ArrowError* error) {
if (schema == NULL) {
ArrowErrorSet(error, "Expected non-NULL schema");
return EINVAL;
@@ -1229,7 +1230,7 @@ static inline void ArrowToStringLogChars(char** out,
int64_t n_chars_last,
}
}
-int64_t ArrowSchemaToString(struct ArrowSchema* schema, char* out, int64_t n,
+int64_t ArrowSchemaToString(const struct ArrowSchema* schema, char* out,
int64_t n,
char recursive) {
if (schema == NULL) {
return snprintf(out, n, "[invalid: pointer is null]");