text:
#ifndef CURLINC_TYPECHECK_GCC_H
#define CURLINC_TYPECHECK_GCC_H

/* wraps curl_easy_setopt() with typechecking */

/* To add a new kind of warning, add an
 *   if(curlcheck_sometype_option(_curl_opt))
 *     if(!curlcheck_sometype(value))
 *       _curl_easy_setopt_err_sometype();
 * block and define curlcheck_sometype_option, curlcheck_sometype and
 * _curl_easy_setopt_err_sometype below
 *
 * NOTE: We use two nested 'if' statements here instead of the && operator, in
 *       order to work around gcc bug #32061.  It affects only gcc 4.3.x/4.4.x
 *       when compiling with -Wlogical-op.
 *
 * To add an option that uses the same type as an existing option, you'll just
 * need to extend the appropriate _curl_*_option macro
 */
#define curl_easy_setopt(handle, option, value)                         \
  __extension__({                                                       \
      __typeof__(option) _curl_opt = option;                            \
      if(__builtin_constant_p(_curl_opt)) {                             \
        if(curlcheck_long_option(_curl_opt))                            \
          if(!curlcheck_long(value))                                    \
            _curl_easy_setopt_err_long();                               \
        if(curlcheck_off_t_option(_curl_opt))                           \
          if(!curlcheck_off_t(value))                                   \
            _curl_easy_setopt_err_curl_off_t();                         \
        if(curlcheck_string_option(_curl_opt))                          \
          if(!curlcheck_string(value))                                  \
            _curl_easy_setopt_err_string();                             \
        if(curlcheck_write_cb_option(_curl_opt))                        \
          if(!curlcheck_write_cb(value))                                \
            _curl_easy_setopt_err_write_callback();                     \
        if((_curl_opt) == CURLOPT_RESOLVER_START_FUNCTION)              \
          if(!curlcheck_resolver_start_callback(value))                 \
            _curl_easy_setopt_err_resolver_start_callback();            \
        if((_curl_opt) == CURLOPT_READFUNCTION)                         \
          if(!curlcheck_read_cb(value))                                 \
            _curl_easy_setopt_err_read_cb();                            \
        if((_curl_opt) == CURLOPT_IOCTLFUNCTION)                        \
          if(!curlcheck_ioctl_cb(value))                                \
            _curl_easy_setopt_err_ioctl_cb();                           \
        if((_curl_opt) == CURLOPT_SOCKOPTFUNCTION)                      \
          if(!curlcheck_sockopt_cb(value))                              \
            _curl_easy_setopt_err_sockopt_cb();                         \
        if((_curl_opt) == CURLOPT_OPENSOCKETFUNCTION)                   \
          if(!curlcheck_opensocket_cb(value))                           \
            _curl_easy_setopt_err_opensocket_cb();                      \
        if((_curl_opt) == CURLOPT_PROGRESSFUNCTION)                     \
          if(!curlcheck_progress_cb(value))                             \
            _curl_easy_setopt_err_progress_cb();                        \
        if((_curl_opt) == CURLOPT_DEBUGFUNCTION)                        \
          if(!curlcheck_debug_cb(value))                                \
            _curl_easy_setopt_err_debug_cb();                           \
        if((_curl_opt) == CURLOPT_SSL_CTX_FUNCTION)                     \
          if(!curlcheck_ssl_ctx_cb(value))                              \
            _curl_easy_setopt_err_ssl_ctx_cb();                         \
        if(curlcheck_conv_cb_option(_curl_opt))                         \
          if(!curlcheck_conv_cb(value))                                 \
            _curl_easy_setopt_err_conv_cb();                            \
        if((_curl_opt) == CURLOPT_SEEKFUNCTION)                         \
          if(!curlcheck_seek_cb(value))                                 \
            _curl_easy_setopt_err_seek_cb();                            \
        if(curlcheck_cb_data_option(_curl_opt))                         \
          if(!curlcheck_cb_data(value))                                 \
            _curl_easy_setopt_err_cb_data();                            \
        if((_curl_opt) == CURLOPT_ERRORBUFFER)                          \
          if(!curlcheck_error_buffer(value))                            \
            _curl_easy_setopt_err_error_buffer();                       \
        if((_curl_opt) == CURLOPT_STDERR)                               \
          if(!curlcheck_FILE(value))                                    \
            _curl_easy_setopt_err_FILE();                               \
        if(curlcheck_postfields_option(_curl_opt))                      \
          if(!curlcheck_postfields(value))                              \
            _curl_easy_setopt_err_postfields();                         \
        if((_curl_opt) == CURLOPT_HTTPPOST)                             \
          if(!curlcheck_arr((value), struct curl_httppost))             \
            _curl_easy_setopt_err_curl_httpost();                       \
        if((_curl_opt) == CURLOPT_MIMEPOST)                             \
          if(!curlcheck_ptr((value), curl_mime))                        \
            _curl_easy_setopt_err_curl_mimepost();                      \
        if(curlcheck_slist_option(_curl_opt))                           \
          if(!curlcheck_arr((value), struct curl_slist))                \
            _curl_easy_setopt_err_curl_slist();                         \
        if((_curl_opt) == CURLOPT_SHARE)                                \
          if(!curlcheck_ptr((value), CURLSH))                           \
            _curl_easy_setopt_err_CURLSH();                             \
      }                                                                 \
      curl_easy_setopt(handle, _curl_opt, value);                       \
    })

/* wraps curl_easy_getinfo() with typechecking */
#define curl_easy_getinfo(handle, info, arg)                            \
  __extension__({                                                      \
      __typeof__(info) _curl_info = info;                               \
      if(__builtin_constant_p(_curl_info)) {                            \
        if(curlcheck_string_info(_curl_info))                           \
          if(!curlcheck_arr((arg), char *))                             \
            _curl_easy_getinfo_err_string();                            \
        if(curlcheck_long_info(_curl_info))                             \
          if(!curlcheck_arr((arg), long))                               \
            _curl_easy_getinfo_err_long();                              \
        if(curlcheck_double_info(_curl_info))                           \
          if(!curlcheck_arr((arg), double))                             \
            _curl_easy_getinfo_err_double();                            \
        if(curlcheck_slist_info(_curl_info))                            \
          if(!curlcheck_arr((arg), struct curl_slist *))                \
            _curl_easy_getinfo_err_curl_slist();                        \
        if(curlcheck_tlssessioninfo_info(_curl_info))                   \
          if(!curlcheck_arr((arg), struct curl_tlssessioninfo *))       \
            _curl_easy_getinfo_err_curl_tlssesssioninfo();              \
        if(curlcheck_certinfo_info(_curl_info))                         \
          if(!curlcheck_arr((arg), struct curl_certinfo *))             \
            _curl_easy_getinfo_err_curl_certinfo();                     \
        if(curlcheck_socket_info(_curl_info))                           \
          if(!curlcheck_arr((arg), curl_socket_t))                      \
            _curl_easy_getinfo_err_curl_socket();                       \
        if(curlcheck_off_t_info(_curl_info))                            \
          if(!curlcheck_arr((arg), curl_off_t))                         \
            _curl_easy_getinfo_err_curl_off_t();                        \
      }                                                                 \
      curl_easy_getinfo(handle, _curl_info, arg);                       \
    })

/*
 * For now, just make sure that the functions are called with three arguments
 */
#define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param)
#define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param)

/* the actual warnings, triggered by calling the _curl_easy_setopt_err*
 * functions */

/* To define a new warning, use _CURL_WARNING(identifier, "message") */
#define CURLWARNING(id, message)                                        \
  static void __attribute__((__warning__(message)))                     \
  __attribute__((__unused__)) __attribute__((__noinline__))             \
  id(void) { __asm__(""); }

CURLWARNING(_curl_easy_setopt_err_long,
  "curl_easy_setopt expects a long argument for this option")
CURLWARNING(_curl_easy_setopt_err_curl_off_t,
  "curl_easy_setopt expects a curl_off_t argument for this option")
CURLWARNING(_curl_easy_setopt_err_string,
              "curl_easy_setopt expects a "
              "string ('char *' or char[]) argument for this option"
  )
CURLWARNING(_curl_easy_setopt_err_write_callback,
  "curl_easy_setopt expects a curl_write_callback argument for this option")
CURLWARNING(_curl_easy_setopt_err_resolver_start_callback,
              "curl_easy_setopt expects a "
              "curl_resolver_start_callback argument for this option"
  )
CURLWARNING(_curl_easy_setopt_err_read_cb,
  "curl_easy_setopt expects a curl_read_callback argument for this option")
CURLWARNING(_curl_easy_setopt_err_ioctl_cb,
  "curl_easy_setopt expects a curl_ioctl_callback argument for this option")
CURLWARNING(_curl_easy_setopt_err_sockopt_cb,
  "curl_easy_setopt expects a curl_sockopt_callback argument for this option")
