Skip to content

Commit

Permalink
C generated put/get - use the new obx_last_error_set()
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Jul 15, 2020
1 parent a7224bd commit 11c081a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 30 deletions.
8 changes: 2 additions & 6 deletions internal/generator/c/templates/c-binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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");
}
}

Expand Down
8 changes: 2 additions & 6 deletions test/comparison/testdata/fbs/typeful/c/other.obx.h.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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");
}
}

Expand Down
8 changes: 2 additions & 6 deletions test/comparison/testdata/fbs/typeful/c/schema.obx.h.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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");
}
}

Expand Down

0 comments on commit 11c081a

Please sign in to comment.