summaryrefslogtreecommitdiff
path: root/ext/sdbm
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-02-13 04:53:22 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-02-13 04:53:22 +0000
commit7f7236025953af6e0308995e073f9babbe149473 (patch)
tree9bf6db5c720b6039d2f913fbfa466ff46d221ca3 /ext/sdbm
parentc37c5419d251c5e72d413a4759eac2a34c1de3e4 (diff)
* parse.y (parser_parse_string): mention "regexp" in a error
message. a patch from Mauricio Fernandez <mfp at acm.org> [ruby-core:07340] * eval.c (rb_f_autoload): check if ruby_cbase is nil (during instance_eval for objects cannot have singleton classes, e.g. fixnums and symbols). [ruby-dev:28178] * gc.c (rb_gc_call_finalizer_at_exit): turn on during_gc while invoking finalizers. * gc.c (rb_gc_finalize_deferred): ditto. * io.c (rb_write_error2): use fwrite(3) if rb_stderr is not updated or is already freed. [ruby-dev:28313] * eval.c (error_line): include the class name of a surrounding method in error position description. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9918 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/sdbm')
-rw-r--r--ext/sdbm/_sdbm.c97
-rw-r--r--ext/sdbm/init.c161
2 files changed, 80 insertions, 178 deletions
diff --git a/ext/sdbm/_sdbm.c b/ext/sdbm/_sdbm.c
index d4cf621..f9a5888 100644
--- a/ext/sdbm/_sdbm.c
+++ b/ext/sdbm/_sdbm.c
@@ -143,10 +143,7 @@ static long masks[] = {
datum nullitem = {NULL, 0};
DBM *
-sdbm_open(file, flags, mode)
-register char *file;
-register int flags;
-register int mode;
+sdbm_open(register char *file, register int flags, register int mode)
{
register DBM *db;
register char *dirname;
@@ -175,11 +172,7 @@ register int mode;
}
DBM *
-sdbm_prep(dirname, pagname, flags, mode)
-char *dirname;
-char *pagname;
-int flags;
-int mode;
+sdbm_prep(char *dirname, char *pagname, int flags, int mode)
{
register DBM *db;
struct stat dstat;
@@ -235,8 +228,7 @@ int mode;
}
void
-sdbm_close(db)
-register DBM *db;
+sdbm_close(register DBM *db)
{
if (db == NULL)
errno = EINVAL;
@@ -248,9 +240,7 @@ register DBM *db;
}
datum
-sdbm_fetch(db, key)
-register DBM *db;
-datum key;
+sdbm_fetch(register DBM *db, datum key)
{
if (db == NULL || bad(key))
return errno = EINVAL, nullitem;
@@ -262,9 +252,7 @@ datum key;
}
int
-sdbm_delete(db, key)
-register DBM *db;
-datum key;
+sdbm_delete(register DBM *db, datum key)
{
if (db == NULL || bad(key))
return errno = EINVAL, -1;
@@ -288,11 +276,7 @@ datum key;
}
int
-sdbm_store(db, key, val, flags)
-register DBM *db;
-datum key;
-datum val;
-int flags;
+sdbm_store(register DBM *db, datum key, datum val, int flags)
{
int need;
register long hash;
@@ -350,10 +334,7 @@ int flags;
* giving up.
*/
static int
-makroom(db, hash, need)
-register DBM *db;
-long hash;
-int need;
+makroom(register DBM *db, long int hash, int need)
{
long newp;
char twin[PBLKSIZ];
@@ -450,8 +431,7 @@ int need;
* deletions aren't taken into account. (ndbm bug)
*/
datum
-sdbm_firstkey(db)
-register DBM *db;
+sdbm_firstkey(register DBM *db)
{
if (db == NULL)
return errno = EINVAL, nullitem;
@@ -470,8 +450,7 @@ register DBM *db;
}
datum
-sdbm_nextkey(db)
-register DBM *db;
+sdbm_nextkey(register DBM *db)
{
if (db == NULL)
return errno = EINVAL, nullitem;
@@ -482,9 +461,7 @@ register DBM *db;
* all important binary trie traversal
*/
static int
-getpage(db, hash)
-register DBM *db;
-register long hash;
+getpage(register DBM *db, register long int hash)
{
register int hbit;
register long dbit;
@@ -526,9 +503,7 @@ register long hash;
}
static int
-getdbit(db, dbit)
-register DBM *db;
-register long dbit;
+getdbit(register DBM *db, register long int dbit)
{
register long c;
register long dirb;
@@ -549,9 +524,7 @@ register long dbit;
}
static int
-setdbit(db, dbit)
-register DBM *db;
-register long dbit;
+setdbit(register DBM *db, register long int dbit)
{
register long c;
register long dirb;
@@ -585,8 +558,7 @@ register long dbit;
* the page, try the next page in sequence
*/
static datum
-getnext(db)
-register DBM *db;
+getnext(register DBM *db)
{
datum key;
@@ -661,9 +633,7 @@ static int seepair proto((char *, int, char *, int));
*/
static int
-fitpair(pag, need)
-char *pag;
-int need;
+fitpair(char *pag, int need)
{
register int n;
register int off;
@@ -680,10 +650,7 @@ int need;
}
static void
-putpair(pag, key, val)
-char *pag;
-datum key;
-datum val;
+putpair(char *pag, datum key, datum val)
{
register int n;
register int off;
@@ -711,9 +678,7 @@ datum val;
}
static datum
-getpair(pag, key)
-char *pag;
-datum key;
+getpair(char *pag, datum key)
{
register int i;
register int n;
@@ -733,9 +698,7 @@ datum key;
#ifdef SEEDUPS
static int
-duppair(pag, key)
-char *pag;
-datum key;
+duppair(char *pag, datum key)
{
register short *ino = (short *) pag;
return GET_SHORT(ino,0) > 0 &&
@@ -744,9 +707,7 @@ datum key;
#endif
static datum
-getnkey(pag, num)
-char *pag;
-int num;
+getnkey(char *pag, int num)
{
datum key;
register int off;
@@ -765,9 +726,7 @@ int num;
}
static int
-delpair(pag, key)
-char *pag;
-datum key;
+delpair(char *pag, datum key)
{
register int n;
register int i;
@@ -837,11 +796,7 @@ datum key;
* return 0 if not found.
*/
static int
-seepair(pag, n, key, siz)
-char *pag;
-register int n;
-register char *key;
-register int siz;
+seepair(char *pag, register int n, register char *key, register int siz)
{
register int i;
register int off = PBLKSIZ;
@@ -857,10 +812,7 @@ register int siz;
}
static void
-splpage(pag, new, sbit)
-char *pag;
-char *new;
-long sbit;
+splpage(char *pag, char *new, long int sbit)
{
datum key;
datum val;
@@ -901,8 +853,7 @@ long sbit;
* this could be made more rigorous.
*/
static int
-chkpage(pag)
-char *pag;
+chkpage(char *pag)
{
register int n;
register int off;
@@ -942,9 +893,7 @@ char *pag;
* 65587 even better.
*/
long
-sdbm_hash(str, len)
-register char *str;
-register int len;
+sdbm_hash(register char *str, register int len)
{
register unsigned long n = 0;
diff --git a/ext/sdbm/init.c b/ext/sdbm/init.c
index 9311a72..8eccbcc 100644
--- a/ext/sdbm/init.c
+++ b/ext/sdbm/init.c
@@ -41,8 +41,7 @@ closed_sdbm()
}
static void
-free_sdbm(dbmp)
- struct dbmdata *dbmp;
+free_sdbm(struct dbmdata *dbmp)
{
if (dbmp->di_dbm) sdbm_close(dbmp->di_dbm);
@@ -50,8 +49,7 @@ free_sdbm(dbmp)
}
static VALUE
-fsdbm_close(obj)
- VALUE obj;
+fsdbm_close(VALUE obj)
{
struct dbmdata *dbmp;
@@ -63,8 +61,7 @@ fsdbm_close(obj)
}
static VALUE
-fsdbm_closed(obj)
- VALUE obj;
+fsdbm_closed(VALUE obj)
{
struct dbmdata *dbmp;
@@ -77,19 +74,14 @@ fsdbm_closed(obj)
return Qfalse;
}
-static VALUE fsdbm_alloc _((VALUE));
static VALUE
-fsdbm_alloc(klass)
- VALUE klass;
+fsdbm_alloc(VALUE klass)
{
return Data_Wrap_Struct(klass, 0, free_sdbm, 0);
}
static VALUE
-fsdbm_initialize(argc, argv, obj)
- int argc;
- VALUE *argv;
- VALUE obj;
+fsdbm_initialize(int argc, VALUE *argv, VALUE obj)
{
VALUE file, vmode;
DBM *dbm;
@@ -129,10 +121,7 @@ fsdbm_initialize(argc, argv, obj)
}
static VALUE
-fsdbm_s_open(argc, argv, klass)
- int argc;
- VALUE *argv;
- VALUE klass;
+fsdbm_s_open(int argc, VALUE *argv, VALUE klass)
{
VALUE obj = Data_Wrap_Struct(klass, 0, free_sdbm, 0);
@@ -148,8 +137,7 @@ fsdbm_s_open(argc, argv, klass)
}
static VALUE
-fsdbm_fetch(obj, keystr, ifnone)
- VALUE obj, keystr, ifnone;
+fsdbm_fetch(VALUE obj, VALUE keystr, VALUE ifnone)
{
datum key, value;
struct dbmdata *dbmp;
@@ -170,17 +158,13 @@ fsdbm_fetch(obj, keystr, ifnone)
}
static VALUE
-fsdbm_aref(obj, keystr)
- VALUE obj, keystr;
+fsdbm_aref(VALUE obj, VALUE keystr)
{
return fsdbm_fetch(obj, keystr, Qnil);
}
static VALUE
-fsdbm_fetch_m(argc, argv, obj)
- int argc;
- VALUE *argv;
- VALUE obj;
+fsdbm_fetch_m(int argc, VALUE *argv, VALUE obj)
{
VALUE keystr, valstr, ifnone;
@@ -193,8 +177,7 @@ fsdbm_fetch_m(argc, argv, obj)
}
static VALUE
-fsdbm_index(obj, valstr)
- VALUE obj, valstr;
+fsdbm_index(VALUE obj, VALUE valstr)
{
datum key, val;
struct dbmdata *dbmp;
@@ -215,8 +198,7 @@ fsdbm_index(obj, valstr)
}
static VALUE
-fsdbm_select(obj)
- VALUE obj;
+fsdbm_select(VALUE obj)
{
VALUE new = rb_ary_new();
datum key, val;
@@ -240,10 +222,7 @@ fsdbm_select(obj)
}
static VALUE
-fsdbm_values_at(argc, argv, obj)
- int argc;
- VALUE *argv;
- VALUE obj;
+fsdbm_values_at(int argc, VALUE *argv, VALUE obj)
{
VALUE new = rb_ary_new2(argc);
int i;
@@ -256,16 +235,14 @@ fsdbm_values_at(argc, argv, obj)
}
static void
-fdbm_modify(obj)
- VALUE obj;
+fdbm_modify(VALUE obj)
{
rb_secure(4);
if (OBJ_FROZEN(obj)) rb_error_frozen("SDBM");
}
static VALUE
-fsdbm_delete(obj, keystr)
- VALUE obj, keystr;
+fsdbm_delete(VALUE obj, VALUE keystr)
{
datum key, value;
struct dbmdata *dbmp;
@@ -300,8 +277,7 @@ fsdbm_delete(obj, keystr)
}
static VALUE
-fsdbm_shift(obj)
- VALUE obj;
+fsdbm_shift(VALUE obj)
{
datum key, val;
struct dbmdata *dbmp;
@@ -324,8 +300,7 @@ fsdbm_shift(obj)
}
static VALUE
-fsdbm_delete_if(obj)
- VALUE obj;
+fsdbm_delete_if(VALUE obj)
{
datum key, val;
struct dbmdata *dbmp;
@@ -364,8 +339,7 @@ fsdbm_delete_if(obj)
}
static VALUE
-fsdbm_clear(obj)
- VALUE obj;
+fsdbm_clear(VALUE obj)
{
datum key;
struct dbmdata *dbmp;
@@ -385,8 +359,7 @@ fsdbm_clear(obj)
}
static VALUE
-fsdbm_invert(obj)
- VALUE obj;
+fsdbm_invert(VALUE obj)
{
datum key, val;
struct dbmdata *dbmp;
@@ -404,42 +377,8 @@ fsdbm_invert(obj)
return hash;
}
-static VALUE each_pair _((VALUE));
-
-static VALUE fsdbm_store _((VALUE,VALUE,VALUE));
-
-static VALUE
-update_i(pair, dbm)
- VALUE pair, dbm;
-{
- Check_Type(pair, T_ARRAY);
- if (RARRAY(pair)->len < 2) {
- rb_raise(rb_eArgError, "pair must be [key, value]");
- }
- fsdbm_store(dbm, RARRAY(pair)->ptr[0], RARRAY(pair)->ptr[1]);
- return Qnil;
-}
-
static VALUE
-fsdbm_update(obj, other)
- VALUE obj, other;
-{
- rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
- return obj;
-}
-
-static VALUE
-fsdbm_replace(obj, other)
- VALUE obj, other;
-{
- fsdbm_clear(obj);
- rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
- return obj;
-}
-
-static VALUE
-fsdbm_store(obj, keystr, valstr)
- VALUE obj, keystr, valstr;
+fsdbm_store(VALUE obj, VALUE keystr, VALUE valstr)
{
datum key, val;
struct dbmdata *dbmp;
@@ -474,8 +413,33 @@ fsdbm_store(obj, keystr, valstr)
}
static VALUE
-fsdbm_length(obj)
- VALUE obj;
+update_i(VALUE pair, VALUE dbm)
+{
+ Check_Type(pair, T_ARRAY);
+ if (RARRAY(pair)->len < 2) {
+ rb_raise(rb_eArgError, "pair must be [key, value]");
+ }
+ fsdbm_store(dbm, RARRAY(pair)->ptr[0], RARRAY(pair)->ptr[1]);
+ return Qnil;
+}
+
+static VALUE
+fsdbm_update(VALUE obj, VALUE other)
+{
+ rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
+ return obj;
+}
+
+static VALUE
+fsdbm_replace(VALUE obj, VALUE other)
+{
+ fsdbm_clear(obj);
+ rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
+ return obj;
+}
+
+static VALUE
+fsdbm_length(VALUE obj)
{
datum key;
struct dbmdata *dbmp;
@@ -494,8 +458,7 @@ fsdbm_length(obj)
}
static VALUE
-fsdbm_empty_p(obj)
- VALUE obj;
+fsdbm_empty_p(VALUE obj)
{
datum key;
struct dbmdata *dbmp;
@@ -518,8 +481,7 @@ fsdbm_empty_p(obj)
}
static VALUE
-fsdbm_each_value(obj)
- VALUE obj;
+fsdbm_each_value(VALUE obj)
{
datum key, val;
struct dbmdata *dbmp;
@@ -535,8 +497,7 @@ fsdbm_each_value(obj)
}
static VALUE
-fsdbm_each_key(obj)
- VALUE obj;
+fsdbm_each_key(VALUE obj)
{
datum key;
struct dbmdata *dbmp;
@@ -551,8 +512,7 @@ fsdbm_each_key(obj)
}
static VALUE
-fsdbm_each_pair(obj)
- VALUE obj;
+fsdbm_each_pair(VALUE obj)
{
datum key, val;
DBM *dbm;
@@ -572,8 +532,7 @@ fsdbm_each_pair(obj)
}
static VALUE
-fsdbm_keys(obj)
- VALUE obj;
+fsdbm_keys(VALUE obj)
{
datum key;
struct dbmdata *dbmp;
@@ -590,8 +549,7 @@ fsdbm_keys(obj)
}
static VALUE
-fsdbm_values(obj)
- VALUE obj;
+fsdbm_values(VALUE obj)
{
datum key, val;
struct dbmdata *dbmp;
@@ -609,8 +567,7 @@ fsdbm_values(obj)
}
static VALUE
-fsdbm_has_key(obj, keystr)
- VALUE obj, keystr;
+fsdbm_has_key(VALUE obj, VALUE keystr)
{
datum key, val;
struct dbmdata *dbmp;
@@ -627,8 +584,7 @@ fsdbm_has_key(obj, keystr)
}
static VALUE
-fsdbm_has_value(obj, valstr)
- VALUE obj, valstr;
+fsdbm_has_value(VALUE obj, VALUE valstr)
{
datum key, val;
struct dbmdata *dbmp;
@@ -649,8 +605,7 @@ fsdbm_has_value(obj, valstr)
}
static VALUE
-fsdbm_to_a(obj)
- VALUE obj;
+fsdbm_to_a(VALUE obj)
{
datum key, val;
struct dbmdata *dbmp;
@@ -669,8 +624,7 @@ fsdbm_to_a(obj)
}
static VALUE
-fsdbm_to_hash(obj)
- VALUE obj;
+fsdbm_to_hash(VALUE obj)
{
datum key, val;
struct dbmdata *dbmp;
@@ -689,8 +643,7 @@ fsdbm_to_hash(obj)
}
static VALUE
-fsdbm_reject(obj)
- VALUE obj;
+fsdbm_reject(VALUE obj)
{
return rb_hash_delete_if(fsdbm_to_hash(obj));
}