about summary refs log tree commit homepage
path: root/ext/clogger_ext/ruby_1_9_compat.h
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-06-06 05:17:14 +0000
committerEric Wong <normalperson@yhbt.net>2010-06-06 06:26:45 +0000
commitb895d3d0393a647d3602783bc53bf68e223e51c9 (patch)
treedb7a7ed6d0f3200f27617a79aacd402d809eb722 /ext/clogger_ext/ruby_1_9_compat.h
parentbc1d1df38d7803ce9fdae05fc5129051eeed89e0 (diff)
downloadclogger-b895d3d0393a647d3602783bc53bf68e223e51c9.tar.gz
Certain configurations of Rainbows! (and Zbatery) are able to
use the return value of body.to_path to serve static files
more efficiently.

This also allows middleware like Rack::Contrib::Sendfile to
work properly higher up the stack, too.
Diffstat (limited to 'ext/clogger_ext/ruby_1_9_compat.h')
-rw-r--r--ext/clogger_ext/ruby_1_9_compat.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/ext/clogger_ext/ruby_1_9_compat.h b/ext/clogger_ext/ruby_1_9_compat.h
index e0ba4ac..b6caa96 100644
--- a/ext/clogger_ext/ruby_1_9_compat.h
+++ b/ext/clogger_ext/ruby_1_9_compat.h
@@ -11,6 +11,12 @@
 #ifndef RARRAY_LEN
 #  define RARRAY_LEN(s) (RARRAY(s)->len)
 #endif
+#ifndef RSTRUCT_PTR
+#  define RSTRUCT_PTR(s) (RSTRUCT(s)->ptr)
+#endif
+#ifndef RSTRUCT_LEN
+#  define RSTRUCT_LEN(s) (RSTRUCT(s)->len)
+#endif
 
 #ifndef HAVE_RB_STR_SET_LEN
 /* this is taken from Ruby 1.8.7, 1.8.6 may not have it */
@@ -21,3 +27,34 @@ static void rb_18_str_set_len(VALUE str, long len)
 }
 #define rb_str_set_len(str,len) rb_18_str_set_len(str,len)
 #endif
+
+#if ! HAVE_RB_IO_T
+#  define rb_io_t OpenFile
+#endif
+
+#ifdef GetReadFile
+#  define FPTR_TO_FD(fptr) (fileno(GetReadFile(fptr)))
+#else
+#  if !HAVE_RB_IO_T || (RUBY_VERSION_MAJOR == 1 && RUBY_VERSION_MINOR == 8)
+#    define FPTR_TO_FD(fptr) fileno(fptr->f)
+#  else
+#    define FPTR_TO_FD(fptr) fptr->fd
+#  endif
+#endif
+
+static int my_fileno(VALUE io)
+{
+        rb_io_t *fptr;
+
+        for (;;) {
+                switch (TYPE(io)) {
+                case T_FILE: {
+                        GetOpenFile(io, fptr);
+                        return FPTR_TO_FD(fptr);
+                }
+                default:
+                        io = rb_convert_type(io, T_FILE, "IO", "to_io");
+                        /* retry */
+                }
+        }
+}