Skip to content
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

wchar_t size #9

Open
stronny opened this issue Oct 31, 2012 · 0 comments
Open

wchar_t size #9

stronny opened this issue Oct 31, 2012 · 0 comments

Comments

@stronny
Copy link

stronny commented Oct 31, 2012

typedefs.rb: typedef :ushort, :wchar_t

Is there a reason to hardcode wchar_t size?

Here's a trivial C program that on my system produces: wchar_t: 4, wint_t: 4:

#include <stdio.h>
#include <wchar.h>

int main() { printf("wchar_t: %d, wint_t: %d\n", sizeof(wchar_t), sizeof(wint_t)); }

Related to this is the following issue (widechars.rb):

buffer_size = (txt.size + 1) * wchar_t.size
buffer = FFI::Buffer.new(wchar_t, buffer_size)

The second argument to Buffer.new is the number of elements in the buffer (http://rubydoc.info/github/ffi/ffi/master/FFI/Buffer#initialize-instance_method), not the size of the buffer in bytes, so buffer_size is twice what's needed and that's why this code works on my machine, ironically.

I am no expert in FFI and C and all this, but I'm sure there must be a way to determine the size of wchar_t and alias is appropriately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant