-
Notifications
You must be signed in to change notification settings - Fork 70
feat: Support table view for C client. #294
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
Conversation
In addition, I don't think use a null-terminated string as the tableview value is good for C API. The value is actually a byte array rather than a null-terminated string. Unlike the #include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void get_value(char **value) {
char *data = (char *)malloc(4);
data[0] = 0x01;
data[1] = 0x00;
data[2] = 0x02;
data[3] = 0x00;
*value = data;
}
int main(int argc, char *argv[]) {
char *value;
get_value(&value);
printf("length: %zu\n", strlen(value));
return 0;
} The code example is a demo to show the difference between a byte array and a null-terminated string. So it's better to add a length parameter like: #include <stdio.h>
#include <stdlib.h>
static void get_value(char **value_ptr, size_t *value_len) {
char *data = (char *)malloc(4);
data[0] = 0x01;
data[1] = 0x00;
data[2] = 0x02;
data[3] = 0x00;
*value_ptr = data;
*value_len = 4;
}
int main(int argc, char *argv[]) {
char *value;
size_t len;
get_value(&value, &len);
printf("length: %zu\n", len);
for (size_t i = 0; i < len; i++) {
printf("0x%02x%c", value[i], (i < len - 1) ? ' ' : '\n');
}
return 0;
} Output:
|
Thanks explain, that makes sense to me. New commit modifications:
PTAL. |
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.
LGTM except the example is still wrong.
Motivation
Support table view for C client.
Modifications
Verifying this change
Documentation
doc-required
(Your PR needs to update docs and you will update later)
doc-not-needed
(Please explain why)
doc
(Your PR contains doc changes)
doc-complete
(Docs have been already added)