CURLWARNING(_curl_easy_setopt_err_opensocket_cb,
              "curl_easy_setopt expects a "
              "curl_opensocket_callback argument for this option"
  )
CURLWARNING(_curl_easy_setopt_err_progress_cb,
  "curl_easy_setopt expects a curl_progress_callback argument for this option")
CURLWARNING(_curl_easy_setopt_err_debug_cb,
  "curl_easy_setopt expects a curl_debug_callback argument for this option")
CURLWARNING(_curl_easy_setopt_err_ssl_ctx_cb,
  "curl_easy_setopt expects a curl_ssl_ctx_callback argument for this option")
CURLWARNING(_curl_easy_setopt_err_conv_cb,
  "curl_easy_setopt expects a curl_conv_callback argument for this option")
CURLWARNING(_curl_easy_setopt_err_seek_cb,
  "curl_easy_setopt expects a curl_seek_callback argument for this option")
CURLWARNING(_curl_easy_setopt_err_cb_data,
              "curl_easy_setopt expects a "
              "private data pointer as argument for this option")
CURLWARNING(_curl_easy_setopt_err_error_buffer,
              "curl_easy_setopt expects a "
              "char buffer of CURL_ERROR_SIZE as argument for this option")
CURLWARNING(_curl_easy_setopt_err_FILE,
  "curl_easy_setopt expects a 'FILE *' argument for this option")
CURLWARNING(_curl_easy_setopt_err_postfields,
  "curl_easy_setopt expects a 'void *' or 'char *' argument for this option")
CURLWARNING(_curl_easy_setopt_err_curl_httpost,
              "curl_easy_setopt expects a 'struct curl_httppost *' "
              "argument for this option")
CURLWARNING(_curl_easy_setopt_err_curl_mimepost,
              "curl_easy_setopt expects a 'curl_mime *' "
              "argument for this option")
CURLWARNING(_curl_easy_setopt_err_curl_slist,
  "curl_easy_setopt expects a 'struct curl_slist *' argument for this option")
CURLWARNING(_curl_easy_setopt_err_CURLSH,
  "curl_easy_setopt expects a CURLSH* argument for this option")

CURLWARNING(_curl_easy_getinfo_err_string,
  "curl_easy_getinfo expects a pointer to 'char *' for this info")
CURLWARNING(_curl_easy_getinfo_err_long,
  "curl_easy_getinfo expects a pointer to long for this info")
CURLWARNING(_curl_easy_getinfo_err_double,
  "curl_easy_getinfo expects a pointer to double for this info")
CURLWARNING(_curl_easy_getinfo_err_curl_slist,
  "curl_easy_getinfo expects a pointer to 'struct curl_slist *' for this info")
CURLWARNING(_curl_easy_getinfo_err_curl_tlssesssioninfo,
              "curl_easy_getinfo expects a pointer to "
              "'struct curl_tlssessioninfo *' for this info")
CURLWARNING(_curl_easy_getinfo_err_curl_certinfo,
              "curl_easy_getinfo expects a pointer to "
              "'struct curl_certinfo *' for this info")
CURLWARNING(_curl_easy_getinfo_err_curl_socket,
  "curl_easy_getinfo expects a pointer to curl_socket_t for this info")
CURLWARNING(_curl_easy_getinfo_err_curl_off_t,
  "curl_easy_getinfo expects a pointer to curl_off_t for this info")

/* groups of curl_easy_setops options that take the same type of argument */

/* To add a new option to one of the groups, just add
 *   (option) == CURLOPT_SOMETHING
 * to the or-expression. If the option takes a long or curl_off_t, you don't
 * have to do anything
 */

/* evaluates to true if option takes a long argument */
#define curlcheck_long_option(option)                   \
  (0 < (option) && (option) < CURLOPTTYPE_OBJECTPOINT)

#define curlcheck_off_t_option(option)          \
  (((option) > CURLOPTTYPE_OFF_T) && ((option) < CURLOPTTYPE_BLOB))

/* evaluates to true if option takes a char* argument */
#define curlcheck_string_option(option)                                       \
  ((option) == CURLOPT_ABSTRACT_UNIX_SOCKET ||                                \
   (option) == CURLOPT_ACCEPT_ENCODING ||                                     \
   (option) == CURLOPT_ALTSVC ||                                              \
   (option) == CURLOPT_CAINFO ||                                              \
   (option) == CURLOPT_CAPATH ||                                              \
   (option) == CURLOPT_COOKIE ||                                              \
   (option) == CURLOPT_COOKIEFILE ||                                          \
   (option) == CURLOPT_COOKIEJAR ||                                           \
   (option) == CURLOPT_COOKIELIST ||                                          \
   (option) == CURLOPT_CRLFILE ||                                             \
   (option) == CURLOPT_CUSTOMREQUEST ||                                       \
   (option) == CURLOPT_DEFAULT_PROTOCOL ||                                    \
   (option) == CURLOPT_DNS_INTERFACE ||                                       \
   (option) == CURLOPT_DNS_LOCAL_IP4 ||                                       \
   (option) == CURLOPT_DNS_LOCAL_IP6 ||                                       \
   (option) == CURLOPT_DNS_SERVERS ||                                         \
   (option) == CURLOPT_DOH_URL ||                                             \
   (option) == CURLOPT_EGDSOCKET ||                                           \
   (option) == CURLOPT_FTPPORT ||                                             \
   (option) == CURLOPT_FTP_ACCOUNT ||                                         \
   (option) == CURLOPT_FTP_ALTERNATIVE_TO_USER ||                             \
   (option) == CURLOPT_HSTS ||                                                \
   (option) == CURLOPT_INTERFACE ||                                           \
   (option) == CURLOPT_ISSUERCERT ||                                          \
   (option) == CURLOPT_KEYPASSWD ||                                           \
   (option) == CURLOPT_KRBLEVEL ||                                            \
   (option) == CURLOPT_LOGIN_OPTIONS ||                                       \
   (option) == CURLOPT_MAIL_AUTH ||                                           \
   (option) == CURLOPT_MAIL_FROM ||                                           \
   (option) == CURLOPT_NETRC_FILE ||                                          \
   (option) == CURLOPT_NOPROXY ||                                             \
   (option) == CURLOPT_PASSWORD ||                                            \
   (option) == CURLOPT_PINNEDPUBLICKEY ||                                     \
   (option) == CURLOPT_PRE_PROXY ||                                           \
   (option) == CURLOPT_PROXY ||                                               \
   (option) == CURLOPT_PROXYPASSWORD ||                                       \
   (option) == CURLOPT_PROXYUSERNAME ||                                       \
   (option) == CURLOPT_PROXYUSERPWD ||                                        \
   (option) == CURLOPT_PROXY_CAINFO ||                                        \
   (option) == CURLOPT_PROXY_CAPATH ||                                        \
   (option) == CURLOPT_PROXY_CRLFILE ||                                       \
   (option) == CURLOPT_PROXY_ISSUERCERT ||                                    \
   (option) == CURLOPT_PROXY_KEYPASSWD ||                                     \
   (option) == CURLOPT_PROXY_PINNEDPUBLICKEY ||                               \
   (option) == CURLOPT_PROXY_SERVICE_NAME ||                                  \
   (option) == CURLOPT_PROXY_SSLCERT ||                                       \
   (option) == CURLOPT_PROXY_SSLCERTTYPE ||                                   \
   (option) == CURLOPT_PROXY_SSLKEY ||                                        \
   (option) == CURLOPT_PROXY_SSLKEYTYPE ||                                    \
   (option) == CURLOPT_PROXY_SSL_CIPHER_LIST ||                               \
   (option) == CURLOPT_PROXY_TLS13_CIPHERS ||                                 \
   (option) == CURLOPT_PROXY_TLSAUTH_PASSWORD ||                              \
   (option) == CURLOPT_PROXY_TLSAUTH_TYPE ||                                  \
   (option) == CURLOPT_PROXY_TLSAUTH_USERNAME ||                              \
   (option) == CURLOPT_RANDOM_FILE ||                                         \
   (option) == CURLOPT_RANGE ||                                               \
   (option) == CURLOPT_REFERER ||                                             \
   (option) == CURLOPT_REQUEST_TARGET ||                                      \
   (option) == CURLOPT_RTSP_SESSION_ID ||                                     \
   (option) == CURLOPT_RTSP_STREAM_URI ||                                     \
   (option) == CURLOPT_RTSP_TRANSPORT ||                                      \
   (option) == CURLOPT_SASL_AUTHZID ||                                        \
   (option) == CURLOPT_SERVICE_NAME ||                                        \
   (option) == CURLOPT_SOCKS5_GSSAPI_SERVICE ||                               \
   (option) == CURLOPT_SSH_HOST_PUBLIC_KEY_MD5 ||                             \
   (option) == CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256 ||                          \
   (option) == CURLOPT_SSH_KNOWNHOSTS ||                                      \
   (option) == CURLOPT_SSH_PRIVATE_KEYFILE ||                                 \
   (option) == CURLOPT_SSH_PUBLIC_KEYFILE ||                                  \
   (option) == CURLOPT_SSLCERT ||                                             \
   (option) == CURLOPT_SSLCERTTYPE ||                                         \
   (option) == CURLOPT_SSLENGINE ||                                           \
   (option) == CURLOPT_SSLKEY ||                                              \
   (option) == CURLOPT_SSLKEYTYPE ||                                          \
   (option) == CURLOPT_SSL_CIPHER_LIST ||                                     \
   (option) == CURLOPT_TLS13_CIPHERS ||                                       \
   (option) == CURLOPT_TLSAUTH_PASSWORD ||                                    \
   (option) == CURLOPT_TLSAUTH_TYPE ||                                        \
   (option) == CURLOPT_TLSAUTH_USERNAME ||                                    \
   (option) == CURLOPT_UNIX_SOCKET_PATH ||                                    \
   (option) == CURLOPT_URL ||                                                 \
   (option) == CURLOPT_USERAGENT ||                                           \
   (option) == CURLOPT_USERNAME ||                                            \
   (option) == CURLOPT_AWS_SIGV4 ||                                           \
   (option) == CURLOPT_USERPWD ||                                             \
   (option) == CURLOPT_XOAUTH2_BEARER ||                                      \
   (option) == CURLOPT_SSL_EC_CURVES ||                                       \
   0)

