From fd61a78303ae67772abec331647a90d0c419f32b Mon Sep 17 00:00:00 2001 From: normal Date: Sun, 2 Mar 2014 22:50:31 +0000 Subject: [PATCH] use do/while(0) around GetDBM macros * README.EXT: wrap GetDBM with do/while(0) * README.EXT.ja: ditto * ext/dbm/dbm.c: ditto, likewise for GetDBM2 * ext/gdbm/gdbm.c: ditto * ext/sdbm/init.c: ditto [ruby-core:61217] ref: http://c-faq.com/cpp/multistmt.html git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ README.EXT | 4 ++-- README.EXT.ja | 4 ++-- ext/dbm/dbm.c | 8 ++++---- ext/gdbm/gdbm.c | 4 ++-- ext/sdbm/init.c | 8 ++++---- 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index d94246e6a40049..610097b796b30c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Mon Mar 3 07:47:17 2014 Eric Wong + + * README.EXT: wrap GetDBM with do/while(0) + * README.EXT.ja: ditto + * ext/dbm/dbm.c: ditto, likewise for GetDBM2 + * ext/gdbm/gdbm.c: ditto + * ext/sdbm/init.c: ditto + [ruby-core:61217] + Mon Mar 3 07:17:31 2014 Zachary Scott * NEWS: [DOC] Update doc regarding filesystem load when flushing IO diff --git a/README.EXT b/README.EXT index b1a816c271e0ac..ecc96933a354a2 100644 --- a/README.EXT +++ b/README.EXT @@ -683,10 +683,10 @@ wrapping DBM* directly, because we want to cache size information. To retrieve the dbmdata structure from a Ruby object, we define the following macro: - #define GetDBM(obj, dbmp) {\ + #define GetDBM(obj, dbmp) do {\ Data_Get_Struct(obj, struct dbmdata, dbmp);\ if (dbmp->di_dbm == 0) closed_dbm();\ - } + } while (0) This sort of complicated macro does the retrieving and close checking for the DBM. diff --git a/README.EXT.ja b/README.EXT.ja index ec2fe8c8b476b3..ea2b44983c8132 100644 --- a/README.EXT.ja +++ b/README.EXT.ja @@ -763,10 +763,10 @@ dbm.cではData_Make_Structを以下のように使っています. Dataオブジェクトからdbmstruct構造体のポインタを取り出すため に以下のマクロを使っています. - #define GetDBM(obj, dbmp) {\ + #define GetDBM(obj, dbmp) do {\ Data_Get_Struct(obj, struct dbmdata, dbmp);\ if (dbmp->di_dbm == 0) closed_dbm();\ - } + } while (0) ちょっと複雑なマクロですが,要するにdbmdata構造体のポインタ の取り出しと,closeされているかどうかのチェックをまとめてい diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c index 03616fd4d85e2d..ae31232cb65f86 100644 --- a/ext/dbm/dbm.c +++ b/ext/dbm/dbm.c @@ -45,16 +45,16 @@ closed_dbm(void) rb_raise(rb_eDBMError, "closed DBM file"); } -#define GetDBM(obj, dbmp) {\ +#define GetDBM(obj, dbmp) do {\ Data_Get_Struct((obj), struct dbmdata, (dbmp));\ if ((dbmp) == 0) closed_dbm();\ if ((dbmp)->di_dbm == 0) closed_dbm();\ -} +} while (0) -#define GetDBM2(obj, data, dbm) {\ +#define GetDBM2(obj, data, dbm) do {\ GetDBM((obj), (data));\ (dbm) = dbmp->di_dbm;\ -} +} while (0) static void free_dbm(struct dbmdata *dbmp) diff --git a/ext/gdbm/gdbm.c b/ext/gdbm/gdbm.c index e0484155b1b198..ff2638e389beea 100644 --- a/ext/gdbm/gdbm.c +++ b/ext/gdbm/gdbm.c @@ -106,10 +106,10 @@ closed_dbm(void) if ((dbmp)->di_dbm == 0) closed_dbm();\ } while (0) -#define GetDBM2(obj, data, dbm) {\ +#define GetDBM2(obj, data, dbm) do {\ GetDBM((obj), (data));\ (dbm) = dbmp->di_dbm;\ -} +} while (0) static void free_dbm(struct dbmdata *dbmp) diff --git a/ext/sdbm/init.c b/ext/sdbm/init.c index 0f26bb89edefaa..596d9541593bc6 100644 --- a/ext/sdbm/init.c +++ b/ext/sdbm/init.c @@ -77,16 +77,16 @@ closed_sdbm() rb_raise(rb_eDBMError, "closed SDBM file"); } -#define GetDBM(obj, dbmp) {\ +#define GetDBM(obj, dbmp) do {\ Data_Get_Struct((obj), struct dbmdata, (dbmp));\ if ((dbmp) == 0) closed_sdbm();\ if ((dbmp)->di_dbm == 0) closed_sdbm();\ -} +} while (0) -#define GetDBM2(obj, data, dbm) {\ +#define GetDBM2(obj, data, dbm) do {\ GetDBM((obj), (data));\ (dbm) = dbmp->di_dbm;\ -} +} while (0) static void free_sdbm(struct dbmdata *dbmp)