Question about tempfile.rb - Ruby vs C

ruby

    Next

  • 1. https authentication & storing https page in string
    Hi, I have to write a ruby script which will give me the dynamic page on a https as a string. First I have to login in the https page. I am doing this using WATIR. Then I want the dynamic page to be stored in a string str. I am able to do the https login using WATIR. But when I try to get the dynamic page using HPRICOT, I am still getting the old https login page. Kindly suggest what to do. Regards, ND

Question about tempfile.rb - Ruby vs C

Postby Daniel Berger » Thu, 26 Apr 2007 04:13:56 GMT

Hi all,

Just curious - why was Ruby's temporary file handling class
(tempfile.rb) written in pure Ruby instead of using the tmpfile()
function? That function appears to be supported on most platforms,
including MS Windows.

Are there file locking or threading issues I'm not aware of?

The tmpfile() function does have the advantage of deleting itself when
all references to it are gone, instead of waiting until the Ruby
process itself dies. Perhaps there's no real advantage to that,
though?

Like I said, not an issue, just curious.

Regards,

Dan

PS - Below is a simple version I created for Solaris (before I
realized how ubiquitous the tmpfile function was):

#include <ruby.h>
#include <stdio.h>

#define VERSION "0.0.1"

VALUE mSolaris, cTempfile;

/* :call-seq:
 *    Solaris::Tmpfile.new => file
 *
 * Creates a new, anonymous temporary file in your Tempfile::TMPDIR
directory,
 * or /tmp if that cannot be accessed. If your $TMPDIR environment
variable is
 * set, it will be used instead. If $TMPDIR is not writable by the
process, it
 * will resort back to Tempfile::TMPDIR or /tmp.
 */
static VALUE tempfile_init(VALUE self){
   VALUE v_args[1];

   v_args[0] = INT2FIX(fileno(tmpfile()));

   rb_call_super(1, v_args);
}

void Init_tempfile(){
   mSolaris  = rb_define_module("Solaris");
   cTempfile = rb_define_class_under(mSolaris, "Tempfile", rb_cFile);

   rb_define_method(cTempfile, "initialize", tempfile_init, 0);

   rb_define_const(cTempfile, "TMPDIR", rb_str_new2(P_tmpdir));
   rb_define_const(cTempfile, "VERSION", rb_str_new2(VERSION));
}


Re: Question about tempfile.rb - Ruby vs C

Postby Tim Pease » Thu, 26 Apr 2007 04:43:26 GMT



The Ruby Tempfile class creates a finalizer that will delete the temp
file when it is collected by the garbage collector; the Ruby Tempfile
also deletes the temp file when it is closed. Your paragraph above
makes it sound like this is not the case.


I do not know why the C tmpfile function was not used. Maybe Matz
likes programming in Ruby more than programming in C   ;)

Blessings,
TwP


Re: Question about tempfile.rb - Ruby vs C

Postby Daniel Berger » Thu, 26 Apr 2007 05:54:32 GMT





I was basing my comment on the Pickaxe 2, p. 741 which says,
"...temporary files are automatically deleted when the Ruby process
terminates".

Regards,

Dan


Similar Threads:

1.tempfile.rb and unlink on windows

2.teaching ruby as cs intro?

3.[ANN] ruby-stemp - Secure tempfile extension for Ruby

4.rake : rakefile vs. rakefile.rb

Why does rake not recognize "rakefile.rb" as a default rakefile? I just had 
to change the file name to just "rakefile" to get it to work (which messes 
up editors etc. that look for ".rb" extensions).

Thanks.


5.RubyOSA vs. rb-Applescript

Does anyone have a comparison of the two?  Any reason to prefer one 
over the other?

Does Ruby OSA have some quasi official status?


6. Gem question: "win32" vs. "ruby"

7. Rake vs SCons vs Boost.Build v2 vs Perforce Jam

8. "ruby script.rb" versus "xterm -e ruby script.rb"



Return to ruby

 

Who is online

Users browsing this forum: No registered users and 2 guest