From 80805292ef9b725cc4003a70b830f0a35ec659f4 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Wed, 5 Dec 2018 13:39:51 +0200 Subject: [PATCH] MXS-2208 Compile avro as C++ An unantecipated sidestep in the path of introducing a small HTTP library to maxbase. --- avro/CMakeLists.txt | 4 +-- avro/{maxavro.c => maxavro.cc} | 8 +++--- ...xavro_datablock.c => maxavro_datablock.cc} | 0 avro/{maxavro_file.c => maxavro_file.cc} | 12 ++++---- avro/{maxavro_record.c => maxavro_record.cc} | 6 ++-- avro/{maxavro_schema.c => maxavro_schema.cc} | 28 +++++++++---------- avro/{maxavro_write.c => maxavro_write.cc} | 0 avro/{maxavrocheck.c => maxavrocheck.cc} | 2 +- 8 files changed, 30 insertions(+), 30 deletions(-) rename avro/{maxavro.c => maxavro.cc} (97%) rename avro/{maxavro_datablock.c => maxavro_datablock.cc} (100%) rename avro/{maxavro_file.c => maxavro_file.cc} (96%) rename avro/{maxavro_record.c => maxavro_record.cc} (98%) rename avro/{maxavro_schema.c => maxavro_schema.cc} (86%) rename avro/{maxavro_write.c => maxavro_write.cc} (100%) rename avro/{maxavrocheck.c => maxavrocheck.cc} (98%) diff --git a/avro/CMakeLists.txt b/avro/CMakeLists.txt index 27189782d..3f25beb07 100644 --- a/avro/CMakeLists.txt +++ b/avro/CMakeLists.txt @@ -1,13 +1,13 @@ if (AVRO_FOUND AND JANSSON_FOUND) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) - add_library(maxavro maxavro.c maxavro_schema.c maxavro_record.c maxavro_file.c) + add_library(maxavro maxavro.cc maxavro_schema.cc maxavro_record.cc maxavro_file.cc) target_link_libraries(maxavro maxscale-common ${JANSSON_LIBRARIES}) if(WITH_ASAN AND ASAN_FOUND) target_link_libraries(maxavro ${ASAN_LIBRARIES}) endif() - add_executable(maxavrocheck maxavrocheck.c) + add_executable(maxavrocheck maxavrocheck.cc) target_link_libraries(maxavrocheck maxavro maxscale-common) install_executable(maxavrocheck core) add_subdirectory(test) diff --git a/avro/maxavro.c b/avro/maxavro.cc similarity index 97% rename from avro/maxavro.c rename to avro/maxavro.cc index 53c890775..4e4844db5 100644 --- a/avro/maxavro.c +++ b/avro/maxavro.cc @@ -144,7 +144,7 @@ char* maxavro_read_string(MAXAVRO_FILE* file, size_t* size) if (maxavro_read_integer(file, &len)) { - key = MXS_MALLOC(len + 1); + key = (char*)MXS_MALLOC(len + 1); if (key) { memcpy(key, file->buffer_ptr, len); @@ -178,7 +178,7 @@ char* maxavro_read_string_from_file(MAXAVRO_FILE* file, size_t* size) if (maxavro_read_integer_from_file(file, &len)) { - key = MXS_MALLOC(len + 1); + key = (char*)MXS_MALLOC(len + 1); if (key) { if (fread(key, 1, len, file->file) == len) @@ -333,10 +333,10 @@ MAXAVRO_MAP* maxavro_read_map_from_file(MAXAVRO_FILE* file) while (blocks > 0) { - for (long i = 0; i < blocks; i++) + for (long i = 0; i < (long)blocks; i++) { size_t size; - MAXAVRO_MAP* val = calloc(1, sizeof(MAXAVRO_MAP)); + MAXAVRO_MAP* val = (MAXAVRO_MAP*)calloc(1, sizeof(MAXAVRO_MAP)); if (val && (val->key = maxavro_read_string_from_file(file, diff --git a/avro/maxavro_datablock.c b/avro/maxavro_datablock.cc similarity index 100% rename from avro/maxavro_datablock.c rename to avro/maxavro_datablock.cc diff --git a/avro/maxavro_file.c b/avro/maxavro_file.cc similarity index 96% rename from avro/maxavro_file.c rename to avro/maxavro_file.cc index 823db2adf..9340ad79c 100644 --- a/avro/maxavro_file.c +++ b/avro/maxavro_file.cc @@ -90,10 +90,10 @@ bool maxavro_verify_block(MAXAVRO_FILE* file) static uint8_t* read_block_data(MAXAVRO_FILE* file, long deflate_size) { - uint8_t* temp_buffer = MXS_MALLOC(deflate_size); + uint8_t* temp_buffer = (uint8_t*)MXS_MALLOC(deflate_size); uint8_t* buffer = NULL; - if (temp_buffer && fread(temp_buffer, 1, deflate_size, file->file) == deflate_size) + if (temp_buffer && fread(temp_buffer, 1, deflate_size, file->file) == (size_t)deflate_size) { unsigned long inflate_size = 0; @@ -108,7 +108,7 @@ static uint8_t* read_block_data(MAXAVRO_FILE* file, long deflate_size) case MAXAVRO_CODEC_DEFLATE: inflate_size = deflate_size * 2; - if ((buffer = MXS_MALLOC(inflate_size))) + if ((buffer = (uint8_t*)MXS_MALLOC(inflate_size))) { z_stream stream; stream.avail_in = deflate_size; @@ -124,7 +124,7 @@ static uint8_t* read_block_data(MAXAVRO_FILE* file, long deflate_size) while ((rc = inflate(&stream, Z_FINISH)) == Z_BUF_ERROR) { int increment = inflate_size; - uint8_t* temp = MXS_REALLOC(buffer, inflate_size + increment); + uint8_t* temp = (uint8_t*)MXS_REALLOC(buffer, inflate_size + increment); if (temp) { @@ -300,7 +300,7 @@ MAXAVRO_FILE* maxavro_file_open(const char* filename) bool error = false; - MAXAVRO_FILE* avrofile = calloc(1, sizeof(MAXAVRO_FILE)); + MAXAVRO_FILE* avrofile = (MAXAVRO_FILE*)calloc(1, sizeof(MAXAVRO_FILE)); char* my_filename = strdup(filename); if (avrofile && my_filename) @@ -419,7 +419,7 @@ GWBUF* maxavro_file_binary_header(MAXAVRO_FILE* file) { if ((rval = gwbuf_alloc(pos))) { - if (fread(GWBUF_DATA(rval), 1, pos, file->file) != pos) + if (fread(GWBUF_DATA(rval), 1, pos, file->file) != (size_t)pos) { if (ferror(file->file)) { diff --git a/avro/maxavro_record.c b/avro/maxavro_record.cc similarity index 98% rename from avro/maxavro_record.c rename to avro/maxavro_record.cc index 4e18dc3ea..50cddabe5 100644 --- a/avro/maxavro_record.c +++ b/avro/maxavro_record.cc @@ -57,7 +57,7 @@ static json_t* read_and_pack_value(MAXAVRO_FILE *file, MAXAVRO_SCHEMA_FIELD *fie uint64_t val = 0; maxavro_read_integer(file, &val); - json_t* arr = field->extra; + json_t* arr = (json_t*)field->extra; mxb_assert(arr); mxb_assert(json_is_array(arr)); @@ -107,7 +107,7 @@ static json_t* read_and_pack_value(MAXAVRO_FILE *file, MAXAVRO_SCHEMA_FIELD *fie case MAXAVRO_TYPE_UNION: { - json_t *arr = field->extra; + json_t *arr = (json_t*)field->extra; uint64_t val = 0; if (maxavro_read_integer(file, &val) && val < json_array_size(arr)) @@ -332,7 +332,7 @@ GWBUF* maxavro_record_read_binary(MAXAVRO_FILE* file) { fseek(file->file, file->block_start_pos, SEEK_SET); - if (fread(GWBUF_DATA(rval), 1, data_size, file->file) == data_size) + if (fread(GWBUF_DATA(rval), 1, data_size, file->file) == (size_t)data_size) { memcpy(((uint8_t*) GWBUF_DATA(rval)) + data_size, file->sync, sizeof(file->sync)); maxavro_next_block(file); diff --git a/avro/maxavro_schema.c b/avro/maxavro_schema.cc similarity index 86% rename from avro/maxavro_schema.c rename to avro/maxavro_schema.cc index cfcf881c9..5835b6581 100644 --- a/avro/maxavro_schema.c +++ b/avro/maxavro_schema.cc @@ -19,16 +19,16 @@ static const MAXAVRO_SCHEMA_FIELD types[MAXAVRO_TYPE_MAX] = { - {"int", NULL, MAXAVRO_TYPE_INT }, - {"long", NULL, MAXAVRO_TYPE_LONG }, - {"float", NULL, MAXAVRO_TYPE_FLOAT }, - {"double", NULL, MAXAVRO_TYPE_DOUBLE }, - {"bool", NULL, MAXAVRO_TYPE_BOOL }, - {"bytes", NULL, MAXAVRO_TYPE_BYTES }, - {"string", NULL, MAXAVRO_TYPE_STRING }, - {"enum", NULL, MAXAVRO_TYPE_ENUM }, - {"null", NULL, MAXAVRO_TYPE_NULL }, - {NULL, NULL, MAXAVRO_TYPE_UNKNOWN} + {(char*)"int", NULL, MAXAVRO_TYPE_INT }, + {(char*)"long", NULL, MAXAVRO_TYPE_LONG }, + {(char*)"float", NULL, MAXAVRO_TYPE_FLOAT }, + {(char*)"double", NULL, MAXAVRO_TYPE_DOUBLE }, + {(char*)"bool", NULL, MAXAVRO_TYPE_BOOL }, + {(char*)"bytes", NULL, MAXAVRO_TYPE_BYTES }, + {(char*)"string", NULL, MAXAVRO_TYPE_STRING }, + {(char*)"enum", NULL, MAXAVRO_TYPE_ENUM }, + {(char*)"null", NULL, MAXAVRO_TYPE_NULL }, + {NULL, NULL, MAXAVRO_TYPE_UNKNOWN} }; /** * @brief Convert string to Avro value type @@ -123,7 +123,7 @@ static enum maxavro_value_type unpack_to_type(json_t* object, */ MAXAVRO_SCHEMA* maxavro_schema_alloc(const char* json) { - MAXAVRO_SCHEMA* rval = malloc(sizeof(MAXAVRO_SCHEMA)); + MAXAVRO_SCHEMA* rval = (MAXAVRO_SCHEMA*)malloc(sizeof(MAXAVRO_SCHEMA)); if (rval) { @@ -138,10 +138,10 @@ MAXAVRO_SCHEMA* maxavro_schema_alloc(const char* json) if (json_unpack(schema, "{s:o}", "fields", &field_arr) == 0) { size_t arr_size = json_array_size(field_arr); - rval->fields = malloc(sizeof(MAXAVRO_SCHEMA_FIELD) * arr_size); + rval->fields = (MAXAVRO_SCHEMA_FIELD*)malloc(sizeof(MAXAVRO_SCHEMA_FIELD) * arr_size); rval->num_fields = arr_size; - for (int i = 0; i < arr_size; i++) + for (int i = 0; i < (int)arr_size; i++) { json_t* object = json_array_get(field_arr, i); char* key; @@ -213,7 +213,7 @@ void maxavro_schema_free(MAXAVRO_SCHEMA* schema) { if (schema) { - for (int i = 0; i < schema->num_fields; i++) + for (unsigned int i = 0; i < schema->num_fields; i++) { maxavro_schema_field_free(&schema->fields[i]); } diff --git a/avro/maxavro_write.c b/avro/maxavro_write.cc similarity index 100% rename from avro/maxavro_write.c rename to avro/maxavro_write.cc diff --git a/avro/maxavrocheck.c b/avro/maxavrocheck.cc similarity index 98% rename from avro/maxavrocheck.c rename to avro/maxavrocheck.cc index e5951f3d2..5190d66a6 100644 --- a/avro/maxavrocheck.c +++ b/avro/maxavrocheck.cc @@ -45,7 +45,7 @@ int check_file(const char* filename) if (!dump) { printf("File sync marker: "); - for (int i = 0; i < sizeof(file->sync); i++) + for (size_t i = 0; i < sizeof(file->sync); i++) { printf("%hhx", file->sync[i]); }