Article 5580 of comp.lang.perl: Xref: feenix.metronet.com comp.lang.perl:5580 Newsgroups: comp.lang.perl Path: feenix.metronet.com!news.utdallas.edu!hermes.chpc.utexas.edu!cs.utexas.edu!csc.ti.com!tilde.csc.ti.com!ra.csc.ti.com!enterprise!sunds From: sunds@.asictest.sc.ti.com (David M. Sundstrom, EC1 F5 , 997-5380, DMSX) Subject: Re: Read only dbm access for PERL? Message-ID: Keywords: dbm gdbm Sender: usenet@csc.ti.com Nntp-Posting-Host: enterprise.asic.sc.ti.com Reply-To: sunds@.asictest.sc.ti.com Organization: Texas Instruments References: <93243.084957NU013809@NDSUVM1.BITNET> Date: Wed, 1 Sep 1993 23:46:56 GMT Lines: 181 In article 084957NU013809@NDSUVM1.BITNET, NU013809@NDSUVM1.BITNET (Greg Wettstein) writes: > Just when you thought that you didn't need something...... Here are the articles as posted. I was the one who asked, but I have to confess that I haven't had time to implement the modifcations yet... I do plan on doing it soon. If anyone else has had other experiences, let me know. BTW, if using gdbm, you'll want to keep an eye on the gnu.util.bugs newsgroup. David Sundstrom sunds@asictest.sc.ti.com Texas Instruments. In article 23c64jINNd7c@perv.hal.COM, aahz@hal.COM (Tom Wylie) writes: > 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. > In article 23c6t1INNd92@perv.hal.COM, aahz@hal.COM (Tom Wylie) writes: > 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. >