mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-25 04:18:08 +01:00
ruby: Use rb_scan_args()
This commit is contained in:
parent
c7893408bb
commit
d2a457a5d8
1 changed files with 9 additions and 9 deletions
|
@ -33,6 +33,7 @@ notmuch_rb_database_new(int argc, VALUE *argv, VALUE klass)
|
||||||
const char *path;
|
const char *path;
|
||||||
int create, mode;
|
int create, mode;
|
||||||
notmuch_database_t *db;
|
notmuch_database_t *db;
|
||||||
|
VALUE pathv, hashv;
|
||||||
VALUE modev;
|
VALUE modev;
|
||||||
|
|
||||||
#if !defined(RSTRING_PTR)
|
#if !defined(RSTRING_PTR)
|
||||||
|
@ -40,16 +41,15 @@ notmuch_rb_database_new(int argc, VALUE *argv, VALUE klass)
|
||||||
#endif /* !defined(RSTRING_PTR) */
|
#endif /* !defined(RSTRING_PTR) */
|
||||||
|
|
||||||
/* Check arguments */
|
/* Check arguments */
|
||||||
if (argc < 1 || argc > 2)
|
rb_scan_args(argc, argv, "11", &pathv, &hashv);
|
||||||
rb_raise(rb_eTypeError, "Wrong number of arguments");
|
|
||||||
|
|
||||||
SafeStringValue(argv[0]);
|
SafeStringValue(pathv);
|
||||||
path = RSTRING_PTR(argv[0]);
|
path = RSTRING_PTR(pathv);
|
||||||
|
|
||||||
if (argc == 2) {
|
if (!NIL_P(hashv)) {
|
||||||
Check_Type(argv[1], T_HASH);
|
Check_Type(hashv, T_HASH);
|
||||||
create = RTEST(rb_hash_aref(argv[1], ID2SYM(ID_db_create)));
|
create = RTEST(rb_hash_aref(hashv, ID2SYM(ID_db_create)));
|
||||||
modev = rb_hash_aref(argv[1], ID2SYM(ID_db_mode));
|
modev = rb_hash_aref(hashv, ID2SYM(ID_db_mode));
|
||||||
if (NIL_P(modev))
|
if (NIL_P(modev))
|
||||||
mode = NOTMUCH_DATABASE_MODE_READ_ONLY;
|
mode = NOTMUCH_DATABASE_MODE_READ_ONLY;
|
||||||
else if (!FIXNUM_P(modev))
|
else if (!FIXNUM_P(modev))
|
||||||
|
@ -72,7 +72,7 @@ notmuch_rb_database_new(int argc, VALUE *argv, VALUE klass)
|
||||||
|
|
||||||
db = create ? notmuch_database_create(path) : notmuch_database_open(path, mode);
|
db = create ? notmuch_database_create(path) : notmuch_database_open(path, mode);
|
||||||
if (!db)
|
if (!db)
|
||||||
rb_raise(notmuch_rb_eDatabaseError, "failed to open database");
|
rb_raise(notmuch_rb_eDatabaseError, "Failed to open database");
|
||||||
|
|
||||||
return Data_Wrap_Struct(klass, NULL, NULL, db);
|
return Data_Wrap_Struct(klass, NULL, NULL, db);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue