summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-02-13 05:09:11 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-02-13 05:09:11 +0000
commit8be410f0653bfb22970381447acf685af4795c00 (patch)
tree8946eb2e9437f998c332d5d7326032efce9dd141 /ext
parent32ce4317d8077c926d0c00172cfac8001dd5ff98 (diff)
* io.c (rb_io_ctl): do not call ioctl/fcntl for f2, if f and f2
have same fileno. * eval.c (rb_load): raise LocaJumpError if unexpected local jumps appear during load. * ext/socket/socket.c (bsock_close_read): don't call rb_thread_fd_close(); it's supposed to be called by io_io_close(). * ext/socket/socket.c (bsock_close_read): do not modify f and f2. * ext/socket/socket.c (bsock_close_write): ditto. * ext/socket/socket.c (sock_new): avoid dup(2) on sockets. * parse.y (primary): preserve and clear in_single and in_def using stack to prevent nested method errors in singleton class bodies. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1177 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/dbm/dbm.c71
-rw-r--r--ext/gdbm/gdbm.c243
-rw-r--r--ext/socket/extconf.rb4
-rw-r--r--ext/socket/socket.c20
4 files changed, 269 insertions, 69 deletions
diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c
index 55c60bf..3744c40 100644
--- a/ext/dbm/dbm.c
+++ b/ext/dbm/dbm.c
@@ -22,7 +22,7 @@
#include <fcntl.h>
#include <errno.h>
-VALUE cDBM;
+VALUE cDBM, rb_eDBMError;
struct dbmdata {
int di_size;
@@ -37,6 +37,7 @@ closed_dbm()
#define GetDBM(obj, dbmp) {\
Data_Get_Struct(obj, struct dbmdata, dbmp);\
+ if (dbmp == 0) closed_dbm();\
if (dbmp->di_dbm == 0) closed_dbm();\
}
@@ -44,21 +45,35 @@ static void
free_dbm(dbmp)
struct dbmdata *dbmp;
{
- if (dbmp->di_dbm) dbm_close(dbmp->di_dbm);
- free(dbmp);
+ if (dbmp) {
+ if (dbmp->di_dbm) dbm_close(dbmp->di_dbm);
+ free(dbmp);
+ }
}
+static VALUE fdbm_close _((VALUE));
+
static VALUE
-fdbm_s_open(argc, argv, klass)
+fdbm_s_new(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
{
+ VALUE obj = Data_Wrap_Struct(klass, 0, free_dbm, 0);
+ rb_obj_call_init(obj, argc, argv);
+ return obj;
+}
+
+static VALUE
+fdbm_initialize(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
+{
VALUE file, vmode;
DBM *dbm;
struct dbmdata *dbmp;
int mode;
- VALUE obj;
if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
mode = 0666; /* default value */
@@ -87,7 +102,8 @@ fdbm_s_open(argc, argv, klass)
rb_sys_fail(RSTRING(file)->ptr);
}
- obj = Data_Make_Struct(klass,struct dbmdata,0,free_dbm,dbmp);
+ dbmp = ALLOC(struct dbmdata);
+ DATA_PTR(obj) = dbmp;
dbmp->di_dbm = dbm;
dbmp->di_size = -1;
@@ -95,6 +111,25 @@ fdbm_s_open(argc, argv, klass)
}
static VALUE
+fdbm_s_open(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
+{
+ VALUE obj = Data_Wrap_Struct(klass, 0, free_dbm, 0);
+
+ if (NIL_P(fdbm_initialize(argc, argv, obj))) {
+ return Qnil;
+ }
+
+ if (rb_block_given_p()) {
+ return rb_ensure(rb_yield, obj, fdbm_close, obj);
+ }
+
+ return obj;
+}
+
+static VALUE
fdbm_close(obj)
VALUE obj;
{
@@ -143,10 +178,14 @@ fdbm_fetch_m(argc, argv, obj)
VALUE *argv;
VALUE obj;
{
- VALUE keystr, ifnone;
+ VALUE keystr, valstr, ifnone;
rb_scan_args(argc, argv, "11", &keystr, &ifnone);
- return fdbm_fetch(obj, keystr, ifnone);
+ valstr = fdbm_fetch(obj, keystr, ifnone);
+ if (argc == 1 && !rb_block_given_p() && NIL_P(valstr))
+ rb_raise(rb_eIndexError, "key not found");
+
+ return valstr;
}
static VALUE
@@ -166,8 +205,9 @@ fdbm_index(obj, valstr)
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);
if (val.dsize == RSTRING(valstr)->len &&
- memcmp(val.dptr, RSTRING(valstr)->ptr, val.dsize) == 0)
+ memcmp(val.dptr, RSTRING(valstr)->ptr, val.dsize) == 0) {
return rb_tainted_str_new(key.dptr, key.dsize);
+ }
}
return Qnil;
}
@@ -213,7 +253,7 @@ fdbm_delete(obj, keystr)
if (dbm_delete(dbm, key)) {
dbmp->di_size = -1;
- rb_raise(rb_eRuntimeError, "dbm_delete failed");
+ rb_raise(rb_eDBMError, "dbm_delete failed");
}
else if (dbmp->di_size >= 0) {
dbmp->di_size--;
@@ -262,7 +302,7 @@ fdbm_delete_if(obj)
valstr = rb_tainted_str_new(val.dptr, val.dsize);
if (RTEST(rb_yield(rb_assoc_new(keystr, valstr)))) {
if (dbm_delete(dbm, key)) {
- rb_raise(rb_eRuntimeError, "dbm_delete failed");
+ rb_raise(rb_eDBMError, "dbm_delete failed");
}
}
}
@@ -283,7 +323,7 @@ fdbm_clear(obj)
dbmp->di_size = -1;
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
if (dbm_delete(dbm, key)) {
- rb_raise(rb_eRuntimeError, "dbm_delete failed");
+ rb_raise(rb_eDBMError, "dbm_delete failed");
}
}
return obj;
@@ -374,7 +414,7 @@ fdbm_store(obj, keystr, valstr)
dbm_clearerr(dbm);
#endif
if (errno == EPERM) rb_sys_fail(0);
- rb_raise(rb_eRuntimeError, "dbm_store failed");
+ rb_raise(rb_eDBMError, "dbm_store failed");
}
return valstr;
@@ -618,10 +658,13 @@ void
Init_dbm()
{
cDBM = rb_define_class("DBM", rb_cObject);
+ rb_eDBMError = rb_define_class("DBMError", rb_eStandardError);
rb_include_module(cDBM, rb_mEnumerable);
+ rb_define_singleton_method(cDBM, "new", fdbm_s_new, -1);
rb_define_singleton_method(cDBM, "open", fdbm_s_open, -1);
- rb_define_singleton_method(cDBM, "new", fdbm_s_open, -1);
+
+ rb_define_method(cDBM, "initialize", fdbm_initialize, -1);
rb_define_method(cDBM, "close", fdbm_close, 0);
rb_define_method(cDBM, "[]", fdbm_aref, 1);
rb_define_method(cDBM, "fetch", fdbm_fetch_m, -1);
diff --git a/ext/gdbm/gdbm.c b/ext/gdbm/gdbm.c
index fad06fa..816c5d7 100644
--- a/ext/gdbm/gdbm.c
+++ b/ext/gdbm/gdbm.c
@@ -14,7 +14,7 @@
#include <fcntl.h>
#include <errno.h>
-VALUE cGDBM;
+VALUE cGDBM, rb_eGDBMError;
#define MY_BLOCK_SIZE (2048)
#define MY_FATAL_FUNC (0)
@@ -32,6 +32,7 @@ closed_dbm()
#define GetDBM(obj, dbmp) {\
Data_Get_Struct(obj, struct dbmdata, dbmp);\
+ if (dbmp == 0) closed_dbm();\
if (dbmp->di_dbm == 0) closed_dbm();\
}
@@ -39,23 +40,37 @@ static void
free_dbm(dbmp)
struct dbmdata *dbmp;
{
- if (dbmp->di_dbm) gdbm_close(dbmp->di_dbm);
- free(dbmp);
+ if (dbmp) {
+ if (dbmp->di_dbm) gdbm_close(dbmp->di_dbm);
+ free(dbmp);
+ }
}
+static VALUE fgdbm_close _((VALUE));
+
static VALUE
-fgdbm_s_open(argc, argv, klass)
+fgdbm_s_new(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
{
- VALUE file, vmode;
+ VALUE obj = Data_Wrap_Struct(klass, 0, free_dbm, 0);
+ rb_obj_call_init(obj, argc, argv);
+ return obj;
+}
+
+static VALUE
+fgdbm_initialize(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
+{
+ VALUE file, vmode, vflags;
GDBM_FILE dbm;
struct dbmdata *dbmp;
- int mode;
- VALUE obj;
+ int mode, flags = 0;
- if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
+ if (rb_scan_args(argc, argv, "12", &file, &vmode, &vflags) == 1) {
mode = 0666; /* default value */
}
else if (NIL_P(vmode)) {
@@ -64,25 +79,36 @@ fgdbm_s_open(argc, argv, klass)
else {
mode = NUM2INT(vmode);
}
+
+ if (!NIL_P(vflags))
+ flags = NUM2INT(vflags);
+
Check_SafeStr(file);
dbm = 0;
if (mode >= 0)
dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE,
- O_RDWR|O_CREAT, mode, MY_FATAL_FUNC);
+ GDBM_WRCREAT|flags, mode, MY_FATAL_FUNC);
if (!dbm)
dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE,
- O_RDWR, 0, MY_FATAL_FUNC);
+ GDBM_WRITER|flags, 0, MY_FATAL_FUNC);
if (!dbm)
dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE,
- O_RDONLY, 0, MY_FATAL_FUNC);
+ GDBM_READER|flags, 0, MY_FATAL_FUNC);
if (!dbm) {
if (mode == -1) return Qnil;
- rb_sys_fail(RSTRING(file)->ptr);
+
+ if (gdbm_errno == GDBM_FILE_OPEN_ERROR ||
+ gdbm_errno == GDBM_CANT_BE_READER ||
+ gdbm_errno == GDBM_CANT_BE_WRITER)
+ rb_sys_fail(RSTRING(file)->ptr);
+ else
+ rb_raise(rb_eGDBMError, "%s", gdbm_strerror(gdbm_errno));
}
- obj = Data_Make_Struct(klass,struct dbmdata,0,free_dbm,dbmp);
+ dbmp = ALLOC(struct dbmdata);
+ DATA_PTR(obj) = dbmp;
dbmp->di_dbm = dbm;
dbmp->di_size = -1;
@@ -90,6 +116,25 @@ fgdbm_s_open(argc, argv, klass)
}
static VALUE
+fgdbm_s_open(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
+{
+ VALUE obj = Data_Wrap_Struct(klass, 0, free_dbm, 0);
+
+ if (NIL_P(fgdbm_initialize(argc, argv, obj))) {
+ return Qnil;
+ }
+
+ if (rb_block_given_p()) {
+ return rb_ensure(rb_yield, obj, fgdbm_close, obj);
+ }
+
+ return obj;
+}
+
+static VALUE
fgdbm_close(obj)
VALUE obj;
{
@@ -102,6 +147,21 @@ fgdbm_close(obj)
return Qnil;
}
+static datum
+gdbm_fetch_1(dbm, key)
+ GDBM_FILE dbm;
+ datum key;
+{
+ static char *ptr;
+ datum val;
+
+ val = gdbm_fetch(dbm, key);
+ if (ptr) free(ptr);
+ ptr = val.dptr;
+
+ return val;
+}
+
static VALUE
fgdbm_fetch(obj, keystr, ifnone)
VALUE obj, keystr, ifnone;
@@ -116,7 +176,7 @@ fgdbm_fetch(obj, keystr, ifnone)
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
- value = gdbm_fetch(dbm, key);
+ value = gdbm_fetch_1(dbm, key);
if (value.dptr == 0) {
if (ifnone == Qnil && rb_block_given_p())
return rb_yield(rb_tainted_str_new(key.dptr, key.dsize));
@@ -138,10 +198,14 @@ fgdbm_fetch_m(argc, argv, obj)
VALUE *argv;
VALUE obj;
{
- VALUE keystr, ifnone;
+ VALUE keystr, valstr, ifnone;
rb_scan_args(argc, argv, "11", &keystr, &ifnone);
- return fgdbm_fetch(obj, keystr, ifnone);
+ valstr = fgdbm_fetch(obj, keystr, ifnone);
+ if (argc == 1 && !rb_block_given_p() && NIL_P(valstr))
+ rb_raise(rb_eIndexError, "key not found");
+
+ return valstr;
}
static VALUE
@@ -159,7 +223,7 @@ fgdbm_index(obj, valstr)
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
for (key = gdbm_firstkey(dbm); key.dptr; key = gdbm_nextkey(dbm, key)) {
- val = gdbm_fetch(dbm, key);
+ val = gdbm_fetch_1(dbm, key);
if (val.dsize == RSTRING(valstr)->len &&
memcmp(val.dptr, RSTRING(valstr)->ptr, val.dsize) == 0)
return rb_tainted_str_new(key.dptr, key.dsize);
@@ -188,7 +252,7 @@ static VALUE
fgdbm_delete(obj, keystr)
VALUE obj, keystr;
{
- datum key, value;
+ datum key;
struct dbmdata *dbmp;
GDBM_FILE dbm;
@@ -200,15 +264,14 @@ fgdbm_delete(obj, keystr)
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
- value = gdbm_fetch(dbm, key);
- if (value.dptr == 0) {
+ if (!gdbm_exists(dbm, key)) {
if (rb_block_given_p()) rb_yield(keystr);
return Qnil;
}
if (gdbm_delete(dbm, key)) {
dbmp->di_size = -1;
- rb_raise(rb_eRuntimeError, "gdbm_delete failed");
+ rb_raise(rb_eGDBMError, "%s", gdbm_strerror(gdbm_errno));
}
else if (dbmp->di_size >= 0) {
dbmp->di_size--;
@@ -231,7 +294,7 @@ fgdbm_shift(obj)
key = gdbm_firstkey(dbm);
if (!key.dptr) return Qnil;
- val = gdbm_fetch(dbm, key);
+ val = gdbm_fetch_1(dbm, key);
gdbm_delete(dbm, key);
keystr = rb_tainted_str_new(key.dptr, key.dsize);
@@ -252,12 +315,12 @@ fgdbm_delete_if(obj)
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
for (key = gdbm_firstkey(dbm); key.dptr; key = gdbm_nextkey(dbm, key)) {
- val = gdbm_fetch(dbm, key);
+ val = gdbm_fetch_1(dbm, key);
keystr = rb_tainted_str_new(key.dptr, key.dsize);
valstr = rb_tainted_str_new(val.dptr, val.dsize);
if (RTEST(rb_yield(rb_assoc_new(keystr, valstr)))) {
if (gdbm_delete(dbm, key)) {
- rb_raise(rb_eRuntimeError, "gdbm_delete failed");
+ rb_raise(rb_eGDBMError, "%s", gdbm_strerror(gdbm_errno));
}
}
}
@@ -279,7 +342,7 @@ fgdbm_clear(obj)
for (key = gdbm_firstkey(dbm); key.dptr; key = nextkey) {
nextkey = gdbm_nextkey(dbm, key);
if (gdbm_delete(dbm, key)) {
- rb_raise(rb_eRuntimeError, "gdbm_delete failed");
+ rb_raise(rb_eGDBMError, "%s", gdbm_strerror(gdbm_errno));
}
}
return obj;
@@ -298,7 +361,7 @@ fgdbm_invert(obj)
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
for (key = gdbm_firstkey(dbm); key.dptr; key = gdbm_nextkey(dbm, key)) {
- val = gdbm_fetch(dbm, key);
+ val = gdbm_fetch_1(dbm, key);
keystr = rb_tainted_str_new(key.dptr, key.dsize);
valstr = rb_tainted_str_new(val.dptr, val.dsize);
rb_hash_aset(hash, valstr, keystr);
@@ -367,7 +430,7 @@ fgdbm_store(obj, keystr, valstr)
dbm = dbmp->di_dbm;
if (gdbm_store(dbm, key, val, GDBM_REPLACE)) {
if (errno == EPERM) rb_sys_fail(0);
- rb_raise(rb_eRuntimeError, "gdbm_store failed");
+ rb_raise(rb_eGDBMError, "%s", gdbm_strerror(gdbm_errno));
}
return valstr;
@@ -429,7 +492,7 @@ fgdbm_each_value(obj)
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
for (key = gdbm_firstkey(dbm); key.dptr; key = gdbm_nextkey(dbm, key)) {
- val = gdbm_fetch(dbm, key);
+ val = gdbm_fetch_1(dbm, key);
rb_yield(rb_tainted_str_new(val.dptr, val.dsize));
}
return obj;
@@ -464,7 +527,7 @@ fgdbm_each_pair(obj)
dbm = dbmp->di_dbm;
for (key = gdbm_firstkey(dbm); key.dptr; key = gdbm_nextkey(dbm, key)) {
- val = gdbm_fetch(dbm, key);
+ val = gdbm_fetch_1(dbm, key);
keystr = rb_tainted_str_new(key.dptr, key.dsize);
valstr = rb_tainted_str_new(val.dptr, val.dsize);
rb_yield(rb_assoc_new(keystr, valstr));
@@ -507,7 +570,7 @@ fgdbm_values(obj)
ary = rb_ary_new();
for (key = gdbm_firstkey(dbm); key.dptr; key = gdbm_nextkey(dbm, key)) {
- val = gdbm_fetch(dbm, key);
+ val = gdbm_fetch_1(dbm, key);
rb_ary_push(ary, rb_tainted_str_new(val.dptr, val.dsize));
}
@@ -537,7 +600,7 @@ static VALUE
fgdbm_has_value(obj, valstr)
VALUE obj, valstr;
{
- datum key, val;
+ datum key;
struct dbmdata *dbmp;
GDBM_FILE dbm;
@@ -548,7 +611,7 @@ fgdbm_has_value(obj, valstr)
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
for (key = gdbm_firstkey(dbm); key.dptr; key = gdbm_nextkey(dbm, key)) {
- val = gdbm_fetch(dbm, key);
+ val = gdbm_fetch_1(dbm, key);
if (val.dsize == RSTRING(valstr)->len &&
memcmp(val.dptr, RSTRING(valstr)->ptr, val.dsize) == 0)
return Qtrue;
@@ -570,7 +633,7 @@ fgdbm_to_a(obj)
ary = rb_ary_new();
for (key = gdbm_firstkey(dbm); key.dptr; key = gdbm_nextkey(dbm, key)) {
- val = gdbm_fetch(dbm, key);
+ val = gdbm_fetch_1(dbm, key);
rb_ary_push(ary, rb_assoc_new(rb_tainted_str_new(key.dptr, key.dsize),
rb_tainted_str_new(val.dptr, val.dsize)));
}
@@ -593,6 +656,88 @@ fgdbm_reorganize(obj)
}
static VALUE
+fgdbm_sync(obj)
+ VALUE obj;
+{
+ struct dbmdata *dbmp;
+ GDBM_FILE dbm;
+
+ rb_secure(4);
+ GetDBM(obj, dbmp);
+ dbm = dbmp->di_dbm;
+ gdbm_sync(dbm);
+ return obj;
+}
+
+static VALUE
+fgdbm_set_cachesize(obj, val)
+ VALUE obj, val;
+{
+ struct dbmdata *dbmp;
+ GDBM_FILE dbm;
+ VALUE hash;
+ int optval;
+
+ GetDBM(obj, dbmp);
+ dbm = dbmp->di_dbm;
+
+ optval = FIX2INT(val);
+ if (gdbm_setopt(dbm, GDBM_CACHESIZE, &optval, sizeof(optval)) == -1) {
+ rb_raise(rb_eGDBMError, "%s", gdbm_strerror(gdbm_errno));
+ }
+ return val;
+}
+
+static VALUE
+fgdbm_set_fastmode(obj, val)
+ VALUE obj, val;
+{
+ struct dbmdata *dbmp;
+ GDBM_FILE dbm;
+ VALUE hash;
+ int optval;
+
+ GetDBM(obj, dbmp);
+ dbm = dbmp->di_dbm;
+
+ optval = 0;
+ if (RTEST(val))
+ optval = 1;
+
+ if (gdbm_setopt(dbm, GDBM_FASTMODE, &optval, sizeof(optval)) == -1) {
+ rb_raise(rb_eGDBMError, "%s", gdbm_strerror(gdbm_errno));
+ }
+ return val;
+}
+
+static VALUE
+fgdbm_set_syncmode(obj, val)
+ VALUE obj, val;
+{
+#if !defined(GDBM_SYNCMODE)
+ fgdbm_set_fastmode(obj, RTEST(val) ? Qfalse : Qtrue);
+ return val;
+#else
+ struct dbmdata *dbmp;
+ GDBM_FILE dbm;
+ VALUE hash;
+ int optval;
+
+ GetDBM(obj, dbmp);
+ dbm = dbmp->di_dbm;
+
+ optval = 0;
+ if (RTEST(val))
+ optval = 1;
+
+ if (gdbm_setopt(dbm, GDBM_FASTMODE, &optval, sizeof(optval)) == -1) {
+ rb_raise(rb_eGDBMError, "%s", gdbm_strerror(gdbm_errno));
+ }
+ return val;
+#endif
+}
+
+static VALUE
fgdbm_to_hash(obj)
VALUE obj;
{
@@ -606,7 +751,7 @@ fgdbm_to_hash(obj)
hash = rb_hash_new();
for (key = gdbm_firstkey(dbm); key.dptr; key = gdbm_nextkey(dbm, key)) {
- val = gdbm_fetch(dbm, key);
+ val = gdbm_fetch_1(dbm, key);
rb_hash_aset(hash, rb_tainted_str_new(key.dptr, key.dsize),
rb_tainted_str_new(val.dptr, val.dsize));
}
@@ -625,10 +770,13 @@ void
Init_gdbm()
{
cGDBM = rb_define_class("GDBM", rb_cObject);
+ rb_eGDBMError = rb_define_class("GDBMError", rb_eStandardError);
rb_include_module(cGDBM, rb_mEnumerable);
+ rb_define_singleton_method(cGDBM, "new", fgdbm_s_new, -1);
rb_define_singleton_method(cGDBM, "open", fgdbm_s_open, -1);
- rb_define_singleton_method(cGDBM, "new", fgdbm_s_open, -1);
+
+ rb_define_method(cGDBM, "initialize", fgdbm_initialize, -1);
rb_define_method(cGDBM, "close", fgdbm_close, 0);
rb_define_method(cGDBM, "[]", fgdbm_aref, 1);
rb_define_method(cGDBM, "fetch", fgdbm_fetch_m, -1);
@@ -656,6 +804,11 @@ Init_gdbm()
rb_define_method(cGDBM,"update", fgdbm_update, 1);
rb_define_method(cGDBM,"replace", fgdbm_replace, 1);
rb_define_method(cGDBM,"reorganize", fgdbm_reorganize, 0);
+ rb_define_method(cGDBM,"sync", fgdbm_sync, 0);
+ /* rb_define_method(cGDBM,"setopt", fgdbm_setopt, 2); */
+ rb_define_method(cGDBM,"cachesize=", fgdbm_set_cachesize, 1);
+ rb_define_method(cGDBM,"fastmode=", fgdbm_set_fastmode, 1);
+ rb_define_method(cGDBM,"syncmode=", fgdbm_set_syncmode, 1);
rb_define_method(cGDBM, "include?", fgdbm_has_key, 1);
rb_define_method(cGDBM, "has_key?", fgdbm_has_key, 1);
@@ -666,4 +819,24 @@ Init_gdbm()
rb_define_method(cGDBM, "to_a", fgdbm_to_a, 0);
rb_define_method(cGDBM, "to_hash", fgdbm_to_hash, 0);
+
+ /* flags for gdbm_opn() */
+ /*
+ rb_define_const(cGDBM, "READER", INT2FIX(GDBM_READER));
+ rb_define_const(cGDBM, "WRITER", INT2FIX(GDBM_WRITER));
+ rb_define_const(cGDBM, "WRCREAT", INT2FIX(GDBM_WRCREAT));
+ rb_define_const(cGDBM, "NEWDB", INT2FIX(GDBM_NEWDB));
+ */
+ rb_define_const(cGDBM, "FAST", INT2FIX(GDBM_FAST));
+ /* this flag is obsolete in gdbm 1.8.
+ On gdbm 1.8, fast mode is default behavior. */
+
+ /* gdbm version 1.8 specific */
+#if defined(GDBM_SYNC)
+ rb_define_const(cGDBM, "SYNC", INT2FIX(GDBM_SYNC));
+#endif
+#if defined(GDBM_NOLOCK)
+ rb_define_const(cGDBM, "NOLOCK", INT2FIX(GDBM_NOLOCK));
+#endif
+ rb_define_const(cGDBM, "VERSION", rb_str_new2(gdbm_version));
}
diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb
index 3582c21..7dadd70 100644
--- a/ext/socket/extconf.rb
+++ b/ext/socket/extconf.rb
@@ -338,9 +338,9 @@ if have_func(test_func)
end
if ENV["SOCKS_SERVER"] or enable_config("socks", false)
if have_library("socks5", "SOCKSinit")
- $CFLAGS="-DSOCKS5 -DSOCKS"
+ $CFLAGS+=" -DSOCKS5 -DSOCKS"
elsif have_library("socks", "Rconnect")
- $CFLAGS="-DSOCKS"
+ $CFLAGS+=" -DSOCKS"
end
end
create_makefile("socket")
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 1ef2e89..891a354 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -182,9 +182,7 @@ sock_new(class, fd)
fp->f = rb_fdopen(fd, "r");
#ifdef NT
fp->finalize = sock_finalize;
- fd = myfddup(fd);
#else
- fd = dup(fd);
#endif
fp->f2 = rb_fdopen(fd, "w");
fp->mode = FMODE_READWRITE;
@@ -233,18 +231,10 @@ bsock_close_read(sock)
}
GetOpenFile(sock, fptr);
shutdown(fileno(fptr->f), 0);
- if (fptr->f2 == 0) {
+ if (!(fptr->mode & FMODE_WRITABLE)) {
return rb_io_close(sock);
}
- rb_thread_fd_close(fileno(fptr->f));
fptr->mode &= ~FMODE_READABLE;
-#ifdef NT
- myfdclose(fptr->f);
-#else
- fclose(fptr->f);
-#endif
- fptr->f = fptr->f2;
- fptr->f2 = 0;
return Qnil;
}
@@ -259,17 +249,11 @@ bsock_close_write(sock)
rb_raise(rb_eSecurityError, "Insecure: can't close socket");
}
GetOpenFile(sock, fptr);
- if (fptr->f2 == 0) {
+ if (!(fptr->mode & FMODE_READABLE)) {
return rb_io_close(sock);
}
shutdown(fileno(fptr->f2), 1);
fptr->mode &= ~FMODE_WRITABLE;
-#ifdef NT
- myfdclose(fptr->f2);
-#else
- fclose(fptr->f2);
-#endif
- fptr->f2 = 0;
return Qnil;
}