/* evaluates to true if option takes a curl_write_callback argument */
#define curlcheck_write_cb_option(option)                               \
  ((option) == CURLOPT_HEADERFUNCTION ||                                \
   (option) == CURLOPT_WRITEFUNCTION)

/* evaluates to true if option takes a curl_conv_callback argument */
#define curlcheck_conv_cb_option(option)                                \
  ((option) == CURLOPT_CONV_TO_NETWORK_FUNCTION ||                      \
   (option) == CURLOPT_CONV_FROM_NETWORK_FUNCTION ||                    \
   (option) == CURLOPT_CONV_FROM_UTF8_FUNCTION)

/* evaluates to true if option takes a data argument to pass to a callback */
#define curlcheck_cb_data_option(option)                                      \
  ((option) == CURLOPT_CHUNK_DATA ||                                          \
   (option) == CURLOPT_CLOSESOCKETDATA ||                                     \
   (option) == CURLOPT_DEBUGDATA ||                                           \
   (option) == CURLOPT_FNMATCH_DATA ||                                        \
   (option) == CURLOPT_HEADERDATA ||                                          \
   (option) == CURLOPT_HSTSREADDATA ||                                        \
   (option) == CURLOPT_HSTSWRITEDATA ||                                       \
   (option) == CURLOPT_INTERLEAVEDATA ||                                      \
   (option) == CURLOPT_IOCTLDATA ||                                           \
   (option) == CURLOPT_OPENSOCKETDATA ||                                      \
   (option) == CURLOPT_PREREQDATA ||                                          \
   (option) == CURLOPT_PROGRESSDATA ||                                        \
   (option) == CURLOPT_READDATA ||                                            \
   (option) == CURLOPT_SEEKDATA ||                                            \
   (option) == CURLOPT_SOCKOPTDATA ||                                         \
   (option) == CURLOPT_SSH_KEYDATA ||                                         \
   (option) == CURLOPT_SSL_CTX_DATA ||                                        \
   (option) == CURLOPT_WRITEDATA ||                                           \
   (option) == CURLOPT_RESOLVER_START_DATA ||                                 \
   (option) == CURLOPT_TRAILERDATA ||                                         \
   (option) == CURLOPT_SSH_HOSTKEYDATA ||                                     \
   0)

/* evaluates to true if option takes a POST data argument (void* or char*) */
#define curlcheck_postfields_option(option)                                   \
  ((option) == CURLOPT_POSTFIELDS ||                                          \
   (option) == CURLOPT_COPYPOSTFIELDS ||                                      \
   0)

/* evaluates to true if option takes a struct curl_slist * argument */
#define curlcheck_slist_option(option)                                        \
  ((option) == CURLOPT_HTTP200ALIASES ||                                      \
   (option) == CURLOPT_HTTPHEADER ||                                          \
   (option) == CURLOPT_MAIL_RCPT ||                                           \
   (option) == CURLOPT_POSTQUOTE ||                                           \
   (option) == CURLOPT_PREQUOTE ||                                            \
   (option) == CURLOPT_PROXYHEADER ||                                         \
   (option) == CURLOPT_QUOTE ||                                               \
   (option) == CURLOPT_RESOLVE ||                                             \
   (option) == CURLOPT_TELNETOPTIONS ||                                       \
   (option) == CURLOPT_CONNECT_TO ||                                          \
   0)

/* groups of curl_easy_getinfo infos that take the same type of argument */

/* evaluates to true if info expects a pointer to char * argument */
#define curlcheck_string_info(info)                             \
  (CURLINFO_STRING < (info) && (info) < CURLINFO_LONG &&        \
   (info) != CURLINFO_PRIVATE)

/* evaluates to true if info expects a pointer to long argument */
#define curlcheck_long_info(info)                       \
  (CURLINFO_LONG < (info) && (info) < CURLINFO_DOUBLE)

/* evaluates to true if info expects a pointer to double argument */
#define curlcheck_double_info(info)                     \
  (CURLINFO_DOUBLE < (info) && (info) < CURLINFO_SLIST)

/* true if info expects a pointer to struct curl_slist * argument */
#define curlcheck_slist_info(info)                                      \
  (((info) == CURLINFO_SSL_ENGINES) || ((info) == CURLINFO_COOKIELIST))

/* true if info expects a pointer to struct curl_tlssessioninfo * argument */
#define curlcheck_tlssessioninfo_info(info)                              \
  (((info) == CURLINFO_TLS_SSL_PTR) || ((info) == CURLINFO_TLS_SESSION))

/* true if info expects a pointer to struct curl_certinfo * argument */
#define curlcheck_certinfo_info(info) ((info) == CURLINFO_CERTINFO)

/* true if info expects a pointer to struct curl_socket_t argument */
#define curlcheck_socket_info(info)                     \
  (CURLINFO_SOCKET < (info) && (info) < CURLINFO_OFF_T)

/* true if info expects a pointer to curl_off_t argument */
#define curlcheck_off_t_info(info)              \
  (CURLINFO_OFF_T < (info))

/* typecheck helpers -- check whether given expression has requested type*/

/* For pointers, you can use the curlcheck_ptr/curlcheck_arr macros,
 * otherwise define a new macro. Search for __builtin_types_compatible_p
 * in the GCC manual.
 * NOTE: these macros MUST NOT EVALUATE their arguments! The argument is
 * the actual expression passed to the curl_easy_setopt macro. This
 * means that you can only apply the sizeof and __typeof__ operators, no
 * == or whatsoever.
 */

/* XXX: should evaluate to true if expr is a pointer */
#define curlcheck_any_ptr(expr)                 \
  (sizeof(expr) == sizeof(void *))

/* evaluates to true if expr is NULL */
/* XXX: must not evaluate expr, so this check is not accurate */
#define curlcheck_NULL(expr)                                            \
  (__builtin_types_compatible_p(__typeof__(expr), __typeof__(NULL)))

/* evaluates to true if expr is type*, const type* or NULL */
#define curlcheck_ptr(expr, type)                                       \
  (curlcheck_NULL(expr) ||                                              \
   __builtin_types_compatible_p(__typeof__(expr), type *) ||            \
   __builtin_types_compatible_p(__typeof__(expr), const type *))

/* evaluates to true if expr is one of type[], type*, NULL or const type* */
#define curlcheck_arr(expr, type)                                       \
  (curlcheck_ptr((expr), type) ||                                       \
   __builtin_types_compatible_p(__typeof__(expr), type []))

/* evaluates to true if expr is a string */
#define curlcheck_string(expr)                                          \
  (curlcheck_arr((expr), char) ||                                       \
   curlcheck_arr((expr), signed char) ||                                \
   curlcheck_arr((expr), unsigned char))

/* evaluates to true if expr is a long (no matter the signedness)
 * XXX: for now, int is also accepted (and therefore short and char, which
 * are promoted to int when passed to a variadic function) */
#define curlcheck_long(expr)                                                  \
  (__builtin_types_compatible_p(__typeof__(expr), long) ||                    \
   __builtin_types_compatible_p(__typeof__(expr), signed long) ||             \
   __builtin_types_compatible_p(__typeof__(expr), unsigned long) ||           \
   __builtin_types_compatible_p(__typeof__(expr), int) ||                     \
   __builtin_types_compatible_p(__typeof__(expr), signed int) ||              \
   __builtin_types_compatible_p(__typeof__(expr), unsigned int) ||            \
   __builtin_types_compatible_p(__typeof__(expr), short) ||                   \
   __builtin_types_compatible_p(__typeof__(expr), signed short) ||            \
   __builtin_types_compatible_p(__typeof__(expr), unsigned short) ||          \
   __builtin_types_compatible_p(__typeof__(expr), char) ||                    \
   __builtin_types_compatible_p(__typeof__(expr), signed char) ||             \
   __builtin_types_compatible_p(__typeof__(expr), unsigned char))

