-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create C library wrapper over existing Java library using GraalVM #196
base: native-schema-registry-release
Are you sure you want to change the base?
Create C library wrapper over existing Java library using GraalVM #196
Conversation
4964d6f
to
939148f
Compare
#include "read_only_byte_array.h" | ||
#include <stdbool.h> | ||
|
||
typedef struct glue_schema_registry_deserializer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not blocking anything here, because it's 100% your call, but the typedef struct idiom goes off the rails when used too frequently. I tend to just use 'struct type' declarations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will check how it plays with Swig and take a call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It plays well with Swig as Swig generates the class structures in target languages from typefdef structs, https://www.swig.org/Doc4.0/SWIGDocumentation.html#SWIG_nn32
Leaving it as is.
native-schema-registry/c/include/glue_schema_registry_deserializer.h
Outdated
Show resolved
Hide resolved
/** | ||
* A mutable byte array that allows write / updating bytes in a fixed array of size `max_len`. | ||
*/ | ||
typedef struct mutable_byte_array { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you're already using aws-c-common, why not use aws_byte_cursor and aws_byte_buf?
cursor is read only slice, and byte_buf is mutable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion. I have modified the mutable_byte_array
to wrap a aws_byte_buf
so that I don't do buffer management myself. The outer structure is still useful to have as it fits our exception handling and binding generation model.
I wanted to do the same by wrapping aws_byte_cursor
under read_only_byte_array
but couldn't find a method that would return a pointer to it (I might be missing something). I could only find this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can return cursor.ptr in that case
#include <stdlib.h> | ||
#include "glue_schema_registry_error.h" | ||
|
||
typedef struct read_only_byte_array { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see what in the type system is making this read only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intention is to create a structure that doesn't manage the memory of underlying array and provides a way to read it.
* Uses the default memory allocator from AWS SDK Common library to allocate / free memory. | ||
*/ | ||
void *aws_common_malloc(size_t size) { | ||
struct aws_allocator *allocator = aws_default_allocator(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aws_default_allocator doesn't change. So you could store it at file scope to save on function calls if you'd like. Though, to be fair, you're allocating memory so a single fn call is unlkely to be noticeable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you suggestion to create a static
member? We don't have a global initializer yet, so couldn't find a way to initialize it once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do it lazily which that function does under the hood anyways, or use AWS_thread_call_once
1. Mutable byte arrays use aws_byte_buf 2. clang-tidy and clang-format integration
9db48e5
to
d994043
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments above. I don’t have any blockers but I do recommend deciding on relevant to you questions before merging over.
Issue #, if available:
#43
Description of changes:
Port the Glue Schema Registry Java library into multiple languages (C#, Python, NodeJS, Go, etc.). The support is added by compiling the existing Java library using GraalVM into a C shared library (.so, .dll) and building Swig bindings on top of it.
Design Choices
NULL
is returned and exception code / message are returned as a pointer holder toglue_schema_registry_error
object.mutable_byte_array * encode(..., glue_schema_registry_error **p_err)
. Swig intercepts this error object and throws as an exception in the target language.cmocka
to test the C code. There is no good ways to test GraalVM code as we cannot mock network calls. Target lang tests will test this code as well. We will add integration tests that cover all the use-cases.Open questions
stderr
. We have to figure out how to pipe to target language logs.aws-c-common
library.Testing
Tested using unit-tests. Target language tests currently make network calls and need credentials to run. We will update our tests to use local docker based Glue service.
Coverage
Setup code coverage using
gcov
and build will fail if code coverage is less than 100.Linting
clang-format and clang-tidy is setup to fail build if code formatting doesn't meet standards.
This is one of the initial PRs to cover the data types and header files. Implementation PRs will follow.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.