You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "namitkewat (via GitHub)" <gi...@apache.org> on 2025/08/09 01:37:41 UTC
[PR] fix(c): Refactor C function to resolve unreachable code error in Zig [arrow-nanoarrow]
namitkewat opened a new pull request, #799:
URL: https://github.com/apache/arrow-nanoarrow/pull/799
Hi there!
I am trying integrate `nanoarrow` into my Zig project. While doing so, the build process failed with an "unreachable code" error. It seems Zig's strict toolchain for importing C headers flags a specific pattern in `src/nanoarrow/common/inline_array.h` as a fatal compile error.
The problematic function appears to be `_ArrowArrayAppendEmptyInternal` , which contains a `for` loop where the inner `switch` statement causes code to be unreachable, which prevents the headers from being imported successfully in Zig.
This PR refactors that loop to remove the explicit `continue` statements and allow control to flow naturally, which resolves the compiler error in Zig without changing the function's logic.
I welcome any feedback or suggestions on this approach. Thank you to the maintainers and the community for your time and review.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(c): Refactor C function to resolve unreachable code error in Zig [arrow-nanoarrow]
Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot commented on PR #799:
URL: https://github.com/apache/arrow-nanoarrow/pull/799#issuecomment-3172848533
Thank you!
You'll still need to run `clang-format` or `pre-commit run --all-files` to get CI to pass. I personally thought the comments were nice! I'm happy to run it for you as well if you'd like!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(c): Refactor C function to resolve unreachable code error in Zig [arrow-nanoarrow]
Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot commented on code in PR #799:
URL: https://github.com/apache/arrow-nanoarrow/pull/799#discussion_r2264930692
##########
src/nanoarrow/common/inline_array.h:
##########
@@ -302,24 +303,27 @@ static inline ArrowErrorCode _ArrowArrayAppendEmptyInternal(struct ArrowArray* a
size_bytes);
}
- // Skip the data buffer
+ // Skip the data buffer in the next iteration
i++;
- continue;
+ break;
+
case NANOARROW_BUFFER_TYPE_DATA:
// Zero out the next bit of memory
if (private_data->layout.element_size_bits[i] % 8 == 0) {
NANOARROW_RETURN_NOT_OK(ArrowBufferAppendFill(buffer, 0, size_bytes * n));
} else {
NANOARROW_RETURN_NOT_OK(_ArrowArrayAppendBits(array, i, 0, n));
}
- continue;
+ break;
+
case NANOARROW_BUFFER_TYPE_VIEW_OFFSET:
NANOARROW_RETURN_NOT_OK(ArrowBufferReserve(buffer, size_bytes * n));
NANOARROW_RETURN_NOT_OK(ArrowBufferAppendFill(buffer, 0, size_bytes * n));
- continue;
+ break;
+
Review Comment:
```suggestion
```
##########
src/nanoarrow/common/inline_array.h:
##########
@@ -302,24 +303,27 @@ static inline ArrowErrorCode _ArrowArrayAppendEmptyInternal(struct ArrowArray* a
size_bytes);
}
- // Skip the data buffer
+ // Skip the data buffer in the next iteration
i++;
- continue;
+ break;
+
case NANOARROW_BUFFER_TYPE_DATA:
// Zero out the next bit of memory
if (private_data->layout.element_size_bits[i] % 8 == 0) {
NANOARROW_RETURN_NOT_OK(ArrowBufferAppendFill(buffer, 0, size_bytes * n));
} else {
NANOARROW_RETURN_NOT_OK(_ArrowArrayAppendBits(array, i, 0, n));
}
- continue;
+ break;
+
case NANOARROW_BUFFER_TYPE_VIEW_OFFSET:
NANOARROW_RETURN_NOT_OK(ArrowBufferReserve(buffer, size_bytes * n));
NANOARROW_RETURN_NOT_OK(ArrowBufferAppendFill(buffer, 0, size_bytes * n));
- continue;
+ break;
+
case NANOARROW_BUFFER_TYPE_TYPE_ID:
case NANOARROW_BUFFER_TYPE_UNION_OFFSET:
- // These cases return above
+ // These cases are handled by the outer switch statement and should never be reached here.
Review Comment:
```suggestion
// These cases are handled by the outer switch statement and should never be
// reached here.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(c): Refactor C function to resolve unreachable code error in Zig [arrow-nanoarrow]
Posted by "namitkewat (via GitHub)" <gi...@apache.org>.
namitkewat commented on PR #799:
URL: https://github.com/apache/arrow-nanoarrow/pull/799#issuecomment-3173058359
Hi @paleolimbot
I have updated the `for-loop` block with inline comments based on my understanding of the logic.
Could you please review them for correctness?
Thank you
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(c): Refactor C function to resolve unreachable code error in Zig [arrow-nanoarrow]
Posted by "namitkewat (via GitHub)" <gi...@apache.org>.
namitkewat commented on code in PR #799:
URL: https://github.com/apache/arrow-nanoarrow/pull/799#discussion_r2265241159
##########
src/nanoarrow/common/inline_array.h:
##########
@@ -302,24 +303,27 @@ static inline ArrowErrorCode _ArrowArrayAppendEmptyInternal(struct ArrowArray* a
size_bytes);
}
- // Skip the data buffer
+ // Skip the data buffer in the next iteration
i++;
- continue;
+ break;
+
case NANOARROW_BUFFER_TYPE_DATA:
// Zero out the next bit of memory
if (private_data->layout.element_size_bits[i] % 8 == 0) {
NANOARROW_RETURN_NOT_OK(ArrowBufferAppendFill(buffer, 0, size_bytes * n));
} else {
NANOARROW_RETURN_NOT_OK(_ArrowArrayAppendBits(array, i, 0, n));
}
- continue;
+ break;
+
case NANOARROW_BUFFER_TYPE_VIEW_OFFSET:
NANOARROW_RETURN_NOT_OK(ArrowBufferReserve(buffer, size_bytes * n));
NANOARROW_RETURN_NOT_OK(ArrowBufferAppendFill(buffer, 0, size_bytes * n));
- continue;
+ break;
+
Review Comment:
Hi @paleolimbot
Thanks for the review!
I've reverted the changes related to comments, as improving them can be handled in a separate pull request.
This commit now only contains the required fix of replacing `continue` with `break`.
The PR is ready for another look.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(c): Refactor C function to resolve unreachable code error in Zig [arrow-nanoarrow]
Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot merged PR #799:
URL: https://github.com/apache/arrow-nanoarrow/pull/799
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org