/* evaluates to true if expr is of type curl_off_t */
#define curlcheck_off_t(expr)                                   \
  (__builtin_types_compatible_p(__typeof__(expr), curl_off_t))

/* evaluates to true if expr is abuffer suitable for CURLOPT_ERRORBUFFER */
/* XXX: also check size of an char[] array? */
#define curlcheck_error_buffer(expr)                                    \
  (curlcheck_NULL(expr) ||                                              \
   __builtin_types_compatible_p(__typeof__(expr), char *) ||            \
   __builtin_types_compatible_p(__typeof__(expr), char[]))

/* evaluates to true if expr is of type (const) void* or (const) FILE* */
#if 0
#define curlcheck_cb_data(expr)                                         \
  (curlcheck_ptr((expr), void) ||                                       \
   curlcheck_ptr((expr), FILE))
#else /* be less strict */
#define curlcheck_cb_data(expr)                 \
  curlcheck_any_ptr(expr)
#endif

/* evaluates to true if expr is of type FILE* */
#define curlcheck_FILE(expr)                                            \
  (curlcheck_NULL(expr) ||                                              \
   (__builtin_types_compatible_p(__typeof__(expr), FILE *)))

/* evaluates to true if expr can be passed as POST data (void* or char*) */
#define curlcheck_postfields(expr)                                      \
  (curlcheck_ptr((expr), void) ||                                       \
   curlcheck_arr((expr), char) ||                                       \
   curlcheck_arr((expr), unsigned char))

/* helper: __builtin_types_compatible_p distinguishes between functions and
 * function pointers, hide it */
#define curlcheck_cb_compatible(func, type)                             \
  (__builtin_types_compatible_p(__typeof__(func), type) ||              \
   __builtin_types_compatible_p(__typeof__(func) *, type))

/* evaluates to true if expr is of type curl_resolver_start_callback */
#define curlcheck_resolver_start_callback(expr)       \
  (curlcheck_NULL(expr) || \
   curlcheck_cb_compatible((expr), curl_resolver_start_callback))

/* evaluates to true if expr is of type curl_read_callback or "similar" */
#define curlcheck_read_cb(expr)                                         \
  (curlcheck_NULL(expr) ||                                              \
   curlcheck_cb_compatible((expr), __typeof__(fread) *) ||              \
   curlcheck_cb_compatible((expr), curl_read_callback) ||               \
   curlcheck_cb_compatible((expr), _curl_read_callback1) ||             \
   curlcheck_cb_compatible((expr), _curl_read_callback2) ||             \
   curlcheck_cb_compatible((expr), _curl_read_callback3) ||             \
   curlcheck_cb_compatible((expr), _curl_read_callback4) ||             \
   curlcheck_cb_compatible((expr), _curl_read_callback5) ||             \
   curlcheck_cb_compatible((expr), _curl_read_callback6))
typedef size_t (*_curl_read_callback1)(char *, size_t, size_t, void *);
typedef size_t (*_curl_read_callback2)(char *, size_t, size_t, const void *);
typedef size_t (*_curl_read_callback3)(char *, size_t, size_t, FILE *);
typedef size_t (*_curl_read_callback4)(void *, size_t, size_t, void *);
typedef size_t (*_curl_read_callback5)(void *, size_t, size_t, const void *);
typedef size_t (*_curl_read_callback6)(void *, size_t, size_t, FILE *);

/* evaluates to true if expr is of type curl_write_callback or "similar" */
#define curlcheck_write_cb(expr)                                        \
  (curlcheck_read_cb(expr) ||                                           \
   curlcheck_cb_compatible((expr), __typeof__(fwrite) *) ||             \
   curlcheck_cb_compatible((expr), curl_write_callback) ||              \
   curlcheck_cb_compatible((expr), _curl_write_callback1) ||            \
   curlcheck_cb_compatible((expr), _curl_write_callback2) ||            \
   curlcheck_cb_compatible((expr), _curl_write_callback3) ||            \
   curlcheck_cb_compatible((expr), _curl_write_callback4) ||            \
   curlcheck_cb_compatible((expr), _curl_write_callback5) ||            \
   curlcheck_cb_compatible((expr), _curl_write_callback6))
typedef size_t (*_curl_write_callback1)(const char *, size_t, size_t, void *);
typedef size_t (*_curl_write_callback2)(const char *, size_t, size_t,
                                       const void *);
typedef size_t (*_curl_write_callback3)(const char *, size_t, size_t, FILE *);
typedef size_t (*_curl_write_callback4)(const void *, size_t, size_t, void *);
typedef size_t (*_curl_write_callback5)(const void *, size_t, size_t,
                                       const void *);
typedef size_t (*_curl_write_callback6)(const void *, size_t, size_t, FILE *);

/* evaluates to true if expr is of type curl_ioctl_callback or "similar" */
#define curlcheck_ioctl_cb(expr)                                        \
  (curlcheck_NULL(expr) ||                                              \
   curlcheck_cb_compatible((expr), curl_ioctl_callback) ||              \
   curlcheck_cb_compatible((expr), _curl_ioctl_callback1) ||            \
   curlcheck_cb_compatible((expr), _curl_ioctl_callback2) ||            \
   curlcheck_cb_compatible((expr), _curl_ioctl_callback3) ||            \
   curlcheck_cb_compatible((expr), _curl_ioctl_callback4))
typedef curlioerr (*_curl_ioctl_callback1)(CURL *, int, void *);
typedef curlioerr (*_curl_ioctl_callback2)(CURL *, int, const void *);
typedef curlioerr (*_curl_ioctl_callback3)(CURL *, curliocmd, void *);
typedef curlioerr (*_curl_ioctl_callback4)(CURL *, curliocmd, const void *);

/* evaluates to true if expr is of type curl_sockopt_callback or "similar" */
#define curlcheck_sockopt_cb(expr)                                      \
  (curlcheck_NULL(expr) ||                                              \
   curlcheck_cb_compatible((expr), curl_sockopt_callback) ||            \
   curlcheck_cb_compatible((expr), _curl_sockopt_callback1) ||          \
   curlcheck_cb_compatible((expr), _curl_sockopt_callback2))
typedef int (*_curl_sockopt_callback1)(void *, curl_socket_t, curlsocktype);
typedef int (*_curl_sockopt_callback2)(const void *, curl_socket_t,
                                      curlsocktype);

/* evaluates to true if expr is of type curl_opensocket_callback or
   "similar" */
#define curlcheck_opensocket_cb(expr)                                   \
  (curlcheck_NULL(expr) ||                                              \
   curlcheck_cb_compatible((expr), curl_opensocket_callback) ||         \
   curlcheck_cb_compatible((expr), _curl_opensocket_callback1) ||       \
   curlcheck_cb_compatible((expr), _curl_opensocket_callback2) ||       \
   curlcheck_cb_compatible((expr), _curl_opensocket_callback3) ||       \
   curlcheck_cb_compatible((expr), _curl_opensocket_callback4))
typedef curl_socket_t (*_curl_opensocket_callback1)
  (void *, curlsocktype, struct curl_sockaddr *);
typedef curl_socket_t (*_curl_opensocket_callback2)
  (void *, curlsocktype, const struct curl_sockaddr *);
typedef curl_socket_t (*_curl_opensocket_callback3)
  (const void *, curlsocktype, struct curl_sockaddr *);
typedef curl_socket_t (*_curl_opensocket_callback4)
  (const void *, curlsocktype, const struct curl_sockaddr *);

/* evaluates to true if expr is of type curl_progress_callback or "similar" */
#define curlcheck_progress_cb(expr)                                     \
  (curlcheck_NULL(expr) ||                                              \
   curlcheck_cb_compatible((expr), curl_progress_callback) ||           \
   curlcheck_cb_compatible((expr), _curl_progress_callback1) ||         \
   curlcheck_cb_compatible((expr), _curl_progress_callback2))
typedef int (*_curl_progress_callback1)(void *,
    double, double, double, double);
typedef int (*_curl_progress_callback2)(const void *,
    double, double, double, double);

