From 11c081ab6ddc2e99ef2e6038e828b0a2439343b4 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Wed, 15 Jul 2020 11:14:57 +0200 Subject: [PATCH] C generated put/get - use the new obx_last_error_set() --- internal/generator/c/templates/c-binding.go | 8 ++------ .../fbs/property-update/c/ChangeUid.obx.h.expected | 8 ++------ .../testdata/fbs/rename-property/c/B.obx.h.expected | 8 ++------ .../testdata/fbs/typeful/c/other.obx.h.expected | 8 ++------ .../testdata/fbs/typeful/c/schema.obx.h.expected | 8 ++------ 5 files changed, 10 insertions(+), 30 deletions(-) diff --git a/internal/generator/c/templates/c-binding.go b/internal/generator/c/templates/c-binding.go index 524d567e..e168425c 100644 --- a/internal/generator/c/templates/c-binding.go +++ b/internal/generator/c/templates/c-binding.go @@ -254,9 +254,7 @@ static obx_id {{.FileIdentifier}}_put_object(OBX_box* box, void* object, size_t size = 0; void* buffer = NULL; if (!to_flatbuffer(&builder, object, &buffer, &size)) { - // if the FlatBuffers serialization fails, we clear any previous ObjectBox errors, so that when our caller - // checks obx_last_error_code() it will be zero in this case. - obx_last_error_clear(); + obx_last_error_set(OBX_ERROR_STD_OTHER, 0, "FlatBuffer serialization failed"); } else { id = obx_box_put_object4(box, buffer, size, mode); // 0 on error } @@ -278,9 +276,7 @@ static void* {{.FileIdentifier}}_get_object(OBX_box* box, obx_id id, void* (*fro if (obx_box_get(box, id, &data, &size) == OBX_SUCCESS) { result = from_flatbuffer(data, size); if (result == NULL) { - // if the FlatBuffers serialization fails, we clear any previous ObjectBox errors, so that when our caller - // checks obx_last_error_code() it will be zero in this case. - obx_last_error_clear(); + obx_last_error_set(OBX_ERROR_STD_OTHER, 0, "FlatBuffer deserialization failed"); } } diff --git a/test/comparison/testdata/fbs/property-update/c/ChangeUid.obx.h.expected b/test/comparison/testdata/fbs/property-update/c/ChangeUid.obx.h.expected index 30b59643..43fc63c6 100644 --- a/test/comparison/testdata/fbs/property-update/c/ChangeUid.obx.h.expected +++ b/test/comparison/testdata/fbs/property-update/c/ChangeUid.obx.h.expected @@ -173,9 +173,7 @@ static obx_id changeuid_obx_h_put_object(OBX_box* box, void* object, size_t size = 0; void* buffer = NULL; if (!to_flatbuffer(&builder, object, &buffer, &size)) { - // if the FlatBuffers serialization fails, we clear any previous ObjectBox errors, so that when our caller - // checks obx_last_error_code() it will be zero in this case. - obx_last_error_clear(); + obx_last_error_set(OBX_ERROR_STD_OTHER, 0, "FlatBuffer serialization failed"); } else { id = obx_box_put_object4(box, buffer, size, mode); // 0 on error } @@ -197,9 +195,7 @@ static void* changeuid_obx_h_get_object(OBX_box* box, obx_id id, void* (*from_fl if (obx_box_get(box, id, &data, &size) == OBX_SUCCESS) { result = from_flatbuffer(data, size); if (result == NULL) { - // if the FlatBuffers serialization fails, we clear any previous ObjectBox errors, so that when our caller - // checks obx_last_error_code() it will be zero in this case. - obx_last_error_clear(); + obx_last_error_set(OBX_ERROR_STD_OTHER, 0, "FlatBuffer deserialization failed"); } } diff --git a/test/comparison/testdata/fbs/rename-property/c/B.obx.h.expected b/test/comparison/testdata/fbs/rename-property/c/B.obx.h.expected index dfb0ad7b..922fc946 100644 --- a/test/comparison/testdata/fbs/rename-property/c/B.obx.h.expected +++ b/test/comparison/testdata/fbs/rename-property/c/B.obx.h.expected @@ -173,9 +173,7 @@ static obx_id b_obx_h_put_object(OBX_box* box, void* object, size_t size = 0; void* buffer = NULL; if (!to_flatbuffer(&builder, object, &buffer, &size)) { - // if the FlatBuffers serialization fails, we clear any previous ObjectBox errors, so that when our caller - // checks obx_last_error_code() it will be zero in this case. - obx_last_error_clear(); + obx_last_error_set(OBX_ERROR_STD_OTHER, 0, "FlatBuffer serialization failed"); } else { id = obx_box_put_object4(box, buffer, size, mode); // 0 on error } @@ -197,9 +195,7 @@ static void* b_obx_h_get_object(OBX_box* box, obx_id id, void* (*from_flatbuffer if (obx_box_get(box, id, &data, &size) == OBX_SUCCESS) { result = from_flatbuffer(data, size); if (result == NULL) { - // if the FlatBuffers serialization fails, we clear any previous ObjectBox errors, so that when our caller - // checks obx_last_error_code() it will be zero in this case. - obx_last_error_clear(); + obx_last_error_set(OBX_ERROR_STD_OTHER, 0, "FlatBuffer deserialization failed"); } } diff --git a/test/comparison/testdata/fbs/typeful/c/other.obx.h.expected b/test/comparison/testdata/fbs/typeful/c/other.obx.h.expected index a871b1d8..2591e02a 100644 --- a/test/comparison/testdata/fbs/typeful/c/other.obx.h.expected +++ b/test/comparison/testdata/fbs/typeful/c/other.obx.h.expected @@ -276,9 +276,7 @@ static obx_id other_obx_h_put_object(OBX_box* box, void* object, size_t size = 0; void* buffer = NULL; if (!to_flatbuffer(&builder, object, &buffer, &size)) { - // if the FlatBuffers serialization fails, we clear any previous ObjectBox errors, so that when our caller - // checks obx_last_error_code() it will be zero in this case. - obx_last_error_clear(); + obx_last_error_set(OBX_ERROR_STD_OTHER, 0, "FlatBuffer serialization failed"); } else { id = obx_box_put_object4(box, buffer, size, mode); // 0 on error } @@ -300,9 +298,7 @@ static void* other_obx_h_get_object(OBX_box* box, obx_id id, void* (*from_flatbu if (obx_box_get(box, id, &data, &size) == OBX_SUCCESS) { result = from_flatbuffer(data, size); if (result == NULL) { - // if the FlatBuffers serialization fails, we clear any previous ObjectBox errors, so that when our caller - // checks obx_last_error_code() it will be zero in this case. - obx_last_error_clear(); + obx_last_error_set(OBX_ERROR_STD_OTHER, 0, "FlatBuffer deserialization failed"); } } diff --git a/test/comparison/testdata/fbs/typeful/c/schema.obx.h.expected b/test/comparison/testdata/fbs/typeful/c/schema.obx.h.expected index 5d4db781..2eade500 100644 --- a/test/comparison/testdata/fbs/typeful/c/schema.obx.h.expected +++ b/test/comparison/testdata/fbs/typeful/c/schema.obx.h.expected @@ -681,9 +681,7 @@ static obx_id schema_obx_h_put_object(OBX_box* box, void* object, size_t size = 0; void* buffer = NULL; if (!to_flatbuffer(&builder, object, &buffer, &size)) { - // if the FlatBuffers serialization fails, we clear any previous ObjectBox errors, so that when our caller - // checks obx_last_error_code() it will be zero in this case. - obx_last_error_clear(); + obx_last_error_set(OBX_ERROR_STD_OTHER, 0, "FlatBuffer serialization failed"); } else { id = obx_box_put_object4(box, buffer, size, mode); // 0 on error } @@ -705,9 +703,7 @@ static void* schema_obx_h_get_object(OBX_box* box, obx_id id, void* (*from_flatb if (obx_box_get(box, id, &data, &size) == OBX_SUCCESS) { result = from_flatbuffer(data, size); if (result == NULL) { - // if the FlatBuffers serialization fails, we clear any previous ObjectBox errors, so that when our caller - // checks obx_last_error_code() it will be zero in this case. - obx_last_error_clear(); + obx_last_error_set(OBX_ERROR_STD_OTHER, 0, "FlatBuffer deserialization failed"); } }