typecheck-gcc.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. #ifndef __CURL_TYPECHECK_GCC_H
  2. #define __CURL_TYPECHECK_GCC_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2015, Daniel Stenberg, <[email protected]>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at http://curl.haxx.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. ***************************************************************************/
  24. /* wraps curl_easy_setopt() with typechecking */
  25. /* To add a new kind of warning, add an
  26. * if(_curl_is_sometype_option(_curl_opt))
  27. * if(!_curl_is_sometype(value))
  28. * _curl_easy_setopt_err_sometype();
  29. * block and define _curl_is_sometype_option, _curl_is_sometype and
  30. * _curl_easy_setopt_err_sometype below
  31. *
  32. * NOTE: We use two nested 'if' statements here instead of the && operator, in
  33. * order to work around gcc bug #32061. It affects only gcc 4.3.x/4.4.x
  34. * when compiling with -Wlogical-op.
  35. *
  36. * To add an option that uses the same type as an existing option, you'll just
  37. * need to extend the appropriate _curl_*_option macro
  38. */
  39. #define curl_easy_setopt(handle, option, value) \
  40. __extension__ ({ \
  41. __typeof__ (option) _curl_opt = option; \
  42. if(__builtin_constant_p(_curl_opt)) { \
  43. if(_curl_is_long_option(_curl_opt)) \
  44. if(!_curl_is_long(value)) \
  45. _curl_easy_setopt_err_long(); \
  46. if(_curl_is_off_t_option(_curl_opt)) \
  47. if(!_curl_is_off_t(value)) \
  48. _curl_easy_setopt_err_curl_off_t(); \
  49. if(_curl_is_string_option(_curl_opt)) \
  50. if(!_curl_is_string(value)) \
  51. _curl_easy_setopt_err_string(); \
  52. if(_curl_is_write_cb_option(_curl_opt)) \
  53. if(!_curl_is_write_cb(value)) \
  54. _curl_easy_setopt_err_write_callback(); \
  55. if((_curl_opt) == CURLOPT_READFUNCTION) \
  56. if(!_curl_is_read_cb(value)) \
  57. _curl_easy_setopt_err_read_cb(); \
  58. if((_curl_opt) == CURLOPT_IOCTLFUNCTION) \
  59. if(!_curl_is_ioctl_cb(value)) \
  60. _curl_easy_setopt_err_ioctl_cb(); \
  61. if((_curl_opt) == CURLOPT_SOCKOPTFUNCTION) \
  62. if(!_curl_is_sockopt_cb(value)) \
  63. _curl_easy_setopt_err_sockopt_cb(); \
  64. if((_curl_opt) == CURLOPT_OPENSOCKETFUNCTION) \
  65. if(!_curl_is_opensocket_cb(value)) \
  66. _curl_easy_setopt_err_opensocket_cb(); \
  67. if((_curl_opt) == CURLOPT_PROGRESSFUNCTION) \
  68. if(!_curl_is_progress_cb(value)) \
  69. _curl_easy_setopt_err_progress_cb(); \
  70. if((_curl_opt) == CURLOPT_DEBUGFUNCTION) \
  71. if(!_curl_is_debug_cb(value)) \
  72. _curl_easy_setopt_err_debug_cb(); \
  73. if((_curl_opt) == CURLOPT_SSL_CTX_FUNCTION) \
  74. if(!_curl_is_ssl_ctx_cb(value)) \
  75. _curl_easy_setopt_err_ssl_ctx_cb(); \
  76. if(_curl_is_conv_cb_option(_curl_opt)) \
  77. if(!_curl_is_conv_cb(value)) \
  78. _curl_easy_setopt_err_conv_cb(); \
  79. if((_curl_opt) == CURLOPT_SEEKFUNCTION) \
  80. if(!_curl_is_seek_cb(value)) \
  81. _curl_easy_setopt_err_seek_cb(); \
  82. if(_curl_is_cb_data_option(_curl_opt)) \
  83. if(!_curl_is_cb_data(value)) \
  84. _curl_easy_setopt_err_cb_data(); \
  85. if((_curl_opt) == CURLOPT_ERRORBUFFER) \
  86. if(!_curl_is_error_buffer(value)) \
  87. _curl_easy_setopt_err_error_buffer(); \
  88. if((_curl_opt) == CURLOPT_STDERR) \
  89. if(!_curl_is_FILE(value)) \
  90. _curl_easy_setopt_err_FILE(); \
  91. if(_curl_is_postfields_option(_curl_opt)) \
  92. if(!_curl_is_postfields(value)) \
  93. _curl_easy_setopt_err_postfields(); \
  94. if((_curl_opt) == CURLOPT_HTTPPOST) \
  95. if(!_curl_is_arr((value), struct curl_httppost)) \
  96. _curl_easy_setopt_err_curl_httpost(); \
  97. if(_curl_is_slist_option(_curl_opt)) \
  98. if(!_curl_is_arr((value), struct curl_slist)) \
  99. _curl_easy_setopt_err_curl_slist(); \
  100. if((_curl_opt) == CURLOPT_SHARE) \
  101. if(!_curl_is_ptr((value), CURLSH)) \
  102. _curl_easy_setopt_err_CURLSH(); \
  103. } \
  104. curl_easy_setopt(handle, _curl_opt, value); \
  105. })
  106. /* wraps curl_easy_getinfo() with typechecking */
  107. /* FIXME: don't allow const pointers */
  108. #define curl_easy_getinfo(handle, info, arg) \
  109. __extension__ ({ \
  110. __typeof__ (info) _curl_info = info; \
  111. if(__builtin_constant_p(_curl_info)) { \
  112. if(_curl_is_string_info(_curl_info)) \
  113. if(!_curl_is_arr((arg), char *)) \
  114. _curl_easy_getinfo_err_string(); \
  115. if(_curl_is_long_info(_curl_info)) \
  116. if(!_curl_is_arr((arg), long)) \
  117. _curl_easy_getinfo_err_long(); \
  118. if(_curl_is_double_info(_curl_info)) \
  119. if(!_curl_is_arr((arg), double)) \
  120. _curl_easy_getinfo_err_double(); \
  121. if(_curl_is_slist_info(_curl_info)) \
  122. if(!_curl_is_arr((arg), struct curl_slist *)) \
  123. _curl_easy_getinfo_err_curl_slist(); \
  124. } \
  125. curl_easy_getinfo(handle, _curl_info, arg); \
  126. })
  127. /* TODO: typechecking for curl_share_setopt() and curl_multi_setopt(),
  128. * for now just make sure that the functions are called with three
  129. * arguments
  130. */
  131. #define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param)
  132. #define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param)
  133. /* the actual warnings, triggered by calling the _curl_easy_setopt_err*
  134. * functions */
  135. /* To define a new warning, use _CURL_WARNING(identifier, "message") */
  136. #define _CURL_WARNING(id, message) \
  137. static void __attribute__((__warning__(message))) \
  138. __attribute__((__unused__)) __attribute__((__noinline__)) \
  139. id(void) { __asm__(""); }
  140. _CURL_WARNING(_curl_easy_setopt_err_long,
  141. "curl_easy_setopt expects a long argument for this option")
  142. _CURL_WARNING(_curl_easy_setopt_err_curl_off_t,
  143. "curl_easy_setopt expects a curl_off_t argument for this option")
  144. _CURL_WARNING(_curl_easy_setopt_err_string,
  145. "curl_easy_setopt expects a "
  146. "string (char* or char[]) argument for this option"
  147. )
  148. _CURL_WARNING(_curl_easy_setopt_err_write_callback,
  149. "curl_easy_setopt expects a curl_write_callback argument for this option")
  150. _CURL_WARNING(_curl_easy_setopt_err_read_cb,
  151. "curl_easy_setopt expects a curl_read_callback argument for this option")
  152. _CURL_WARNING(_curl_easy_setopt_err_ioctl_cb,
  153. "curl_easy_setopt expects a curl_ioctl_callback argument for this option")
  154. _CURL_WARNING(_curl_easy_setopt_err_sockopt_cb,
  155. "curl_easy_setopt expects a curl_sockopt_callback argument for this option")
  156. _CURL_WARNING(_curl_easy_setopt_err_opensocket_cb,
  157. "curl_easy_setopt expects a "
  158. "curl_opensocket_callback argument for this option"
  159. )
  160. _CURL_WARNING(_curl_easy_setopt_err_progress_cb,
  161. "curl_easy_setopt expects a curl_progress_callback argument for this option")
  162. _CURL_WARNING(_curl_easy_setopt_err_debug_cb,
  163. "curl_easy_setopt expects a curl_debug_callback argument for this option")
  164. _CURL_WARNING(_curl_easy_setopt_err_ssl_ctx_cb,
  165. "curl_easy_setopt expects a curl_ssl_ctx_callback argument for this option")
  166. _CURL_WARNING(_curl_easy_setopt_err_conv_cb,
  167. "curl_easy_setopt expects a curl_conv_callback argument for this option")
  168. _CURL_WARNING(_curl_easy_setopt_err_seek_cb,
  169. "curl_easy_setopt expects a curl_seek_callback argument for this option")
  170. _CURL_WARNING(_curl_easy_setopt_err_cb_data,
  171. "curl_easy_setopt expects a "
  172. "private data pointer as argument for this option")
  173. _CURL_WARNING(_curl_easy_setopt_err_error_buffer,
  174. "curl_easy_setopt expects a "
  175. "char buffer of CURL_ERROR_SIZE as argument for this option")
  176. _CURL_WARNING(_curl_easy_setopt_err_FILE,
  177. "curl_easy_setopt expects a FILE* argument for this option")
  178. _CURL_WARNING(_curl_easy_setopt_err_postfields,
  179. "curl_easy_setopt expects a void* or char* argument for this option")
  180. _CURL_WARNING(_curl_easy_setopt_err_curl_httpost,
  181. "curl_easy_setopt expects a struct curl_httppost* argument for this option")
  182. _CURL_WARNING(_curl_easy_setopt_err_curl_slist,
  183. "curl_easy_setopt expects a struct curl_slist* argument for this option")
  184. _CURL_WARNING(_curl_easy_setopt_err_CURLSH,
  185. "curl_easy_setopt expects a CURLSH* argument for this option")
  186. _CURL_WARNING(_curl_easy_getinfo_err_string,
  187. "curl_easy_getinfo expects a pointer to char * for this info")
  188. _CURL_WARNING(_curl_easy_getinfo_err_long,
  189. "curl_easy_getinfo expects a pointer to long for this info")
  190. _CURL_WARNING(_curl_easy_getinfo_err_double,
  191. "curl_easy_getinfo expects a pointer to double for this info")
  192. _CURL_WARNING(_curl_easy_getinfo_err_curl_slist,
  193. "curl_easy_getinfo expects a pointer to struct curl_slist * for this info")
  194. /* groups of curl_easy_setops options that take the same type of argument */
  195. /* To add a new option to one of the groups, just add
  196. * (option) == CURLOPT_SOMETHING
  197. * to the or-expression. If the option takes a long or curl_off_t, you don't
  198. * have to do anything
  199. */
  200. /* evaluates to true if option takes a long argument */
  201. #define _curl_is_long_option(option) \
  202. (0 < (option) && (option) < CURLOPTTYPE_OBJECTPOINT)
  203. #define _curl_is_off_t_option(option) \
  204. ((option) > CURLOPTTYPE_OFF_T)
  205. /* evaluates to true if option takes a char* argument */
  206. #define _curl_is_string_option(option) \
  207. ((option) == CURLOPT_ACCEPT_ENCODING || \
  208. (option) == CURLOPT_CAINFO || \
  209. (option) == CURLOPT_CAPATH || \
  210. (option) == CURLOPT_COOKIE || \
  211. (option) == CURLOPT_COOKIEFILE || \
  212. (option) == CURLOPT_COOKIEJAR || \
  213. (option) == CURLOPT_COOKIELIST || \
  214. (option) == CURLOPT_CRLFILE || \
  215. (option) == CURLOPT_CUSTOMREQUEST || \
  216. (option) == CURLOPT_DEFAULT_PROTOCOL || \
  217. (option) == CURLOPT_DNS_INTERFACE || \
  218. (option) == CURLOPT_DNS_LOCAL_IP4 || \
  219. (option) == CURLOPT_DNS_LOCAL_IP6 || \
  220. (option) == CURLOPT_DNS_SERVERS || \
  221. (option) == CURLOPT_EGDSOCKET || \
  222. (option) == CURLOPT_FTPPORT || \
  223. (option) == CURLOPT_FTP_ACCOUNT || \
  224. (option) == CURLOPT_FTP_ALTERNATIVE_TO_USER || \
  225. (option) == CURLOPT_INTERFACE || \
  226. (option) == CURLOPT_ISSUERCERT || \
  227. (option) == CURLOPT_KEYPASSWD || \
  228. (option) == CURLOPT_KRBLEVEL || \
  229. (option) == CURLOPT_LOGIN_OPTIONS || \
  230. (option) == CURLOPT_MAIL_AUTH || \
  231. (option) == CURLOPT_MAIL_FROM || \
  232. (option) == CURLOPT_NETRC_FILE || \
  233. (option) == CURLOPT_NOPROXY || \
  234. (option) == CURLOPT_PASSWORD || \
  235. (option) == CURLOPT_PINNEDPUBLICKEY || \
  236. (option) == CURLOPT_PROXY || \
  237. (option) == CURLOPT_PROXYPASSWORD || \
  238. (option) == CURLOPT_PROXYUSERNAME || \
  239. (option) == CURLOPT_PROXYUSERPWD || \
  240. (option) == CURLOPT_PROXY_SERVICE_NAME || \
  241. (option) == CURLOPT_RANDOM_FILE || \
  242. (option) == CURLOPT_RANGE || \
  243. (option) == CURLOPT_REFERER || \
  244. (option) == CURLOPT_RTSP_SESSION_ID || \
  245. (option) == CURLOPT_RTSP_STREAM_URI || \
  246. (option) == CURLOPT_RTSP_TRANSPORT || \
  247. (option) == CURLOPT_SERVICE_NAME || \
  248. (option) == CURLOPT_SOCKS5_GSSAPI_SERVICE || \
  249. (option) == CURLOPT_SSH_HOST_PUBLIC_KEY_MD5 || \
  250. (option) == CURLOPT_SSH_KNOWNHOSTS || \
  251. (option) == CURLOPT_SSH_PRIVATE_KEYFILE || \
  252. (option) == CURLOPT_SSH_PUBLIC_KEYFILE || \
  253. (option) == CURLOPT_SSLCERT || \
  254. (option) == CURLOPT_SSLCERTTYPE || \
  255. (option) == CURLOPT_SSLENGINE || \
  256. (option) == CURLOPT_SSLKEY || \
  257. (option) == CURLOPT_SSLKEYTYPE || \
  258. (option) == CURLOPT_SSL_CIPHER_LIST || \
  259. (option) == CURLOPT_TLSAUTH_PASSWORD || \
  260. (option) == CURLOPT_TLSAUTH_TYPE || \
  261. (option) == CURLOPT_TLSAUTH_USERNAME || \
  262. (option) == CURLOPT_UNIX_SOCKET_PATH || \
  263. (option) == CURLOPT_URL || \
  264. (option) == CURLOPT_USERAGENT || \
  265. (option) == CURLOPT_USERNAME || \
  266. (option) == CURLOPT_USERPWD || \
  267. (option) == CURLOPT_XOAUTH2_BEARER || \
  268. 0)
  269. /* evaluates to true if option takes a curl_write_callback argument */
  270. #define _curl_is_write_cb_option(option) \
  271. ((option) == CURLOPT_HEADERFUNCTION || \
  272. (option) == CURLOPT_WRITEFUNCTION)
  273. /* evaluates to true if option takes a curl_conv_callback argument */
  274. #define _curl_is_conv_cb_option(option) \
  275. ((option) == CURLOPT_CONV_TO_NETWORK_FUNCTION || \
  276. (option) == CURLOPT_CONV_FROM_NETWORK_FUNCTION || \
  277. (option) == CURLOPT_CONV_FROM_UTF8_FUNCTION)
  278. /* evaluates to true if option takes a data argument to pass to a callback */
  279. #define _curl_is_cb_data_option(option) \
  280. ((option) == CURLOPT_CHUNK_DATA || \
  281. (option) == CURLOPT_CLOSESOCKETDATA || \
  282. (option) == CURLOPT_DEBUGDATA || \
  283. (option) == CURLOPT_FNMATCH_DATA || \
  284. (option) == CURLOPT_HEADERDATA || \
  285. (option) == CURLOPT_INTERLEAVEDATA || \
  286. (option) == CURLOPT_IOCTLDATA || \
  287. (option) == CURLOPT_OPENSOCKETDATA || \
  288. (option) == CURLOPT_PRIVATE || \
  289. (option) == CURLOPT_PROGRESSDATA || \
  290. (option) == CURLOPT_READDATA || \
  291. (option) == CURLOPT_SEEKDATA || \
  292. (option) == CURLOPT_SOCKOPTDATA || \
  293. (option) == CURLOPT_SSH_KEYDATA || \
  294. (option) == CURLOPT_SSL_CTX_DATA || \
  295. (option) == CURLOPT_WRITEDATA || \
  296. 0)
  297. /* evaluates to true if option takes a POST data argument (void* or char*) */
  298. #define _curl_is_postfields_option(option) \
  299. ((option) == CURLOPT_POSTFIELDS || \
  300. (option) == CURLOPT_COPYPOSTFIELDS || \
  301. 0)
  302. /* evaluates to true if option takes a struct curl_slist * argument */
  303. #define _curl_is_slist_option(option) \
  304. ((option) == CURLOPT_HTTP200ALIASES || \
  305. (option) == CURLOPT_HTTPHEADER || \
  306. (option) == CURLOPT_MAIL_RCPT || \
  307. (option) == CURLOPT_POSTQUOTE || \
  308. (option) == CURLOPT_PREQUOTE || \
  309. (option) == CURLOPT_PROXYHEADER || \
  310. (option) == CURLOPT_QUOTE || \
  311. (option) == CURLOPT_RESOLVE || \
  312. (option) == CURLOPT_TELNETOPTIONS || \
  313. 0)
  314. /* groups of curl_easy_getinfo infos that take the same type of argument */
  315. /* evaluates to true if info expects a pointer to char * argument */
  316. #define _curl_is_string_info(info) \
  317. (CURLINFO_STRING < (info) && (info) < CURLINFO_LONG)
  318. /* evaluates to true if info expects a pointer to long argument */
  319. #define _curl_is_long_info(info) \
  320. (CURLINFO_LONG < (info) && (info) < CURLINFO_DOUBLE)
  321. /* evaluates to true if info expects a pointer to double argument */
  322. #define _curl_is_double_info(info) \
  323. (CURLINFO_DOUBLE < (info) && (info) < CURLINFO_SLIST)
  324. /* true if info expects a pointer to struct curl_slist * argument */
  325. #define _curl_is_slist_info(info) \
  326. (CURLINFO_SLIST < (info))
  327. /* typecheck helpers -- check whether given expression has requested type*/
  328. /* For pointers, you can use the _curl_is_ptr/_curl_is_arr macros,
  329. * otherwise define a new macro. Search for __builtin_types_compatible_p
  330. * in the GCC manual.
  331. * NOTE: these macros MUST NOT EVALUATE their arguments! The argument is
  332. * the actual expression passed to the curl_easy_setopt macro. This
  333. * means that you can only apply the sizeof and __typeof__ operators, no
  334. * == or whatsoever.
  335. */
  336. /* XXX: should evaluate to true iff expr is a pointer */
  337. #define _curl_is_any_ptr(expr) \
  338. (sizeof(expr) == sizeof(void*))
  339. /* evaluates to true if expr is NULL */
  340. /* XXX: must not evaluate expr, so this check is not accurate */
  341. #define _curl_is_NULL(expr) \
  342. (__builtin_types_compatible_p(__typeof__(expr), __typeof__(NULL)))
  343. /* evaluates to true if expr is type*, const type* or NULL */
  344. #define _curl_is_ptr(expr, type) \
  345. (_curl_is_NULL(expr) || \
  346. __builtin_types_compatible_p(__typeof__(expr), type *) || \
  347. __builtin_types_compatible_p(__typeof__(expr), const type *))
  348. /* evaluates to true if expr is one of type[], type*, NULL or const type* */
  349. #define _curl_is_arr(expr, type) \
  350. (_curl_is_ptr((expr), type) || \
  351. __builtin_types_compatible_p(__typeof__(expr), type []))
  352. /* evaluates to true if expr is a string */
  353. #define _curl_is_string(expr) \
  354. (_curl_is_arr((expr), char) || \
  355. _curl_is_arr((expr), signed char) || \
  356. _curl_is_arr((expr), unsigned char))
  357. /* evaluates to true if expr is a long (no matter the signedness)
  358. * XXX: for now, int is also accepted (and therefore short and char, which
  359. * are promoted to int when passed to a variadic function) */
  360. #define _curl_is_long(expr) \
  361. (__builtin_types_compatible_p(__typeof__(expr), long) || \
  362. __builtin_types_compatible_p(__typeof__(expr), signed long) || \
  363. __builtin_types_compatible_p(__typeof__(expr), unsigned long) || \
  364. __builtin_types_compatible_p(__typeof__(expr), int) || \
  365. __builtin_types_compatible_p(__typeof__(expr), signed int) || \
  366. __builtin_types_compatible_p(__typeof__(expr), unsigned int) || \
  367. __builtin_types_compatible_p(__typeof__(expr), short) || \
  368. __builtin_types_compatible_p(__typeof__(expr), signed short) || \
  369. __builtin_types_compatible_p(__typeof__(expr), unsigned short) || \
  370. __builtin_types_compatible_p(__typeof__(expr), char) || \
  371. __builtin_types_compatible_p(__typeof__(expr), signed char) || \
  372. __builtin_types_compatible_p(__typeof__(expr), unsigned char))
  373. /* evaluates to true if expr is of type curl_off_t */
  374. #define _curl_is_off_t(expr) \
  375. (__builtin_types_compatible_p(__typeof__(expr), curl_off_t))
  376. /* evaluates to true if expr is abuffer suitable for CURLOPT_ERRORBUFFER */
  377. /* XXX: also check size of an char[] array? */
  378. #define _curl_is_error_buffer(expr) \
  379. (_curl_is_NULL(expr) || \
  380. __builtin_types_compatible_p(__typeof__(expr), char *) || \
  381. __builtin_types_compatible_p(__typeof__(expr), char[]))
  382. /* evaluates to true if expr is of type (const) void* or (const) FILE* */
  383. #if 0
  384. #define _curl_is_cb_data(expr) \
  385. (_curl_is_ptr((expr), void) || \
  386. _curl_is_ptr((expr), FILE))
  387. #else /* be less strict */
  388. #define _curl_is_cb_data(expr) \
  389. _curl_is_any_ptr(expr)
  390. #endif
  391. /* evaluates to true if expr is of type FILE* */
  392. #define _curl_is_FILE(expr) \
  393. (__builtin_types_compatible_p(__typeof__(expr), FILE *))
  394. /* evaluates to true if expr can be passed as POST data (void* or char*) */
  395. #define _curl_is_postfields(expr) \
  396. (_curl_is_ptr((expr), void) || \
  397. _curl_is_arr((expr), char))
  398. /* FIXME: the whole callback checking is messy...
  399. * The idea is to tolerate char vs. void and const vs. not const
  400. * pointers in arguments at least
  401. */
  402. /* helper: __builtin_types_compatible_p distinguishes between functions and
  403. * function pointers, hide it */
  404. #define _curl_callback_compatible(func, type) \
  405. (__builtin_types_compatible_p(__typeof__(func), type) || \
  406. __builtin_types_compatible_p(__typeof__(func), type*))
  407. /* evaluates to true if expr is of type curl_read_callback or "similar" */
  408. #define _curl_is_read_cb(expr) \
  409. (_curl_is_NULL(expr) || \
  410. __builtin_types_compatible_p(__typeof__(expr), __typeof__(fread)) || \
  411. __builtin_types_compatible_p(__typeof__(expr), curl_read_callback) || \
  412. _curl_callback_compatible((expr), _curl_read_callback1) || \
  413. _curl_callback_compatible((expr), _curl_read_callback2) || \
  414. _curl_callback_compatible((expr), _curl_read_callback3) || \
  415. _curl_callback_compatible((expr), _curl_read_callback4) || \
  416. _curl_callback_compatible((expr), _curl_read_callback5) || \
  417. _curl_callback_compatible((expr), _curl_read_callback6))
  418. typedef size_t (_curl_read_callback1)(char *, size_t, size_t, void*);
  419. typedef size_t (_curl_read_callback2)(char *, size_t, size_t, const void*);
  420. typedef size_t (_curl_read_callback3)(char *, size_t, size_t, FILE*);
  421. typedef size_t (_curl_read_callback4)(void *, size_t, size_t, void*);
  422. typedef size_t (_curl_read_callback5)(void *, size_t, size_t, const void*);
  423. typedef size_t (_curl_read_callback6)(void *, size_t, size_t, FILE*);
  424. /* evaluates to true if expr is of type curl_write_callback or "similar" */
  425. #define _curl_is_write_cb(expr) \
  426. (_curl_is_read_cb(expr) || \
  427. __builtin_types_compatible_p(__typeof__(expr), __typeof__(fwrite)) || \
  428. __builtin_types_compatible_p(__typeof__(expr), curl_write_callback) || \
  429. _curl_callback_compatible((expr), _curl_write_callback1) || \
  430. _curl_callback_compatible((expr), _curl_write_callback2) || \
  431. _curl_callback_compatible((expr), _curl_write_callback3) || \
  432. _curl_callback_compatible((expr), _curl_write_callback4) || \
  433. _curl_callback_compatible((expr), _curl_write_callback5) || \
  434. _curl_callback_compatible((expr), _curl_write_callback6))
  435. typedef size_t (_curl_write_callback1)(const char *, size_t, size_t, void*);
  436. typedef size_t (_curl_write_callback2)(const char *, size_t, size_t,
  437. const void*);
  438. typedef size_t (_curl_write_callback3)(const char *, size_t, size_t, FILE*);
  439. typedef size_t (_curl_write_callback4)(const void *, size_t, size_t, void*);
  440. typedef size_t (_curl_write_callback5)(const void *, size_t, size_t,
  441. const void*);
  442. typedef size_t (_curl_write_callback6)(const void *, size_t, size_t, FILE*);
  443. /* evaluates to true if expr is of type curl_ioctl_callback or "similar" */
  444. #define _curl_is_ioctl_cb(expr) \
  445. (_curl_is_NULL(expr) || \
  446. __builtin_types_compatible_p(__typeof__(expr), curl_ioctl_callback) || \
  447. _curl_callback_compatible((expr), _curl_ioctl_callback1) || \
  448. _curl_callback_compatible((expr), _curl_ioctl_callback2) || \
  449. _curl_callback_compatible((expr), _curl_ioctl_callback3) || \
  450. _curl_callback_compatible((expr), _curl_ioctl_callback4))
  451. typedef curlioerr (_curl_ioctl_callback1)(CURL *, int, void*);
  452. typedef curlioerr (_curl_ioctl_callback2)(CURL *, int, const void*);
  453. typedef curlioerr (_curl_ioctl_callback3)(CURL *, curliocmd, void*);
  454. typedef curlioerr (_curl_ioctl_callback4)(CURL *, curliocmd, const void*);
  455. /* evaluates to true if expr is of type curl_sockopt_callback or "similar" */
  456. #define _curl_is_sockopt_cb(expr) \
  457. (_curl_is_NULL(expr) || \
  458. __builtin_types_compatible_p(__typeof__(expr), curl_sockopt_callback) || \
  459. _curl_callback_compatible((expr), _curl_sockopt_callback1) || \
  460. _curl_callback_compatible((expr), _curl_sockopt_callback2))
  461. typedef int (_curl_sockopt_callback1)(void *, curl_socket_t, curlsocktype);
  462. typedef int (_curl_sockopt_callback2)(const void *, curl_socket_t,
  463. curlsocktype);
  464. /* evaluates to true if expr is of type curl_opensocket_callback or
  465. "similar" */
  466. #define _curl_is_opensocket_cb(expr) \
  467. (_curl_is_NULL(expr) || \
  468. __builtin_types_compatible_p(__typeof__(expr), curl_opensocket_callback) ||\
  469. _curl_callback_compatible((expr), _curl_opensocket_callback1) || \
  470. _curl_callback_compatible((expr), _curl_opensocket_callback2) || \
  471. _curl_callback_compatible((expr), _curl_opensocket_callback3) || \
  472. _curl_callback_compatible((expr), _curl_opensocket_callback4))
  473. typedef curl_socket_t (_curl_opensocket_callback1)
  474. (void *, curlsocktype, struct curl_sockaddr *);
  475. typedef curl_socket_t (_curl_opensocket_callback2)
  476. (void *, curlsocktype, const struct curl_sockaddr *);
  477. typedef curl_socket_t (_curl_opensocket_callback3)
  478. (const void *, curlsocktype, struct curl_sockaddr *);
  479. typedef curl_socket_t (_curl_opensocket_callback4)
  480. (const void *, curlsocktype, const struct curl_sockaddr *);
  481. /* evaluates to true if expr is of type curl_progress_callback or "similar" */
  482. #define _curl_is_progress_cb(expr) \
  483. (_curl_is_NULL(expr) || \
  484. __builtin_types_compatible_p(__typeof__(expr), curl_progress_callback) || \
  485. _curl_callback_compatible((expr), _curl_progress_callback1) || \
  486. _curl_callback_compatible((expr), _curl_progress_callback2))
  487. typedef int (_curl_progress_callback1)(void *,
  488. double, double, double, double);
  489. typedef int (_curl_progress_callback2)(const void *,
  490. double, double, double, double);
  491. /* evaluates to true if expr is of type curl_debug_callback or "similar" */
  492. #define _curl_is_debug_cb(expr) \
  493. (_curl_is_NULL(expr) || \
  494. __builtin_types_compatible_p(__typeof__(expr), curl_debug_callback) || \
  495. _curl_callback_compatible((expr), _curl_debug_callback1) || \
  496. _curl_callback_compatible((expr), _curl_debug_callback2) || \
  497. _curl_callback_compatible((expr), _curl_debug_callback3) || \
  498. _curl_callback_compatible((expr), _curl_debug_callback4) || \
  499. _curl_callback_compatible((expr), _curl_debug_callback5) || \
  500. _curl_callback_compatible((expr), _curl_debug_callback6) || \
  501. _curl_callback_compatible((expr), _curl_debug_callback7) || \
  502. _curl_callback_compatible((expr), _curl_debug_callback8))
  503. typedef int (_curl_debug_callback1) (CURL *,
  504. curl_infotype, char *, size_t, void *);
  505. typedef int (_curl_debug_callback2) (CURL *,
  506. curl_infotype, char *, size_t, const void *);
  507. typedef int (_curl_debug_callback3) (CURL *,
  508. curl_infotype, const char *, size_t, void *);
  509. typedef int (_curl_debug_callback4) (CURL *,
  510. curl_infotype, const char *, size_t, const void *);
  511. typedef int (_curl_debug_callback5) (CURL *,
  512. curl_infotype, unsigned char *, size_t, void *);
  513. typedef int (_curl_debug_callback6) (CURL *,
  514. curl_infotype, unsigned char *, size_t, const void *);
  515. typedef int (_curl_debug_callback7) (CURL *,
  516. curl_infotype, const unsigned char *, size_t, void *);
  517. typedef int (_curl_debug_callback8) (CURL *,
  518. curl_infotype, const unsigned char *, size_t, const void *);
  519. /* evaluates to true if expr is of type curl_ssl_ctx_callback or "similar" */
  520. /* this is getting even messier... */
  521. #define _curl_is_ssl_ctx_cb(expr) \
  522. (_curl_is_NULL(expr) || \
  523. __builtin_types_compatible_p(__typeof__(expr), curl_ssl_ctx_callback) || \
  524. _curl_callback_compatible((expr), _curl_ssl_ctx_callback1) || \
  525. _curl_callback_compatible((expr), _curl_ssl_ctx_callback2) || \
  526. _curl_callback_compatible((expr), _curl_ssl_ctx_callback3) || \
  527. _curl_callback_compatible((expr), _curl_ssl_ctx_callback4) || \
  528. _curl_callback_compatible((expr), _curl_ssl_ctx_callback5) || \
  529. _curl_callback_compatible((expr), _curl_ssl_ctx_callback6) || \
  530. _curl_callback_compatible((expr), _curl_ssl_ctx_callback7) || \
  531. _curl_callback_compatible((expr), _curl_ssl_ctx_callback8))
  532. typedef CURLcode (_curl_ssl_ctx_callback1)(CURL *, void *, void *);
  533. typedef CURLcode (_curl_ssl_ctx_callback2)(CURL *, void *, const void *);
  534. typedef CURLcode (_curl_ssl_ctx_callback3)(CURL *, const void *, void *);
  535. typedef CURLcode (_curl_ssl_ctx_callback4)(CURL *, const void *, const void *);
  536. #ifdef HEADER_SSL_H
  537. /* hack: if we included OpenSSL's ssl.h, we know about SSL_CTX
  538. * this will of course break if we're included before OpenSSL headers...
  539. */
  540. typedef CURLcode (_curl_ssl_ctx_callback5)(CURL *, SSL_CTX, void *);
  541. typedef CURLcode (_curl_ssl_ctx_callback6)(CURL *, SSL_CTX, const void *);
  542. typedef CURLcode (_curl_ssl_ctx_callback7)(CURL *, const SSL_CTX, void *);
  543. typedef CURLcode (_curl_ssl_ctx_callback8)(CURL *, const SSL_CTX,
  544. const void *);
  545. #else
  546. typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback5;
  547. typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback6;
  548. typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback7;
  549. typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback8;
  550. #endif
  551. /* evaluates to true if expr is of type curl_conv_callback or "similar" */
  552. #define _curl_is_conv_cb(expr) \
  553. (_curl_is_NULL(expr) || \
  554. __builtin_types_compatible_p(__typeof__(expr), curl_conv_callback) || \
  555. _curl_callback_compatible((expr), _curl_conv_callback1) || \
  556. _curl_callback_compatible((expr), _curl_conv_callback2) || \
  557. _curl_callback_compatible((expr), _curl_conv_callback3) || \
  558. _curl_callback_compatible((expr), _curl_conv_callback4))
  559. typedef CURLcode (*_curl_conv_callback1)(char *, size_t length);
  560. typedef CURLcode (*_curl_conv_callback2)(const char *, size_t length);
  561. typedef CURLcode (*_curl_conv_callback3)(void *, size_t length);
  562. typedef CURLcode (*_curl_conv_callback4)(const void *, size_t length);
  563. /* evaluates to true if expr is of type curl_seek_callback or "similar" */
  564. #define _curl_is_seek_cb(expr) \
  565. (_curl_is_NULL(expr) || \
  566. __builtin_types_compatible_p(__typeof__(expr), curl_seek_callback) || \
  567. _curl_callback_compatible((expr), _curl_seek_callback1) || \
  568. _curl_callback_compatible((expr), _curl_seek_callback2))
  569. typedef CURLcode (*_curl_seek_callback1)(void *, curl_off_t, int);
  570. typedef CURLcode (*_curl_seek_callback2)(const void *, curl_off_t, int);
  571. #endif /* __CURL_TYPECHECK_GCC_H */