>>>>> "P" == Paul Brannan <paul / atdesk.com> writes:

P> I'm not sure I understand why either.  An instance variable makes
P> perfect sense here.

 Something like this, in this case (not tested)

pigeon% cat sv.c
#include <ruby.h>
#include <rubyio.h>

static VALUE
sv_setvbuf(int argc, VALUE *argv, VALUE obj)
{
    VALUE buf, mode;
    int c_mode;
    OpenFile * fptr;
    FILE * f1, * f2;
    char * c_buf = NULL;
    size_t size = 0;

    if (rb_scan_args(argc, argv, "11", &mode, &buf) == 2) {
        buf = rb_str_to_str(buf);
        c_buf = RSTRING(buf)->ptr;
        size = RSTRING(buf)->len;
        rb_ivar_set(obj, rb_intern("__buff__"), buf);
    }
    c_mode = NUM2INT(mode);
    GetOpenFile(obj, fptr);
    f1 = GetReadFile(fptr);
    f2 = GetWriteFile(fptr);
    setvbuf(f1, c_buf, c_mode, size);
    if (f1 != f2) {
        setvbuf(f2, c_buf, c_mode, size);
    }
    return Qnil;
}

void Init_sv()
{
    rb_define_method(rb_cIO, "setvbuf", sv_setvbuf, -1);
    rb_define_const(rb_cIO, "NBF", INT2NUM(_IONBF));
    rb_define_const(rb_cIO, "LBF", INT2NUM(_IOLBF));
    rb_define_const(rb_cIO, "FBF", INT2NUM(_IOFBF));
}
pigeon% 



Guy Decoux