diff --git a/examples/benchmark_write.c b/examples/benchmark_write.c index f1e6efc..4c92f04 100644 --- a/examples/benchmark_write.c +++ b/examples/benchmark_write.c @@ -62,7 +62,7 @@ void flush_writes() { #endif } -void delete_file(char* file_name) { +void delete_file(const char* file_name) { char command[2048]; snprintf(command, 2047, "rm %s", file_name); int rv = system(command); diff --git a/examples/mtx2bsp.c b/examples/mtx2bsp.c index 2ddc93b..7de6d8f 100644 --- a/examples/mtx2bsp.c +++ b/examples/mtx2bsp.c @@ -70,8 +70,8 @@ int main(int argc, char** argv) { compression_level = atoi(argv[4]); } - char* input_file_extension = bsp_get_file_extension(input_fname); - char* output_file_extension = bsp_get_file_extension(output_fname); + const char* input_file_extension = bsp_get_file_extension(input_fname); + const char* output_file_extension = bsp_get_file_extension(output_fname); if (input_file_extension == NULL || strcmp(input_file_extension, ".mtx") != 0) { diff --git a/examples/simple_matrix_read.c b/examples/simple_matrix_read.c index 7d4c0c3..aaa8884 100644 --- a/examples/simple_matrix_read.c +++ b/examples/simple_matrix_read.c @@ -1,14 +1,14 @@ #include int main(int argc, char** argv) { - char* file_name = "test.hdf5"; + const char* file_name = "test.hdf5"; bsp_matrix_t mat = bsp_read_matrix(file_name, NULL); if (mat.format == BSP_COO) { - float* values = mat.values.data; - int* rowind = mat.indices_0.data; - int* colind = mat.indices_1.data; + float* values = (float*) mat.values.data; + int* rowind = (int*) mat.indices_0.data; + int* colind = (int*) mat.indices_1.data; for (size_t i = 0; i < mat.nnz; i++) { printf("%d, %d: %f\n", rowind[i], colind[i], values[i]); diff --git a/examples/simple_matrix_write.c b/examples/simple_matrix_write.c index 88ac963..bf551d2 100644 --- a/examples/simple_matrix_write.c +++ b/examples/simple_matrix_write.c @@ -7,9 +7,9 @@ int main(int argc, char** argv) { bsp_matrix_t mat = bsp_generate_coo(m, n, nnz, BSP_FLOAT32, BSP_INT32); - float* values = mat.values.data; - int* rowind = mat.indices_0.data; - int* colind = mat.indices_1.data; + float* values = (float*) mat.values.data; + int* rowind = (int*) mat.indices_0.data; + int* colind = (int*) mat.indices_1.data; for (size_t i = 0; i < nnz; i++) { printf("%d, %d: %f\n", rowind[i], colind[i], values[i]); diff --git a/examples/simple_read.c b/examples/simple_read.c index 94da3cf..225ea54 100644 --- a/examples/simple_read.c +++ b/examples/simple_read.c @@ -7,7 +7,7 @@ int main(int argc, char** argv) { bsp_array_t array = bsp_read_array(f, "test"); - int* values = array.data; + int* values = (int*) array.data; for (size_t i = 0; i < array.size; i++) { printf("%lu: %d\n", i, values[i]); diff --git a/examples/simple_write.c b/examples/simple_write.c index e4f5952..15e3b36 100644 --- a/examples/simple_write.c +++ b/examples/simple_write.c @@ -1,13 +1,13 @@ #include int main(int argc, char** argv) { - char* file_name = "test.hdf5"; + const char* file_name = "test.hdf5"; hid_t f = H5Fcreate(file_name, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); bsp_array_t array = bsp_construct_array_t(1000, BSP_INT32); - int* values = array.data; + int* values = (int*) array.data; for (size_t i = 0; i < array.size; i++) { bsp_array_write(array, i, i); diff --git a/include/binsparse/detail/cpp/array.hpp b/include/binsparse/detail/cpp/array.hpp index c351202..2c9d268 100644 --- a/include/binsparse/detail/cpp/array.hpp +++ b/include/binsparse/detail/cpp/array.hpp @@ -2,6 +2,7 @@ #ifdef __cplusplus +#include #include #include @@ -71,7 +72,7 @@ void bsp_array_read(bsp_array_t array, size_t index, T& value) { [&](auto* ptr) { using U = std::remove_pointer_t; - if constexpr (std::is_assignable_v) { + if constexpr (std::is_assignable_v) { value = ptr[index]; } }, @@ -87,7 +88,7 @@ void bsp_array_write(bsp_array_t array, size_t index, U value) { [&](auto* ptr) { using T = std::remove_pointer_t; - if constexpr (std::is_assignable_v) { + if constexpr (std::is_assignable_v) { ptr[index] = value; } }, @@ -105,7 +106,7 @@ void bsp_array_awrite(bsp_array_t array_0, size_t index_0, bsp_array_t array_1, using T = std::remove_pointer_t; using U = std::remove_pointer_t; - if constexpr (std::is_assignable_v) { + if constexpr (std::is_assignable_v) { ptr_0[index_0] = ptr_1[index_1]; } }, diff --git a/include/binsparse/detail/parse_dataset.h b/include/binsparse/detail/parse_dataset.h index 434c821..53123c8 100644 --- a/include/binsparse/detail/parse_dataset.h +++ b/include/binsparse/detail/parse_dataset.h @@ -35,7 +35,7 @@ bsp_fdataset_info_t bsp_parse_fdataset_string(char* str) { } } -char* bsp_get_file_extension(char* file_name) { +const char* bsp_get_file_extension(const char* file_name) { int64_t len = strlen(file_name); for (int64_t i = len - 1; i >= 0; i--) { if (file_name[i] == '.') { diff --git a/include/binsparse/hdf5_wrapper.h b/include/binsparse/hdf5_wrapper.h index b30b697..89e84e9 100644 --- a/include/binsparse/hdf5_wrapper.h +++ b/include/binsparse/hdf5_wrapper.h @@ -11,7 +11,7 @@ // Write an array to a dataset / file // Returns 0 on success, nonzero on error. -int bsp_write_array(hid_t f, char* label, bsp_array_t array, +int bsp_write_array(hid_t f, const char* label, bsp_array_t array, int compression_level) { if (array.type == BSP_COMPLEX_FLOAT32 || array.type == BSP_COMPLEX_FLOAT64) { array = bsp_complex_array_to_fp(array); @@ -65,7 +65,8 @@ int bsp_write_array(hid_t f, char* label, bsp_array_t array, return 0; } -bsp_array_t bsp_read_array_parallel(hid_t f, char* label, int num_threads) { +bsp_array_t bsp_read_array_parallel(hid_t f, const char* label, + int num_threads) { hid_t dset = H5Dopen2(f, label, H5P_DEFAULT); if (dset == H5I_INVALID_HID) { @@ -147,7 +148,7 @@ bsp_array_t bsp_read_array_parallel(hid_t f, char* label, int num_threads) { return array; } -bsp_array_t bsp_read_array(hid_t f, char* label) { +bsp_array_t bsp_read_array(hid_t f, const char* label) { hid_t dset = H5Dopen2(f, label, H5P_DEFAULT); if (dset == H5I_INVALID_HID) { @@ -186,7 +187,7 @@ bsp_array_t bsp_read_array(hid_t f, char* label) { return array; } -void bsp_write_attribute(hid_t f, char* label, char* string) { +void bsp_write_attribute(hid_t f, const char* label, const char* string) { hid_t strtype = H5Tcopy(H5T_C_S1); H5Tset_size(strtype, strlen(string)); H5Tset_cset(strtype, H5T_CSET_UTF8); @@ -202,7 +203,7 @@ void bsp_write_attribute(hid_t f, char* label, char* string) { H5Sclose(dataspace); } -char* bsp_read_attribute(hid_t f, char* label) { +char* bsp_read_attribute(hid_t f, const char* label) { hid_t attribute = H5Aopen(f, label, H5P_DEFAULT); hid_t strtype = H5Aget_type(attribute); diff --git a/include/binsparse/matrix_market/matrix_market_inspector.h b/include/binsparse/matrix_market/matrix_market_inspector.h index ffac771..724b691 100644 --- a/include/binsparse/matrix_market/matrix_market_inspector.h +++ b/include/binsparse/matrix_market/matrix_market_inspector.h @@ -26,7 +26,7 @@ typedef struct bsp_mm_metadata { char* comments; } bsp_mm_metadata; -bsp_mm_metadata bsp_mmread_metadata(char* file_path) { +bsp_mm_metadata bsp_mmread_metadata(const char* file_path) { FILE* f = fopen(file_path, "r"); assert(f != NULL); diff --git a/include/binsparse/matrix_market/matrix_market_read.h b/include/binsparse/matrix_market/matrix_market_read.h index e2e1fb3..d6745e4 100644 --- a/include/binsparse/matrix_market/matrix_market_read.h +++ b/include/binsparse/matrix_market/matrix_market_read.h @@ -9,7 +9,8 @@ #include #include -bsp_matrix_t bsp_mmread_explicit_array(char* file_path, bsp_type_t value_type, +bsp_matrix_t bsp_mmread_explicit_array(const char* file_path, + bsp_type_t value_type, bsp_type_t index_type) { bsp_mm_metadata metadata = bsp_mmread_metadata(file_path); @@ -96,7 +97,7 @@ bsp_matrix_t bsp_mmread_explicit_array(char* file_path, bsp_type_t value_type, return matrix; } -bsp_matrix_t bsp_mmread_explicit_coordinate(char* file_path, +bsp_matrix_t bsp_mmread_explicit_coordinate(const char* file_path, bsp_type_t value_type, bsp_type_t index_type) { bsp_mm_metadata metadata = bsp_mmread_metadata(file_path); @@ -254,7 +255,7 @@ bsp_matrix_t bsp_mmread_explicit_coordinate(char* file_path, return matrix; } -bsp_matrix_t bsp_mmread_explicit(char* file_path, bsp_type_t value_type, +bsp_matrix_t bsp_mmread_explicit(const char* file_path, bsp_type_t value_type, bsp_type_t index_type) { bsp_mm_metadata metadata = bsp_mmread_metadata(file_path); @@ -267,7 +268,7 @@ bsp_matrix_t bsp_mmread_explicit(char* file_path, bsp_type_t value_type, } } -bsp_matrix_t bsp_mmread(char* file_path) { +bsp_matrix_t bsp_mmread(const char* file_path) { bsp_mm_metadata metadata = bsp_mmread_metadata(file_path); bsp_type_t value_type; diff --git a/include/binsparse/matrix_market/matrix_market_write.h b/include/binsparse/matrix_market/matrix_market_write.h index 3446bda..75f9aeb 100644 --- a/include/binsparse/matrix_market/matrix_market_write.h +++ b/include/binsparse/matrix_market/matrix_market_write.h @@ -6,7 +6,7 @@ #include -void bsp_mmwrite(char* file_path, bsp_matrix_t matrix) { +void bsp_mmwrite(const char* file_path, bsp_matrix_t matrix) { FILE* f = fopen(file_path, "w"); assert(f != NULL); diff --git a/include/binsparse/read_matrix.h b/include/binsparse/read_matrix.h index 4a5339c..4664be0 100644 --- a/include/binsparse/read_matrix.h +++ b/include/binsparse/read_matrix.h @@ -209,7 +209,7 @@ bsp_matrix_t bsp_read_matrix_from_group(hid_t f) { return matrix; } -size_t bsp_final_dot(char* str) { +size_t bsp_final_dot(const char* str) { size_t dot_idx = 0; for (size_t i = 0; str[i] != '\0'; i++) { if (str[i] == '.') { @@ -219,7 +219,7 @@ size_t bsp_final_dot(char* str) { return dot_idx; } -bsp_matrix_t bsp_read_matrix_parallel(char* file_name, char* group, +bsp_matrix_t bsp_read_matrix_parallel(const char* file_name, const char* group, int num_threads) { if (group == NULL) { size_t idx = bsp_final_dot(file_name); @@ -244,7 +244,7 @@ bsp_matrix_t bsp_read_matrix_parallel(char* file_name, char* group, } } -bsp_matrix_t bsp_read_matrix(char* file_name, char* group) { +bsp_matrix_t bsp_read_matrix(const char* file_name, const char* group) { if (group == NULL) { size_t idx = bsp_final_dot(file_name); if (strcmp(file_name + idx, ".hdf5") == 0 || diff --git a/include/binsparse/write_matrix.h b/include/binsparse/write_matrix.h index 0bd3657..76dd7c7 100644 --- a/include/binsparse/write_matrix.h +++ b/include/binsparse/write_matrix.h @@ -121,7 +121,7 @@ int bsp_write_matrix_to_group(hid_t f, bsp_matrix_t matrix, cJSON* user_json, return 0; } -int bsp_write_matrix(char* fname, bsp_matrix_t matrix, char* group, +int bsp_write_matrix(const char* fname, bsp_matrix_t matrix, const char* group, cJSON* user_json, int compression_level) { if (group == NULL) { hid_t f = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);