/* evaluates to true if expr is of type curl_debug_callback or "similar" */
#define curlcheck_debug_cb(expr)                                        \
  (curlcheck_NULL(expr) ||                                              \
   curlcheck_cb_compatible((expr), curl_debug_callback) ||              \
   curlcheck_cb_compatible((expr), _curl_debug_callback1) ||            \
   curlcheck_cb_compatible((expr), _curl_debug_callback2) ||            \
   curlcheck_cb_compatible((expr), _curl_debug_callback3) ||            \
   curlcheck_cb_compatible((expr), _curl_debug_callback4) ||            \
   curlcheck_cb_compatible((expr), _curl_debug_callback5) ||            \
   curlcheck_cb_compatible((expr), _curl_debug_callback6) ||            \
   curlcheck_cb_compatible((expr), _curl_debug_callback7) ||            \
   curlcheck_cb_compatible((expr), _curl_debug_callback8))
typedef int (*_curl_debug_callback1) (CURL *,
    curl_infotype, char *, size_t, void *);
typedef int (*_curl_debug_callback2) (CURL *,
    curl_infotype, char *, size_t, const void *);
typedef int (*_curl_debug_callback3) (CURL *,
    curl_infotype, const char *, size_t, void *);
typedef int (*_curl_debug_callback4) (CURL *,
    curl_infotype, const char *, size_t, const void *);
typedef int (*_curl_debug_callback5) (CURL *,
    curl_infotype, unsigned char *, size_t, void *);
typedef int (*_curl_debug_callback6) (CURL *,
    curl_infotype, unsigned char *, size_t, const void *);
typedef int (*_curl_debug_callback7) (CURL *,
    curl_infotype, const unsigned char *, size_t, void *);
typedef int (*_curl_debug_callback8) (CURL *,
    curl_infotype, const unsigned char *, size_t, const void *);

/* evaluates to true if expr is of type curl_ssl_ctx_callback or "similar" */
/* this is getting even messier... */
#define curlcheck_ssl_ctx_cb(expr)                                      \
  (curlcheck_NULL(expr) ||                                              \
   curlcheck_cb_compatible((expr), curl_ssl_ctx_callback) ||            \
   curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback1) ||          \
   curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback2) ||          \
   curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback3) ||          \
   curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback4) ||          \
   curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback5) ||          \
   curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback6) ||          \
   curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback7) ||          \
   curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback8))
typedef CURLcode (*_curl_ssl_ctx_callback1)(CURL *, void *, void *);
typedef CURLcode (*_curl_ssl_ctx_callback2)(CURL *, void *, const void *);
typedef CURLcode (*_curl_ssl_ctx_callback3)(CURL *, const void *, void *);
typedef CURLcode (*_curl_ssl_ctx_callback4)(CURL *, const void *,
                                            const void *);
#ifdef HEADER_SSL_H
/* hack: if we included OpenSSL's ssl.h, we know about SSL_CTX
 * this will of course break if we're included before OpenSSL headers...
 */
typedef CURLcode (*_curl_ssl_ctx_callback5)(CURL *, SSL_CTX *, void *);
typedef CURLcode (*_curl_ssl_ctx_callback6)(CURL *, SSL_CTX *, const void *);
typedef CURLcode (*_curl_ssl_ctx_callback7)(CURL *, const SSL_CTX *, void *);
typedef CURLcode (*_curl_ssl_ctx_callback8)(CURL *, const SSL_CTX *,
                                            const void *);
#else
typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback5;
typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback6;
typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback7;
typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback8;
#endif

/* evaluates to true if expr is of type curl_conv_callback or "similar" */
#define curlcheck_conv_cb(expr)                                         \
  (curlcheck_NULL(expr) ||                                              \
   curlcheck_cb_compatible((expr), curl_conv_callback) ||               \
   curlcheck_cb_compatible((expr), _curl_conv_callback1) ||             \
   curlcheck_cb_compatible((expr), _curl_conv_callback2) ||             \
   curlcheck_cb_compatible((expr), _curl_conv_callback3) ||             \
   curlcheck_cb_compatible((expr), _curl_conv_callback4))
typedef CURLcode (*_curl_conv_callback1)(char *, size_t length);
typedef CURLcode (*_curl_conv_callback2)(const char *, size_t length);
typedef CURLcode (*_curl_conv_callback3)(void *, size_t length);
typedef CURLcode (*_curl_conv_callback4)(const void *, size_t length);

/* evaluates to true if expr is of type curl_seek_callback or "similar" */
#define curlcheck_seek_cb(expr)                                         \
  (curlcheck_NULL(expr) ||                                              \
   curlcheck_cb_compatible((expr), curl_seek_callback) ||               \
   curlcheck_cb_compatible((expr), _curl_seek_callback1) ||             \
   curlcheck_cb_compatible((expr), _curl_seek_callback2))
typedef CURLcode (*_curl_seek_callback1)(void *, curl_off_t, int);
typedef CURLcode (*_curl_seek_callback2)(const void *, curl_off_t, int);

#endif /* CURLINC_TYPECHECK_GCC_H */


text:
<?xml version="1.0" encoding="UTF-8"?>

<dynamodm-mapping xmlns="http://cldtk.com/schema/dynamodm-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://cldtk.com/schema/dynamodm-mapping
                  http://cldtk.com/schema/dynamodm-mapping.xsd">

    <document name="TestDocuments\User" db="documents" collection="users">
        <attribute name="id" id="true" />
        <attribute name="username" type="string" unique="true" sparse="true"/>
        <attribute name="createdAt" type="date" />
        <attribute name="tags" type="collection" />
        <embed-one target-document="Documents\Address" attribute="address" />
        <!--<attribute name="profile" targetDocument="Documents\Profile" reference="true" type="one" cascade="all" />-->
        <reference-one target-document="Documents\Profile" attribute="profile" simple="true" orphan-removal="true">
            <cascade>
                <all />
            </cascade>
        </reference-one>
        <embed-many target-document="Documents\Phonenumber" attribute="phonenumbers" />
        <embed-one target-document="TestDocument\EmbeddedDocument" attribute="test" />
        <reference-many target-document="Documents\Group" attribute="groups">
            <cascade>
                <all />
            </cascade>
        </reference-many>
        <reference-one target-document="Documents\Account" attribute="account">
            <cascade>
                <all />
            </cascade>
        </reference-one>
        <lifecycle-callbacks>
          <lifecycle-callback method="doStuffOnPrePersist" type="prePersist" />
          <lifecycle-callback method="doStuffOnPostPersist" type="postPersist" />
          <lifecycle-callback method="doOtherStuffOnPostPersist" type="postPersist" />
        </lifecycle-callbacks>
        <also-load-methods>
            <also-load-method method="doStuffOnAlsoLoad" attribute="unmappedAttribute" />
        </also-load-methods>
    </document>
</dynamodm-mapping>

redpajama_set_name: RedPajamaGithub


text:
package me.dkzwm.widget.srl.sample.ui;

import android.os.Bundle;
import android.os.Handler;
import android.view.MenuItem;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.motion.widget.MotionLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import me.dkzwm.widget.srl.RefreshingListenerAdapter;
import me.dkzwm.widget.srl.SmoothRefreshLayout;
import me.dkzwm.widget.srl.extra.IRefreshView;
import me.dkzwm.widget.srl.sample.R;
import me.dkzwm.widget.srl.sample.adapter.RecyclerViewAdapter;
import me.dkzwm.widget.srl.sample.utils.DataUtil;

public class TestInMotionLayoutSceneActivity extends AppCompatActivity {
    private Handler mHandler = new Handler();
    private SmoothRefreshLayout mRefreshLayout;
    private MotionLayout mMotionLayout;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_inner_motionscene_start);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setTitle(R.string.test_inner_motionlayout_scene);
        RecyclerView recyclerView = findViewById(R.id.recyclerView_test_motionLayout_scene);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        RecyclerViewAdapter adapter = new RecyclerViewAdapter(this, getLayoutInflater());
        recyclerView.setAdapter(adapter);
        adapter.updateData(DataUtil.createList(0, 100));
        mMotionLayout = findViewById(R.id.motionLayout_test_motionLayout_scene);
        mRefreshLayout = findViewById(R.id.smoothRefreshLayout_test_motionLayout_scene);
        mRefreshLayout.setOnHeaderEdgeDetectCallBack(
                new SmoothRefreshLayout.OnHeaderEdgeDetectCallBack() {
                    @Override
                    public boolean isNotYetInEdgeCannotMoveHeader(
                            SmoothRefreshLayout parent,
                            @Nullable View child,
                            @Nullable IRefreshView header) {
                        return mMotionLayout.getProgress() != 0f
                                || (child != null && child.canScrollVertically(-1));
                    }
                });
        mRefreshLayout.setOnRefreshListener(
                new RefreshingListenerAdapter() {
                    @Override
                    public void onRefreshing() {
                        mHandler.postDelayed(
                                new Runnable() {
                                    @Override
                                    public void run() {
                                        mRefreshLayout.refreshComplete();
                                    }
                                },
                                1000);
                    }
                });
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mHandler.removeCallbacksAndMessages(null);
    }
}


text:
import Component from 'ember-component';
import computed from 'ember-computed';
import get from 'ember-metal/get';

