-
Notifications
You must be signed in to change notification settings - Fork 42
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
fix(value): don't assume that zero-terminated array is of type gchar** #313
Conversation
src/value.cc
Outdated
for (int i = 0; (i < length || length == -1); i++) { | ||
void** pointer = (void**)((ulong)data + i * item_size); | ||
memcpy(&value, pointer, item_size); | ||
|
||
if (length == -1 && isZero(value, item_type_info)) | ||
break; | ||
|
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.
This seems a bit hard to read. Can we clearly separate zero-terminated and non-zero terminated cases?
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.
Does the current version look better? My other alternative is:
if (length >= 0) {
for (int i = 0; i < length; i++) {
void** pointer = (void**)((ulong)data + i * item_size);
memcpy(&value, pointer, item_size);
Nan::Set(array, i, GIArgumentToV8(item_type_info, &value));
}
} else {
for (int i = 0; ; i++) {
void** pointer = (void**)((ulong)data + i * item_size);
memcpy(&value, pointer, item_size);
if (isZero(value, item_type_info))
break;
Nan::Set(array, i, GIArgumentToV8(item_type_info, &value));
}
}
But this feels silly.
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.
No, current version still feels off :|
The alternative is nice because it avoid unnecessary comparisons, but I don't think it matters enough. So anyway put it back however you want, if you could just assign bool isZeroTerminated = length == -1;
so things are clear for whoever reads it.
9328011
to
6bfb188
Compare
I don't understand the test failure on macos.
The annotation of the function is:
So the JS version should take only 1 argument, the |
Can't see the tests, can you rebase on master to fetch the updated workflow yaml file? For the issue, maybe you could detect the OS or glib version, and provide the missing argument depending on that? |
The array's element type can be arbitrary, so we need to check the value with the correct type. The long switch and a template function is used to do this job. We can't just memcmp() with item_size, because one of the type is float, and we can't assume a 0.0 float is the same as 0 integer. A test, based on how I discovered this, is added.
Done. Please see the result.
The problem is, I don't know what I'm supposed to pass in as the second argument. Without a Mac, I can't take a look at the Gir file or use a debugger to find out what the second argument is. |
You can add the following line somewhere in the CI script to see the metadata for that function:
|
ArgInfo {
infoType: 'arg',
name: 'exit_status',
parent: [Circular *1],
typeName: 'gint32',
type: [TypeInfo],
direction: 'IN',
transfer: 'NOTHING'
} Huh? |
7ea35d2
to
f2ea23a
Compare
So, I got myself a macOS VM, and discovered a problem with Homebrew's gobject-introspection bottle. Put a workaround to rebuild that from source, and now the CI is green. |
f2ea23a
to
155b8e5
Compare
Thanks :) @binyamin: I'm very inconsistent in my presence on github due to lack of time :( As you have write access to the repo, I bless you with the power to merge PRs if you feel like they're complete. I can also give you access to NPM so you can publish in case I'm not around. |
The array's element type can be arbitrary, so we need to check the value
with the correct type. The long switch and a template function is used
to do this job.
We can't just memcmp() with item_size, because one of the type is float,
and we can't assume a 0.0 float is the same as 0 integer.
A test, based on how I discovered this, is added.