_IO_SYSWRITEを展開していくと、
count = _IO_new_file_write(fp, data, to_do);
になります。
以下でそれなりに細かく展開工程をのせました。「// 8」「// 9」が説明が不足しているかもしれません。
C
1// 1
2// fileops.c
3count = _IO_SYSWRITE (fp, data, to_do);
4// から始めます。
C
1// 2
2// #define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN)
3// で置き換え
4count = JUMP2 (__write, fp, data, to_do);
C
1// 3
2// #define JUMP2(FUNC, THIS, X1, X2) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
3// で置き換え
4count = (_IO_JUMPS_FUNC(fp)->__write) (fp, data, to_do);
C
1// 4
2// # define _IO_JUMPS_FUNC(THIS) (IO_validate_vtable (_IO_JUMPS_FILE_plus (THIS)))
3// で置き換え
4count =\
5((IO_validate_vtable (_IO_JUMPS_FILE_plus (fp))->__write) (fp, data, to_do);
C
1// 5
2// #define _IO_JUMPS_FILE_plus(THIS) \
3// _IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE_plus, vtable)
4// で置き換え
5count =\
6((IO_validate_vtable (_IO_CAST_FIELD_ACCESS ((fp), struct _IO_FILE_plus, vtable))->__write)\
7(fp, data, to_do);
C
1// 6
2// #define _IO_CAST_FIELD_ACCESS(THIS, TYPE, MEMBER) \
3// (*(_IO_MEMBER_TYPE (TYPE, MEMBER) *)(((char *) (THIS)) \
4// + offsetof(TYPE, MEMBER)))
5// で置き換え
6count =\
7((IO_validate_vtable ((*(_IO_MEMBER_TYPE (struct _IO_FILE_plus, vtable) *)\
8(((char *) ((fp))) + offsetof(struct _IO_FILE_plus, vtable))))->__write)\
9(fp, data, to_do);
C
1// 7
2// #define _IO_MEMBER_TYPE(TYPE, MEMBER) __typeof__ (((TYPE){}).MEMBER)
3// で置き換え
4count =\
5((IO_validate_vtable ((*(__typeof__ (((struct _IO_FILE_plus){}).vtable) *)\
6(((char *) ((fp))) + offsetof(struct _IO_FILE_plus, vtable))))->__write)\
7(fp, data, to_do);
C
1// 8
2// __typeof__を置き換え
3// struct _IO_FILE_plus
4// {
5// _IO_FILE file; // fpが指している先。fpの後ろにvtableが隠れている。
6// const struct _IO_jump_t *vtable;
7// };
8count =\
9((IO_validate_vtable ((*(const struct _IO_jump_t *)\
10(((char *) ((fp))) + offsetof(struct _IO_FILE_plus, vtable))))->__write)\
11(fp, data, to_do);
C
1// 9
2// IO_validate_vtable はデータをチェックして問題なければ、引数を戻す関数。
3// 整理すると、
4count = (vtable->__write)(fp, data, to_do);
C
1// 10
2// vtableはstruct _IO_jump_t型。
3// struct _IO_jump_tの定義に__writeがある。
4#define JUMP_FIELD(TYPE, NAME) TYPE NAME
5struct _IO_jump_t
6{
7…
8 JUMP_FIELD(_IO_write_t, __write);
9…
10};
11// struct _IO_jump_t型の変数 _IO_file_jumps の定義で__writeのメンバとして、
12// _IO_new_file_writeを定義。
13// ※ _IO_file_jumps以外にもstruct _IO_jump_t型の変数が存在し、簡単に切り替えできるようになっている。
14#define JUMP_INIT(NAME, VALUE) VALUE
15const struct _IO_jump_t _IO_file_jumps libio_vtable =
16{
17//…
18 JUMP_INIT(write, _IO_new_file_write),
19//…
20};
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/12/16 02:19