ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* ext/gdbm and multiple readers at a time
@ 2003-06-03 11:49 Mauricio Fernández
  0 siblings, 0 replies; only message in thread
From: Mauricio Fernández @ 2003-06-03 11:49 UTC (permalink / raw
  To: ruby-core


man gdbm says

A  process that opens a gdbm file is designated as a "reader" or a
"writer".  Only one writer may open a gdbm file and many readers
                                                    ============ 
may open the file.  Readers and writers can not open the gdbm
file at the same time.

However the gdbm extension didn't seem to allow that.
I ended up doing the following:

--- ruby-1.8.0.orig/ext/gdbm/gdbm.c     Tue Jun  3 13:25:17 2003
+++ ruby-1.8.0/ext/gdbm/gdbm.c  Tue Jun  3 13:27:17 2003
@@ -97,6 +97,8 @@

     if (!NIL_P(vflags))
         flags = NUM2INT(vflags);
+    else
+           flags = GDBM_READER;

     SafeStringValue(file);

@@ -106,10 +108,7 @@
                        GDBM_WRCREAT|flags, mode, MY_FATAL_FUNC);
     if (!dbm)
        dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE,
-                       GDBM_WRITER|flags, 0, MY_FATAL_FUNC);
-    if (!dbm)
-       dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE,
-                       GDBM_READER|flags, 0, MY_FATAL_FUNC);
+                       flags, 0, MY_FATAL_FUNC);

     if (!dbm) {
        if (mode == -1) return Qnil;
@@ -974,12 +973,12 @@
     rb_define_method(rb_cGDBM, "to_hash", fgdbm_to_hash, 0);

     /* flags for gdbm_opn() */
-    /*
+
     rb_define_const(rb_cGDBM, "READER",  INT2FIX(GDBM_READER));
     rb_define_const(rb_cGDBM, "WRITER",  INT2FIX(GDBM_WRITER));
     rb_define_const(rb_cGDBM, "WRCREAT", INT2FIX(GDBM_WRCREAT));
     rb_define_const(rb_cGDBM, "NEWDB",   INT2FIX(GDBM_NEWDB));
-    */
+
     rb_define_const(rb_cGDBM, "FAST", INT2FIX(GDBM_FAST));
     /* this flag is obsolete in gdbm 1.8.
        On gdbm 1.8, fast mode is default behavior. */


Now I can do
  require 'gdbm'
  GDBM.open("something.db", GDBM::READER) do |db|
	.... = db["bla"]
  end

in several processes/threads at a time.

My patch is so simple there must be something wrong about it, otherwise
it'd be in Ruby already :-P

-- 
 _           _                             
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
	Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

We apologize for the inconvenience, but we'd still like yout to test out
this kernel. 
	-- Linus Torvalds, announcing another kernel patch

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-06-03 11:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-03 11:49 ext/gdbm and multiple readers at a time Mauricio Fernández

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).