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