Permalink
Browse files

Ruby 1.9 compatibility fixes.

  • Loading branch information...
FooBarWidget committed Feb 2, 2009
1 parent 03badf8 commit 0e43297b18f03e8b01c7c40897925b2ede6bc831
Showing with 15 additions and 8 deletions.
  1. +8 −1 ext/passenger/native_support.c
  2. +5 −5 lib/passenger/rack/request_handler.rb
  3. +2 −2 lib/passenger/utils.rb
@@ -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;
@@ -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) {
@@ -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
@@ -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

2 comments on commit 0e43297

@nobu

This comment has been minimized.

Copy link

nobu replied Feb 5, 2009

-

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

This comment has been minimized.

Copy link
Member

FooBarWidget replied Feb 14, 2009

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.