Add a few C APIs#2047
Conversation
|
@cdleary |
cdleary
left a comment
There was a problem hiding this comment.
Looks good -- just the only thing I think should change is that the API should offer an xls_bytes_free to do the delete[] of the xls_bits_to_bytes() result under the hood.
With that in place all looks good!
I'm not sure why the CLA scan didn't happen automatically but I think to land the change I imagine you'll need to do https://cla.developers.google.com/about/google-individual
| const auto* cpp_bits = reinterpret_cast<const xls::Bits*>(bits); | ||
| auto bytes = cpp_bits->ToBytes(); | ||
| *byte_count_out = bytes.size(); | ||
| *bytes_out = (uint8_t*)malloc(bytes.size()); |
There was a problem hiding this comment.
You'll need a xls_bytes_free() for this (because the libxls allocator can be different from the surrounding process so you can't assume the surrounding process can use the same free()), and generally I think we've been doing new[] inside the impl e.g. https://sourcegraph.com/github.com/google/xls@ef07f4bc7db8df70dc32e52a04d268653b58847a/-/blob/xls/public/c_api_impl_helpers.cc?L72
There was a problem hiding this comment.
Done, can you take another look?
19089f8 to
03d519c
Compare
I am a Googler thus have signed CLA. |
| bool xls_bits_get_bit(const struct xls_bits* bits, int64_t index); | ||
|
|
||
| // Returns the bytes in the given bits value. The caller must | ||
| // free the returned `bytes_out` pointer via `free`, The caller |
There was a problem hiding this comment.
Shouldn't it be freed via xls_bytes_free?
| // Converts the given bits value to a signed or unsigned integer 64-bit integer | ||
| // value. if the conversion is not possible, false is returned and `error_out` | ||
| // contains the error message and the caller must free the `value_out` pointer | ||
| // itself via `free`. |
There was a problem hiding this comment.
In the success case, no memory is returned, so there is nothing to free, right?
There was a problem hiding this comment.
Doc in comment updated.
e205c20 to
2eadc0f
Compare
ingomueller-net
left a comment
There was a problem hiding this comment.
LGTM!
Disclaimer: I am not familiar with the coding conventions of this project. Some of the code does not respect the Google style guide (like the use of auto) but similar patterns are used in the rest of the file so I guess it's fine.
| uint8_t** bytes_out, size_t* byte_count_out); | ||
|
|
||
| // Converts the given bits value to a signed or unsigned integer 64-bit integer | ||
| // value. if the conversion is not possible, false is returned, `error_out` |
There was a problem hiding this comment.
Ultra-nit:
| // value. if the conversion is not possible, false is returned, `error_out` | |
| // value. If the conversion is not possible, false is returned, `error_out` |
It would be nice to have a lint tool for style conformance. |
|
@cdleary can you take another look and if it is OK, can we proceed with the merge? |
Add xls_value_get_kind to allow inspecting the type of a Value object. Signed-off-by: Hui Peng <phui@google.com>
cdleary
left a comment
There was a problem hiding this comment.
LGTM! You may want to check that this has nothing flagged under bazel test -c opt --config=asan or it may hit a snag when folks attempt to import it to the repo.
| CHECK(error_out != nullptr); | ||
| CHECK(byte_count_out != nullptr); | ||
| const auto* cpp_bits = reinterpret_cast<const xls::Bits*>(bits); | ||
| auto bytes = cpp_bits->ToBytes(); |
There was a problem hiding this comment.
Since the type is not obvious from the right hand side expression this auto should probably be elided. (That's the general C++ style guide guideline.)
There was a problem hiding this comment.
Since the type is not obvious from the right hand side expression this auto should probably be elided. (That's the general C++ style guide guideline.)
Fixed.
Yeah this is a good point, an Thanks for helping build out this API! cc @meheff @richmckeever and team to tag for import. |
Can we add a check in the CI? |
Fixed |
I got the following odr violation, is it expected?================================================================= These globals were registered at these points: [2]: ==3602574==HINT: if you don't care about these errors you may set ASAN_OPTIONS=detect_odr_violation=0 |
Yes I get that as well, use the env var to disable it as it suggests: |
#1447 is the issue that tracks this but I'm not sure there's active movement on it |
I ran the following command and all tests passed |
Awesome! I expect the google XLS team build gardener should be able to merge successfully then. @benquike Just out of curiosity are you building out the C APIs for use in the Rust crate? (https://github.com/xlsynth/xlsynth-crate) Or a different use case? |
erinzmoore
left a comment
There was a problem hiding this comment.
LG overall. Just the comment on auto from cdleary@ to address and then can merge.
- xls_bits_to_bytes - xls_bits_to_uint64 - xls_bits_to_int64 Signed-off-by: Hui Peng <phui@google.com>
No, We are using these APIs to create python bindings. |
Nah it's ok was just curious, I can add them there no problem, look forward to the Python bindings if you'll be doing them in open source! |
No description provided.