Created
June 15, 2009 11:17
-
-
Save radarek/130051 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "mkmf" | |
create_makefile("null") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <ruby.h> | |
VALUE string_with_null(VALUE self) { | |
char str[] = { 102, 111, 111, 0, 98, 97, 114 }; | |
return rb_str_new(str, 7); | |
} | |
void Init_null() { | |
rb_define_global_function("string_with_null", string_with_null, 0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby extconf.rb | |
creating Makefile | |
$ make | |
gcc -I. -I/opt/ruby-enterprise-1.8.6-20090520/lib/ruby/1.8/i686-linux -I/opt/ruby-enterprise-1.8.6-20090520/lib/ruby/1.8/i686-linux -I. -D_FILE_OFFSET_BITS=64 -fPIC -g -O2 -c null.c | |
gcc -shared -o null.so null.o -L. -L/opt/ruby-enterprise-1.8.6-20090520/lib -Wl,-R/opt/ruby-enterprise-1.8.6-20090520/lib -L. -rdynamic -Wl,-export-dynamic -ldl -lcrypt -lm -lc | |
$ ruby test.rb | |
foobar | |
7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "null" | |
puts string_with_null | |
puts string_with_null.size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment