Article 4687 of comp.lang.perl:
Xref: feenix.metronet.com comp.lang.perl:4687
Path: feenix.metronet.com!news.ecn.bgu.edu!mp.cs.niu.edu!vixen.cso.uiuc.edu!howland.reston.ans.net!spool.mu.edu!olivea!hal.com!perv.hal.COM!not-for-mail
From: aahz@hal.COM (Tom Wylie)
Newsgroups: comp.lang.perl
Subject: augmenting dbmopen to take read-only argument
Date: 30 Jul 1993 15:08:19 -0700
Organization: HaL Computer Systems, Inc.
Lines: 127
Distribution: world
Message-ID: <23c64jINNd7c@perv.hal.COM>
NNTP-Posting-Host: perv.hal.com

Ok, a week or two ago I posted saying we'd augmented dbmopen to take
a "read-only" 4th argument.  Below is what should be all the patches
for our changes.  WARNING:  The line numbers will mean nothing to your
source code.  You may well have to patch these in manually.  As I recall,
the only files we need to change were arg.h, eval.c, hash.c, and perly.y.

This offer void if you are not using a g/n/dbm which does
read-only vs. write-only locks.


arg.h:

***************
*** 778,784 ****
        A(1,0,0),       /* COMPLEMENT */
        A(1,0,0),       /* SELECT */
        A(1,0,0),       /* WRITE */
!       A(1,1,1),       /* DBMOPEN */
        A(1,0,0),       /* DBMCLOSE */
        A(1,1,0),       /* OPEN */
        A(1,0,0),       /* TRANS */
--- 781,787 ----
        A(1,0,0),       /* COMPLEMENT */
        A(1,0,0),       /* SELECT */
        A(1,0,0),       /* WRITE */
!       A(1,1,3),       /* DBMOPEN */
        A(1,0,0),       /* DBMCLOSE */
        A(1,1,0),       /* OPEN */
        A(1,0,0),       /* TRANS */


eval.c:

***************
*** 1231,1237 ****
            anum = (int)str_gnum(st[3]);
        else
            anum = -1;
!       value = (double)hdbmopen(stab_hash(stab),str_get(st[2]),anum);
        goto donumset;
  #else
        fatal("No dbm or ndbm on this machine");
--- 1234,1241 ----
            anum = (int)str_gnum(st[3]);
        else
            anum = -1;
!       value = (double)hdbmopen(stab_hash(stab),str_get(st[2]),anum,
!               ((sp - arglast[0]) == 4 ? (int) str_gnum(st[4]) : 0));
        goto donumset;
  #else
        fatal("No dbm or ndbm on this machine");


hash.c:

***************
*** 629,638 ****
  #endif
  
  bool
! hdbmopen(tb,fname,mode)
  register HASH *tb;
  char *fname;
  int mode;
  {
      if (!tb)
        return FALSE;
--- 632,642 ----
  #endif
  
  bool
! hdbmopen(tb,fname,mode,readonly)
  register HASH *tb;
  char *fname;
  int mode;
+ int readonly;
  {
      if (!tb)
        return FALSE;
***************
*** 646,655 ****
--- 650,661 ----
      }
      hclear(tb, FALSE);        /* clear cache */
  #ifdef HAS_GDBM
+     if (!readonly) {
      if (mode >= 0)
        tb->tbl_dbm = gdbm_open(fname, 0, GDBM_WRCREAT,mode, (void *) NULL);
      if (!tb->tbl_dbm)
        tb->tbl_dbm = gdbm_open(fname, 0, GDBM_WRITER, mode, (void *) NULL);
+     }
      if (!tb->tbl_dbm)
        tb->tbl_dbm = gdbm_open(fname, 0, GDBM_READER, mode, (void *) NULL);
  #else


perly.y:

***************
*** 797,803 ****
                                Nullarg,
                                Nullarg); }
        |       HSHFUN3 '(' hshword csexpr cexpr ')'
!                       { $$ = make_op($1, 3, $3, $4, $5); }
        |       bareword
        |       listop
        ;
--- 800,806 ----
                                Nullarg,
                                Nullarg); }
        |       HSHFUN3 '(' hshword csexpr cexpr ')'
!                       { $$ = make_op($1, 3, $3, $4, make_list($5)); }
        |       bareword
        |       listop
        ;



sorry these aren't "real" patches, but i don't feel like wrestling standard
patches out of cvs, and again, the line numbers will probably be meaningless
to you (our perl is way hacked up in places...  don't even ask).



Tom Wylie	| What is the difference between apathy and ignorance?
aahz@hal.com	| I don't know, and I don't care.



Article 4689 of comp.lang.perl:
Xref: feenix.metronet.com comp.lang.perl:4689
Path: feenix.metronet.com!news.ecn.bgu.edu!psuvax1!uwm.edu!cs.utexas.edu!uunet!olivea!hal.com!perv.hal.COM!not-for-mail
From: aahz@hal.COM (Tom Wylie)
Newsgroups: comp.lang.perl
Subject: more on read-only dbmopen
Date: 30 Jul 1993 15:21:21 -0700
Organization: HaL Computer Systems, Inc.
Lines: 31
Distribution: world
Message-ID: <23c6t1INNd92@perv.hal.COM>
NNTP-Posting-Host: perv.hal.com

Sigh...  forgot some stuff...


1.  The new way of calling dbmopen is:

	dbmopen(%ARRAY,DBMNAME,MODE[,READ-ONLY])

Behavior with 3 arguments is unchanged.  If a 4th argument is present,
and true, then it doesn't even bother trying to open the file in
create or write modes.  Thus, mode becomes a basically useless argument
if the read-only argument is true.


2.  I didn't include instructions on changing which dbm you are using.
Presumably those who are interested have already figured out how to do
this and have done it, or they wouldn't be interested.


3.  We originally toyed with the idea of having some special case of
mode would mean read-only (instead of adding a fourth argument), but
decided this wasn't going to be possible...  I think we basically figured
our only option would be to make negative modes translate as read-only,
but that this probably would not be backwards compatible.


I think that about covers it.


Tom Wylie	| What is the difference between apathy and ignorance?
aahz@hal.com	| I don't know, and I don't care.