export default Component.extend({
  tagName: 'svg',
  attributeBindings: ['viewBox', 'fill'],

  fill: 'currentColor',
  dotGapSize: 50,
  dotRadius: 10,
  numDots: 3,

  viewBoxLength: computed('dotGapSize', 'numDots', 'dotRadius', {
    get() {
      const numDots = get(this, 'numDots');
      const dotGapSize = get(this, 'dotGapSize');
      const dotRadius = get(this, 'dotRadius');

      return (
        (dotGapSize * (numDots - 1)) +
        (dotRadius * (numDots - 1))
      );
    }
  }),

  viewBox: computed('viewBoxLength', 'dotRadius', {
    get() {
      const viewBoxLength = get(this, 'viewBoxLength');
      const dotRadius = get(this, 'dotRadius');

      return `0 0 ${viewBoxLength} ${dotRadius * 2}`;
    }
  }),

  dots: computed('viewBox', {
    get() {
      const numDots = get(this, 'numDots');
      const dotGapSize = get(this, 'dotGapSize');
      const dotRadius = get(this, 'dotRadius');

      return Array.from({ length: numDots }, (item, idx) => {
        return {
          cx: dotRadius + (idx * dotGapSize),
          cy: dotRadius,
          radius: dotRadius
        }
      });
    }
  })
});


text:
'use strict';

import { Uri, EventEmitter, Event, SCMResource, SCMResourceDecorations, SCMResourceGroup, Disposable, window } from 'vscode';
import { Repository, IRef, IBranch, IRemote, IPushOptions } from './git';
import { anyEvent, eventToPromise, filterEvent, mapEvent } from './util';
import { memoize, throttle, debounce } from './decorators';
import { watch } from './watch';
import * as path from 'path';
import * as nls from 'vscode-nls';

const localize = nls.loadMessageBundle();
const iconsRootPath = path.join(path.dirname(__dirname), 'resources', 'icons');

function getIconUri(iconName: string, theme: string): Uri {
	return Uri.file(path.join(iconsRootPath, theme, `${iconName}.svg`));
}

export enum Status {
	INDEX_MODIFIED,
	INDEX_ADDED,
	INDEX_DELETED,
	INDEX_RENAMED,
	INDEX_COPIED,

	MODIFIED,
	DELETED,
	UNTRACKED,
	IGNORED,

	ADDED_BY_US,
	ADDED_BY_THEM,
	DELETED_BY_US,
	DELETED_BY_THEM,
	BOTH_ADDED,
	BOTH_DELETED,
	BOTH_MODIFIED
}

export class Resource implements SCMResource {

	get uri(): Uri { return this._uri; }
	get type(): Status { return this._type; }

	private static Icons = {
		light: {
			Modified: getIconUri('status-modified', 'light'),
			Added: getIconUri('status-added', 'light'),
			Deleted: getIconUri('status-deleted', 'light'),
			Renamed: getIconUri('status-renamed', 'light'),
			Copied: getIconUri('status-copied', 'light'),
			Untracked: getIconUri('status-untracked', 'light'),
			Ignored: getIconUri('status-ignored', 'light'),
			Conflict: getIconUri('status-conflict', 'light'),
		},
		dark: {
			Modified: getIconUri('status-modified', 'dark'),
			Added: getIconUri('status-added', 'dark'),
			Deleted: getIconUri('status-deleted', 'dark'),
			Renamed: getIconUri('status-renamed', 'dark'),
			Copied: getIconUri('status-copied', 'dark'),
			Untracked: getIconUri('status-untracked', 'dark'),
			Ignored: getIconUri('status-ignored', 'dark'),
			Conflict: getIconUri('status-conflict', 'dark')
		}
	};

	private getIconPath(theme: string): Uri | undefined {
		switch (this.type) {
			case Status.INDEX_MODIFIED: return Resource.Icons[theme].Modified;
			case Status.MODIFIED: return Resource.Icons[theme].Modified;
			case Status.INDEX_ADDED: return Resource.Icons[theme].Added;
			case Status.INDEX_DELETED: return Resource.Icons[theme].Deleted;
			case Status.DELETED: return Resource.Icons[theme].Deleted;
			case Status.INDEX_RENAMED: return Resource.Icons[theme].Renamed;
			case Status.INDEX_COPIED: return Resource.Icons[theme].Copied;
			case Status.UNTRACKED: return Resource.Icons[theme].Untracked;
			case Status.IGNORED: return Resource.Icons[theme].Ignored;
			case Status.BOTH_DELETED: return Resource.Icons[theme].Conflict;
			case Status.ADDED_BY_US: return Resource.Icons[theme].Conflict;
			case Status.DELETED_BY_THEM: return Resource.Icons[theme].Conflict;
			case Status.ADDED_BY_THEM: return Resource.Icons[theme].Conflict;
			case Status.DELETED_BY_US: return Resource.Icons[theme].Conflict;
			case Status.BOTH_ADDED: return Resource.Icons[theme].Conflict;
			case Status.BOTH_MODIFIED: return Resource.Icons[theme].Conflict;
			default: return void 0;
		}
	}

	private get strikeThrough(): boolean {
		switch (this.type) {
			case Status.DELETED:
			case Status.BOTH_DELETED:
			case Status.DELETED_BY_THEM:
			case Status.DELETED_BY_US:
				return true;
			default:
				return false;
		}
	}

	get decorations(): SCMResourceDecorations {
		const light = { iconPath: this.getIconPath('light') };
		const dark = { iconPath: this.getIconPath('dark') };

		return { strikeThrough: this.strikeThrough, light, dark };
	}

	constructor(private _uri: Uri, private _type: Status) {

	}
}

export class ResourceGroup implements SCMResourceGroup {

	get id(): string { return this._id; }
	get label(): string { return this._label; }
	get resources(): Resource[] { return this._resources; }

	constructor(private _id: string, private _label: string, private _resources: Resource[]) {

	}
}

export class MergeGroup extends ResourceGroup {

	static readonly ID = 'merge';

	constructor(resources: Resource[]) {
		super(MergeGroup.ID, localize('merge changes', "Merge Changes"), resources);
	}
}

export class IndexGroup extends ResourceGroup {

	static readonly ID = 'index';

	constructor(resources: Resource[]) {
		super(IndexGroup.ID, localize('staged changes', "Staged Changes"), resources);
	}
}

export class WorkingTreeGroup extends ResourceGroup {

	static readonly ID = 'workingTree';

	constructor(resources: Resource[]) {
		super(WorkingTreeGroup.ID, localize('changes', "Changes"), resources);
	}
}

export enum Operation {
	Status = 0o1,
	Stage = 0o2,
	Unstage = 0o4,
	Commit = 0o10,
	Clean = 0o20,
	Branch = 0o40,
	Checkout = 0o100,
	Fetch = 0o200,
	Sync = 0o400,
	Push = 0o1000
}

export interface Operations {
	isIdle(): boolean;
	isRunning(operation: Operation): boolean;
}

class OperationsImpl implements Operations {

	constructor(private readonly operations: number = 0) {
		// noop
	}

	start(operation: Operation): OperationsImpl {
		return new OperationsImpl(this.operations | operation);
	}

	end(operation: Operation): OperationsImpl {
		return new OperationsImpl(this.operations & ~operation);
	}

	isRunning(operation: Operation): boolean {
		return (this.operations & operation) !== 0;
	}

	isIdle(): boolean {
		return this.operations === 0;
	}
}

export class Model {

	private _onDidChange = new EventEmitter<SCMResourceGroup[]>();
	readonly onDidChange: Event<SCMResourceGroup[]> = this._onDidChange.event;

	private _onRunOperation = new EventEmitter<Operation>();
	readonly onRunOperation: Event<Operation> = this._onRunOperation.event;

	private _onDidRunOperation = new EventEmitter<Operation>();
	readonly onDidRunOperation: Event<Operation> = this._onDidRunOperation.event;

	@memoize
	get onDidChangeOperations(): Event<void> {
		return anyEvent(this.onRunOperation as Event<any>, this.onDidRunOperation as Event<any>);
	}

	private _mergeGroup = new MergeGroup([]);
	get mergeGroup(): MergeGroup { return this._mergeGroup; }

	private _indexGroup = new IndexGroup([]);
	get indexGroup(): IndexGroup { return this._indexGroup; }

	private _workingTreeGroup = new WorkingTreeGroup([]);
	get workingTreeGroup(): WorkingTreeGroup { return this._workingTreeGroup; }

	get resources(): ResourceGroup[] {
		const result: ResourceGroup[] = [];

		if (this._mergeGroup.resources.length > 0) {
			result.push(this._mergeGroup);
		}

		if (this._indexGroup.resources.length > 0) {
			result.push(this._indexGroup);
		}

		result.push(this._workingTreeGroup);

		return result;
	}

	private _operations = new OperationsImpl();
	get operations(): Operations { return this._operations; }

	private disposables: Disposable[] = [];

