Skip to content

Commit

Permalink
use do/while(0) around GetDBM macros
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
normal committed Mar 2, 2014
1 parent 60bfa43 commit fd61a78
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Mon Mar 3 07:47:17 2014 Eric Wong <e@80x24.org>

* 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 <e@zzak.io>

* NEWS: [DOC] Update doc regarding filesystem load when flushing IO
Expand Down
4 changes: 2 additions & 2 deletions README.EXT
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions README.EXT.ja
Original file line number Diff line number Diff line change
Expand Up @@ -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されているかどうかのチェックをまとめてい
Expand Down
8 changes: 4 additions & 4 deletions ext/dbm/dbm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ext/gdbm/gdbm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions ext/sdbm/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fd61a78

Please sign in to comment.