Skip to content

Commit

Permalink
Ruby 1.9 compatibility fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
FooBarWidget committed Feb 2, 2009
1 parent 03badf8 commit 0e43297
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 8 additions & 1 deletion ext/passenger/native_support.c
Expand Up @@ -34,6 +34,12 @@
#ifndef RARRAY_LEN
#define RARRAY_LEN(ary) RARRAY(ary)->len
#endif
#ifndef RSTRING_PTR
#define RSTRING_PTR(str) RSTRING(str)->ptr
#endif
#ifndef RSTRING_LEN
#define RSTRING_LEN(str) RSTRING(str)->len
#endif

static VALUE mPassenger;
static VALUE mNativeSupport;
Expand Down Expand Up @@ -178,7 +184,8 @@ create_unix_socket(VALUE self, VALUE filename, VALUE backlog) {
char *filename_str;
long filename_length;

filename_str = rb_str2cstr(filename, &filename_length);
filename_str = RSTRING_PTR(filename);
filename_length = RSTRING_LEN(filename);

fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (fd == -1) {
Expand Down
10 changes: 5 additions & 5 deletions lib/passenger/rack/request_handler.rb
Expand Up @@ -66,13 +66,13 @@ def process_request(env, input, output)
begin
output.write("Status: #{status}#{CRLF}")
headers[X_POWERED_BY] = PASSENGER_HEADER
headers.each do |k, vs|
vs.each do |v|
output.write("#{k}: #{v}#{CRLF}")
end
headers.each_pair do |k, v|
output.write("#{k}: #{v}#{CRLF}")
end
output.write(CRLF)
if body
if body.is_a?(String)
output.write(body)
elsif body
body.each do |s|
output.write(s)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/passenger/utils.rb
Expand Up @@ -18,15 +18,15 @@

require 'rubygems'
require 'thread'
if RUBY_PLATFORM != "java" && RUBY_VERSION < "1.8.7"
if (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby") && RUBY_VERSION < "1.8.7"
require 'fastthread'
end
require 'pathname'
require 'etc'
require 'fcntl'
require 'tempfile'
require 'passenger/exceptions'
if RUBY_PLATFORM != "java"
if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby"
require 'passenger/native_support'
end

Expand Down

2 comments on commit 0e43297

@nobu
Copy link

@nobu nobu commented on 0e43297 Feb 5, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-

RSTRING_PTR()
is not a direct replacement of
rb_str2cstr()
.
Use
StringValueCStr()
instead.
- Why you use
write
instead of
print
?
The latter can deal with multiple arguments.
You don’t need
body.each
, as you can write
output.print(*body)
.
- ‘fastthread’ is bundled with 1.8.6, and its gem has been left with some bugs.
$“.grep(%r”(?:\A|/)thread.(?!rb\z)\w+\z")0
returns true value if the extension library verion of ‘thread’.
- Some indentation seem broken :)

@FooBarWidget
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comments nobu.

I use write instead of print because print will append a newline to the output.

I am aware that it is claimed that fastthread’s functionality is bundled starting from a certain patchlevel of 1.8.6. But I once ran into a threading bug in 1.8.6, which seemed to be solved by loading fastthread.

As for the indentation, Github doesn’t properly display tabs.

Please sign in to comment.