1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
#ifndef _NULLPO_H_
#define _NULLPO_H_
#define NULLPO_CHECK 1
// �S�̂̃X�C�b�`��錾���Ă���w�b�_�������
// �����Ɉړ����Ă����������
#ifndef __NETBSD__
#if __STDC_VERSION__ < 199901L
# if __GNUC__ >= 2
# define __func__ __FUNCTION__
# else
# define __func__ ""
# endif
#endif
#endif
#ifdef _WIN32
#define __attribute__(x) /* nothing */
#endif
#define NLP_MARK __FILE__, __LINE__, __func__
/*----------------------------------------------------------------------------
* Macros
*----------------------------------------------------------------------------
*/
/*======================================
* Null�`�F�b�N �y�� ���o�͌� return
*�E�W�J�����if�Ƃ�return�����o��̂�
* ��s�P�̂Ŏg���Ă��������B
*�Enullpo_ret(x = func());
* �̂悤�Ȏg�p�@���z�肵�Ă��܂��B
*--------------------------------------
* nullpo_ret(t)
* �߂�l 0�Œ�
* [����]
* t �`�F�b�N�Ώ�
*--------------------------------------
* nullpo_retv(t)
* �߂�l �Ȃ�
* [����]
* t �`�F�b�N�Ώ�
*--------------------------------------
* nullpo_retr(ret, t)
* �߂�l �w��
* [����]
* ret return(ret);
* t �`�F�b�N�Ώ�
*--------------------------------------
* nullpo_ret_f(t, fmt, ...)
* �ڍ��o�͗p
* �߂�l 0
* [����]
* t �`�F�b�N�Ώ�
* fmt ... vprintf�ɓn�����
* ���l��W�ϐ��̏����o���Ȃǂ�
*--------------------------------------
* nullpo_retv_f(t, fmt, ...)
* �ڍ��o�͗p
* �߂�l �Ȃ�
* [����]
* t �`�F�b�N�Ώ�
* fmt ... vprintf�ɓn�����
* ���l��W�ϐ��̏����o���Ȃǂ�
*--------------------------------------
* nullpo_retr_f(ret, t, fmt, ...)
* �ڍ��o�͗p
* �߂�l �w��
* [����]
* ret return(ret);
* t �`�F�b�N�Ώ�
* fmt ... vprintf�ɓn�����
* ���l��W�ϐ��̏����o���Ȃǂ�
*--------------------------------------
*/
#if NULLPO_CHECK
#define nullpo_ret(t) \
if (nullpo_chk(NLP_MARK, (void *)(t))) {return(0);}
#define nullpo_retv(t) \
if (nullpo_chk(NLP_MARK, (void *)(t))) {return;}
#define nullpo_retr(ret, t) \
if (nullpo_chk(NLP_MARK, (void *)(t))) {return(ret);}
#define nullpo_retb(t) \
if (nullpo_chk(NLP_MARK, (void *)(t))) {break;}
// �ψ����}�N���Ɋւ�������R���p�C��
#if __STDC_VERSION__ >= 199901L
/* C99�ɑΉ� */
#define nullpo_ret_f(t, fmt, ...) \
if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), __VA_ARGS__)) {return(0);}
#define nullpo_retv_f(t, fmt, ...) \
if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), __VA_ARGS__)) {return;}
#define nullpo_retr_f(ret, t, fmt, ...) \
if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), __VA_ARGS__)) {return(ret);}
#define nullpo_retb_f(t, fmt, ...) \
if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), __VA_ARGS__)) {break;}
#elif __GNUC__ >= 2
/* GCC�p */
#define nullpo_ret_f(t, fmt, args...) \
if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), ## args)) {return(0);}
#define nullpo_retv_f(t, fmt, args...) \
if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), ## args)) {return;}
#define nullpo_retr_f(ret, t, fmt, args...) \
if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), ## args)) {return(ret);}
#define nullpo_retb_f(t, fmt, args...) \
if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), ## args)) {break;}
#else
/* ���̑��̏ꍇ�E�E�E orz */
#endif
#else /* NULLPO_CHECK */
/* No Nullpo check */
// if((t)){;}
// �ǂ����@���v�����Ȃ������̂ŁE�E�E����̍�ł��B
// �ꉞ���[�j���O�͏o�Ȃ��͂�
#define nullpo_ret(t) if((t)){;}
#define nullpo_retv(t) if((t)){;}
#define nullpo_retr(ret, t) if((t)){;}
#define nullpo_retb(t) if((t)){;}
// �ψ����}�N���Ɋւ�������R���p�C��
#if __STDC_VERSION__ >= 199901L
/* C99�ɑΉ� */
#define nullpo_ret_f(t, fmt, ...) if((t)){;}
#define nullpo_retv_f(t, fmt, ...) if((t)){;}
#define nullpo_retr_f(ret, t, fmt, ...) if((t)){;}
#define nullpo_retb_f(t, fmt, ...) if((t)){;}
#elif __GNUC__ >= 2
/* GCC�p */
#define nullpo_ret_f(t, fmt, args...) if((t)){;}
#define nullpo_retv_f(t, fmt, args...) if((t)){;}
#define nullpo_retr_f(ret, t, fmt, args...) if((t)){;}
#define nullpo_retb_f(t, fmt, args...) if((t)){;}
#else
/* ���̑��̏ꍇ�E�E�E orz */
#endif
#endif /* NULLPO_CHECK */
/*----------------------------------------------------------------------------
* Functions
*----------------------------------------------------------------------------
*/
/*======================================
* nullpo_chk
* Null�`�F�b�N �y�� ���o��
* [����]
* file __FILE__
* line __LINE__
* func __func__ (����)
* �����ɂ� NLP_MARK ���g���Ƃ悢
* target �`�F�b�N�Ώ�
* [�Ԃ�l]
* 0 OK
* 1 NULL
*--------------------------------------
*/
int nullpo_chk(const char *file, int line, const char *func, const void *target);
/*======================================
* nullpo_chk_f
* Null�`�F�b�N �y�� �ڍׂȏ��o��
* [����]
* file __FILE__
* line __LINE__
* func __func__ (����)
* �����ɂ� NLP_MARK ���g���Ƃ悢
* target �`�F�b�N�Ώ�
* fmt ... vprintf�ɓn�����
* ���l��W�ϐ��̏����o���Ȃǂ�
* [�Ԃ�l]
* 0 OK
* 1 NULL
*--------------------------------------
*/
int nullpo_chk_f(const char *file, int line, const char *func, const void *target,
const char *fmt, ...)
__attribute__((format(printf,5,6)));
/*======================================
* nullpo_info
* nullpo���o��
* [����]
* file __FILE__
* line __LINE__
* func __func__ (����)
* �����ɂ� NLP_MARK ���g���Ƃ悢
*--------------------------------------
*/
void nullpo_info(const char *file, int line, const char *func);
/*======================================
* nullpo_info_f
* nullpo�ڍ��o��
* [����]
* file __FILE__
* line __LINE__
* func __func__ (����)
* �����ɂ� NLP_MARK ���g���Ƃ悢
* fmt ... vprintf�ɓn�����
* ���l��W�ϐ��̏����o���Ȃǂ�
*--------------------------------------
*/
void nullpo_info_f(const char *file, int line, const char *func,
const char *fmt, ...)
__attribute__((format(printf,4,5)));
#endif /* _NULLPO_H_ */
|