	constructor(
		private _repositoryRoot: string,
		private repository: Repository,
		onWorkspaceChange: Event<Uri>
	) {
		/* We use the native Node `watch` for faster, non debounced events.
		 * That way we hopefully get the events during the operations we're
		 * performing, thus sparing useless `git status` calls to refresh
		 * the model's state.
		 */
		const gitPath = path.join(_repositoryRoot, '.git');
		const { event, disposable } = watch(gitPath);
		const onGitChange = mapEvent(event, ({ filename }) => Uri.file(path.join(gitPath, filename)));
		const onRelevantGitChange = filterEvent(onGitChange, uri => !/\/\.git\/index\.lock$/.test(uri.fsPath));
		onRelevantGitChange(this.onFSChange, this, this.disposables);
		this.disposables.push(disposable);

		const onNonGitChange = filterEvent(onWorkspaceChange, uri => !/\/\.git\//.test(uri.fsPath));
		onNonGitChange(this.onFSChange, this, this.disposables);

		this.status();
	}

	get repositoryRoot(): string {
		return this._repositoryRoot;
	}

	private _HEAD: IBranch | undefined;
	get HEAD(): IBranch | undefined {
		return this._HEAD;
	}

	private _refs: IRef[] = [];
	get refs(): IRef[] {
		return this._refs;
	}

	private _remotes: IRemote[] = [];
	get remotes(): IRemote[] {
		return this._remotes;
	}

	@throttle
	async status(): Promise<void> {
		await this.run(Operation.Status);
	}

	@throttle
	async stage(...resources: Resource[]): Promise<void> {
		await this.run(Operation.Stage, () => this.repository.add(resources.map(r => r.uri.fsPath)));
	}

	@throttle
	async unstage(...resources: Resource[]): Promise<void> {
		await this.run(Operation.Unstage, () => this.repository.revertFiles('HEAD', resources.map(r => r.uri.fsPath)));
	}

	@throttle
	async commit(message: string, opts: { all?: boolean, amend?: boolean, signoff?: boolean } = Object.create(null)): Promise<void> {
		await this.run(Operation.Commit, async () => {
			if (opts.all) {
				await this.repository.add([]);
			}

			await this.repository.commit(message, opts);
		});
	}

	@throttle
	async clean(...resources: Resource[]): Promise<void> {
		await this.run(Operation.Clean, async () => {
			const toClean: string[] = [];
			const toCheckout: string[] = [];

			resources.forEach(r => {
				switch (r.type) {
					case Status.UNTRACKED:
					case Status.IGNORED:
						toClean.push(r.uri.fsPath);
						break;

					default:
						toCheckout.push(r.uri.fsPath);
						break;
				}
			});

			const promises: Promise<void>[] = [];

			if (toClean.length > 0) {
				promises.push(this.repository.clean(toClean));
			}

			if (toCheckout.length > 0) {
				promises.push(this.repository.checkout('', toCheckout));
			}

			await Promise.all(promises);
		});
	}

	@throttle
	async branch(name: string): Promise<void> {
		await this.run(Operation.Branch, () => this.repository.branch(name, true));
	}

	@throttle
	async checkout(treeish: string): Promise<void> {
		await this.run(Operation.Checkout, () => this.repository.checkout(treeish, []));
	}

	@throttle
	async fetch(): Promise<void> {
		await this.run(Operation.Fetch, () => this.repository.fetch());
	}

	@throttle
	async sync(): Promise<void> {
		await this.run(Operation.Sync, () => this.repository.sync());
	}

	@throttle
	async push(remote?: string, name?: string, options?: IPushOptions): Promise<void> {
		await this.run(Operation.Push, () => this.repository.push(remote, name, options));
	}

	private async run(operation: Operation, fn: () => Promise<void> = () => Promise.resolve()): Promise<void> {
		return window.withScmProgress(async () => {
			this._operations = this._operations.start(operation);
			this._onRunOperation.fire(operation);

			try {
				await fn();
				await this.update();
			} finally {
				this._operations = this._operations.end(operation);
				this._onDidRunOperation.fire(operation);
			}
		});
	}

	@throttle
	private async update(): Promise<void> {
		const status = await this.repository.getStatus();
		let HEAD: IBranch | undefined;

		try {
			HEAD = await this.repository.getHEAD();

			if (HEAD.name) {
				try {
					HEAD = await this.repository.getBranch(HEAD.name);
				} catch (err) {
					// noop
				}
			}
		} catch (err) {
			// noop
		}

		const [refs, remotes] = await Promise.all([this.repository.getRefs(), this.repository.getRemotes()]);

		this._HEAD = HEAD;
		this._refs = refs;
		this._remotes = remotes;

		const index: Resource[] = [];
		const workingTree: Resource[] = [];
		const merge: Resource[] = [];

		status.forEach(raw => {
			const uri = Uri.file(path.join(this.repositoryRoot, raw.path));

			switch (raw.x + raw.y) {
				case '??': return workingTree.push(new Resource(uri, Status.UNTRACKED));
				case '!!': return workingTree.push(new Resource(uri, Status.IGNORED));
				case 'DD': return merge.push(new Resource(uri, Status.BOTH_DELETED));
				case 'AU': return merge.push(new Resource(uri, Status.ADDED_BY_US));
				case 'UD': return merge.push(new Resource(uri, Status.DELETED_BY_THEM));
				case 'UA': return merge.push(new Resource(uri, Status.ADDED_BY_THEM));
				case 'DU': return merge.push(new Resource(uri, Status.DELETED_BY_US));
				case 'AA': return merge.push(new Resource(uri, Status.BOTH_ADDED));
				case 'UU': return merge.push(new Resource(uri, Status.BOTH_MODIFIED));
			}

			let isModifiedInIndex = false;

			switch (raw.x) {
				case 'M': index.push(new Resource(uri, Status.INDEX_MODIFIED)); isModifiedInIndex = true; break;
				case 'A': index.push(new Resource(uri, Status.INDEX_ADDED)); break;
				case 'D': index.push(new Resource(uri, Status.INDEX_DELETED)); break;
				case 'R': index.push(new Resource(uri, Status.INDEX_RENAMED/*, raw.rename*/)); break;
				case 'C': index.push(new Resource(uri, Status.INDEX_COPIED)); break;
			}

			switch (raw.y) {
				case 'M': workingTree.push(new Resource(uri, Status.MODIFIED/*, raw.rename*/)); break;
				case 'D': workingTree.push(new Resource(uri, Status.DELETED/*, raw.rename*/)); break;
			}
		});

		this._mergeGroup = new MergeGroup(merge);
		this._indexGroup = new IndexGroup(index);
		this._workingTreeGroup = new WorkingTreeGroup(workingTree);

		this._onDidChange.fire(this.resources);
	}

	private onFSChange(uri: Uri): void {
		if (!this.operations.isIdle()) {
			return;
		}

		this.eventuallyUpdateWhenIdleAndWait();
	}

	@debounce(1000)
	private eventuallyUpdateWhenIdleAndWait(): void {
		this.updateWhenIdleAndWait();
	}

	@throttle
	private async updateWhenIdleAndWait(): Promise<void> {
		await this.whenIdle();
		await this.status();
		await new Promise(c => setTimeout(c, 5000));
	}

	private async whenIdle(): Promise<void> {
		while (!this.operations.isIdle()) {
			await eventToPromise(this.onDidRunOperation);
		}
	}
}


text:
#include <stdlib.h>
#include <memory.h>
#include <assert.h>
#include <stdio.h>

#include "NxSocket.h"

/**@brief Set nonblocking mode
 * @return negative on error, 1 on success*/
int SetNonBlock(SOCKET sock)
{
#	ifdef WIN32
	u_long iMode = 1;
	ioctlsocket(sock, FIONBIO, &iMode);
#	else
	int flags;
	if( (flags = fcntl(sock, F_GETFL, 0)) < 0 )
		return -1;
	if( fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0 )
		return -2;
#	endif
	return 1;
}

/**@brief Enable broadcasting on socket
 * @return negative on error, 1 on success*/
int SetBroadcast(SOCKET sock)
{
	int on = 1;
	if(setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)))
		return -1;
	return 1;
}

/**@brief set reusable
 * @return negative on error, 1 on success*/
int SetReusable(SOCKET sock)
{
#ifdef WINSOCK
	char on = 1, off = 0;
	if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)))
		return -1;
	// windows allow to bind the same port
	if(setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, &off, sizeof(off)))
		return -1;
#else
	int on = 1;
	if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)))
		return -1;
#endif
	/*
	if(setsockopt(*sock, SOL_SOCKET, SO_REUSEPORT, &off, sizeof(off)))
		return -1;
		*/
	return 1;
}

/**@brief get ipv4 type
 * @param ip - uint32_t ip representation in network byte order*/
