From: Michal MalĂ˝ Date: Sun, 29 Jun 2014 23:52:32 +0000 (+0200) Subject: Provide alloc() and free() functions to simplify memory deallocation and X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=674a9cd3968abf12feb0fb1c5fca78a03fccec63;p=libHPCS.git Provide alloc() and free() functions to simplify memory deallocation and prevent usage of different allocators. --- diff --git a/libhpcs.c b/libhpcs.c index e6f4e27..880f4eb 100644 --- a/libhpcs.c +++ b/libhpcs.c @@ -4,6 +4,11 @@ #include #include +struct HPCS_MeasuredData* hpcs_alloc() +{ + return malloc(sizeof(struct HPCS_MeasuredData)); +} + char* hpcs_error_to_string(const enum HPCS_RetCode err) { char* msg; @@ -36,6 +41,21 @@ char* hpcs_error_to_string(const enum HPCS_RetCode err) } } +void hpcs_free(struct HPCS_MeasuredData* const mdata) +{ + if (mdata == NULL) + return; + free(mdata->file_description); + free(mdata->sample_info); + free(mdata->operator_name); + free(mdata->method_name); + free(mdata->cs_ver); + free(mdata->cs_rev); + free(mdata->y_units); + free(mdata->data); + free(mdata); +} + enum HPCS_RetCode hpcs_read_file(const char* filename, struct HPCS_MeasuredData* mdata) { FILE* datafile; diff --git a/libhpcs.h b/libhpcs.h index 42db2c4..9b79451 100644 --- a/libhpcs.h +++ b/libhpcs.h @@ -54,11 +54,15 @@ struct HPCS_MeasuredData { }; #ifdef __WIN32__ -__declspec(dllexport) enum HPCS_RetCode __cdecl hpcs_read_file(const char* const filename, struct HPCS_MeasuredData* mdata); +__declspec(dllexport) struct HPCS_MeasuredData* __cdecl hpcs_alloc(); +__declspec(dllexport) void __cdecl hpcs_free(struct HPCS_MeasuredData* const mdata); __declspec(dllexport) char* __cdecl hpcs_error_to_string(const enum HPCS_RetCode); +__declspec(dllexport) enum HPCS_RetCode __cdecl hpcs_read_file(const char* const filename, struct HPCS_MeasuredData* mdata); #else -enum HPCS_RetCode hpcs_read_file(const char* const filename, struct HPCS_MeasuredData* mdata); +struct HPCS_MeasuredData* hpcs_alloc(); +void hpcs_free(struct HPCS_MeasuredData* const mdata); char* hpcs_error_to_string(const enum HPCS_RetCode); +enum HPCS_RetCode hpcs_read_file(const char* const filename, struct HPCS_MeasuredData* mdata); #endif #ifdef __cplusplus