IPv4Info GetIPv4Info(const uint32_t ip)
{
	IPv4Info result;
	uint32_t hostip = ntohl(ip);
	uint32_t netid = 0, hostid = 0;
	int private = 0;

	const uint32_t b1000 = (uint32_t)1  << 31; // 10000000 00000000 00000000 00000000
	const uint32_t b1100 = (uint32_t)3  << 30; // 11000000 00000000 00000000 00000000
	const uint32_t b1110 = (uint32_t)7  << 29; // 11100000 00000000 00000000 00000000
	const uint32_t b1111 = (uint32_t)15 << 28; // 11110000 00000000 00000000 00000000

	const uint32_t anetmask  = (uint32_t)0x7f000000; // 01111111 00000000 00000000 00000000
	const uint32_t ahostmask = (uint32_t)0x00ffffff; // 00000000 11111111 11111111 11111111
	const uint32_t bnetmask  = (uint32_t)0x3fff0000; // 00111111 11111111 00000000 00000000
	const uint32_t bhostmask = (uint32_t)0x0000ffff; // 00000000 00000000 11111111 11111111
	const uint8_t  b1st_private = (uint8_t)0x3f & (uint8_t)172;  // 1-st byte of net id for private B networks
	const uint32_t cnetmask  = (uint32_t)0x1fffff00; // 00011111 11111111 11111111 00000000
	const uint32_t chostmask = (uint32_t)0x000000ff; // 00000000 00000000 00000000 11111111
	const uint8_t  c1st_private = (uint8_t)0x1f & (uint8_t)192; // 1-st byte of net id for private C networks

	result.net_type = IPv4_NETTYPE_UNKNOWN;
	result.addr_type = IPv4_ADDRTYPE_UNKNOWN;

	if( (hostip & b1111) == b1110 )
	{
		result.addr_type = IPv4_ADDRTYPE_BROADCAST;
		return result;
	}
	if( (hostip & b1111) == b1111 )
	{
		result.addr_type = IPv4_ADDRTYPE_RESERVED;
		return result;
	}

	if((hostip & b1000) == 0)
	{
		netid  = (hostip & anetmask)/0x1000000;
		if(netid == 0)
			return result;
		hostid = (hostip & ahostmask);
		if( (hostip & anetmask) == anetmask )
			result.net_type = IPv4_NETTYPE_LOCAL;
		else
			result.net_type = IPv4_NETTYPE_A;
		if( hostid == ahostmask )
		{
			result.addr_type = IPv4_ADDRTYPE_BROADCAST;
			return result;
		}
		if(netid == 10)
			private = 1;
	}
	else if((hostip & b1100) == b1000)
	{
		result.net_type = IPv4_NETTYPE_B;
		netid  = (hostip & bnetmask)/0x10000;
		hostid = (hostip & bhostmask);
		if( hostid == bhostmask )
		{
			result.addr_type = IPv4_ADDRTYPE_BROADCAST;
			return result;
		}
		if(  netid/0x100 == b1st_private && 16 <= netid%0x100 && netid%0x100 <= 31)
			private = 1;
	}
	else if((hostip & b1110) == b1100)
	{
		result.net_type = IPv4_NETTYPE_C;
		netid  = (hostip & cnetmask);
		netid = netid/0x100;
		hostid = (hostip & chostmask);
		if( hostid == chostmask )
		{
			result.addr_type = IPv4_ADDRTYPE_BROADCAST;
			return result;
		}
		if(  netid/0x10000 == c1st_private && (netid%0x10000)/0x100 == 0xa8 )
			private = 1;
	}
	if(hostid == 0)
	{
		if(private)
			result.addr_type = IPv4_ADDRTYPE_NET_PRIVATE;
		else
			result.addr_type = IPv4_ADDRTYPE_NET;
	}
	else
	{
		if(private)
			result.addr_type = IPv4_ADDRTYPE_HOST_PRIVATE;
		else
			result.addr_type = IPv4_ADDRTYPE_HOST;
	}
	return result;
}

void* GetAddr(const struct sockaddr* addr)
{
	if(addr == NULL)
		return NULL;
	if(addr->sa_family == AF_INET)
		return &(((struct sockaddr_in *)addr)->sin_addr);
	if(addr->sa_family == AF_INET6)
		return &(((struct sockaddr_in6*)addr)->sin6_addr);
	return NULL;
}

void PrintSockInfo(SOCKET sock)
{
	struct sockaddr_storage addr;
	socklen_t addrln = sizeof(addr);
	char tmp[50];
	memset(&addr, 0, sizeof(addr));
	memset(tmp, 0, sizeof(tmp));

	printf("SOCKINFO:\n");
	if(!IS_VALID_SOCK(sock))
	{
		printf("Not valid socket\n");
		return;
	}
	printf("socket: %d\n", sock);
	if(getsockname(sock, (struct sockaddr*)&addr, &addrln) != 0)
	{
		printf("  bind: not binded\n");
		return;
	}
	if(!inet_ntop(addr.ss_family, GetAddr((struct sockaddr*)&addr), tmp, sizeof(tmp)))
	{
		printf("  bind: bind address corrupted\n");
		return;
	}
	printf("  bind: %s:%d", tmp, GetPort((struct sockaddr*)&addr));
}

unsigned short GetPort(const struct sockaddr* addr)
{
	if(addr->sa_family == AF_INET)
	{
		return ((struct sockaddr_in*)addr)->sin_port;
	}
	else if(addr->sa_family == AF_INET6)
	{
		return ((struct sockaddr_in6*)addr)->sin6_port;
	}
	else
		return 0;
}

void CopyStorageToSockaddr(const struct sockaddr_storage * st, struct sockaddr* sa)
{
	sa->sa_family = st->ss_family;
	if(st->ss_family == AF_INET)
	{
		((struct sockaddr_in*)sa)->sin_addr = ((const struct sockaddr_in*)st)->sin_addr;
		((struct sockaddr_in*)sa)->sin_port = ((const struct sockaddr_in*)st)->sin_port;
	}
	else if(sa->sa_family == AF_INET6)
	{
		((struct sockaddr_in6*)sa)->sin6_addr = ((const struct sockaddr_in6*)st)->sin6_addr;
		((struct sockaddr_in6*)sa)->sin6_port = ((const struct sockaddr_in6*)st)->sin6_port;
	}
}

void CopySockaddrToStorage(const struct sockaddr * sa, struct sockaddr_storage* st)
{
	st->ss_family = sa->sa_family;
	if(sa->sa_family == AF_INET)
	{
		((struct sockaddr_in*)st)->sin_addr = ((const struct sockaddr_in*)sa)->sin_addr;
		((struct sockaddr_in*)st)->sin_port = ((const struct sockaddr_in*)sa)->sin_port;
	}
	else if(sa->sa_family == AF_INET6)
	{
		((struct sockaddr_in6*)st)->sin6_addr = ((const struct sockaddr_in6*)sa)->sin6_addr;
		((struct sockaddr_in6*)st)->sin6_port = ((const struct sockaddr_in6*)sa)->sin6_port;
	}
}

/**@brief fill sockaddr_storage structure from parameters values
 * @param src - source, where to save data
 * @param addr - dotted notation of IP address
 * @param addrln - the addr length
 * @param port - port number (network byte order)
 * @return negative on error, 0 on success*/
int MakeSockaddr(struct sockaddr* src,
                 const char * addr,
                 const size_t addrln,
                 const unsigned short port)
{
	char * tmp = (char*)malloc((addrln + 1)*sizeof(char));
	memset(tmp, 0, addrln + 1);
	memcpy(tmp, addr, addrln);
	if(src == NULL || addr == NULL || addrln == 0)
		return -1;
	src->sa_family = GetFamily(addr, addrln);
	if( inet_pton(src->sa_family, tmp, GetAddr(src)) != 1 )
	{
		free(tmp);
		return -2;
	}
	free(tmp);
	((struct sockaddr_in6*)src)->sin6_port = port;
	return 0;
}

/**@brief fill sockaddr_storage structure from parameters values
 * @param src - source, where to save data
 * @param host - hostname (try to resolve host)
 * @param hostln - the hostname length
 * @param port - port number (network byte order)
 * @return negative on error, 0 on success*/
int ResolveSockaddr(struct sockaddr* src,
                    const char * host,
                    const size_t hostln,
                    const unsigned short port)
{
	// user getaddrinfo
	return 0;
}

/**@brief get address family by string representation
 * @param addr - address
 * @param addrln - the address length
 * @return AF_INET, if addr may be IPv4, AF_INET6 if IPv6 and -1 on error
 *
 * TODO: For now, this function just search for ':' sign, if it is here, we
 * expect IPv6 address, otherwise - IPv4.*/
int GetFamily(const char* addr, const size_t addrln)
{
	size_t i;
	if(addr == NULL || addrln == 0)
		return 0;
	for(i = 0; i < addrln; ++i)
		if(addr[i] == ':')
			return AF_INET6;
	return AF_INET;
}