lws_intptr_t
authorAndy Green <andy@warmcat.com>
Fri, 7 Jul 2017 00:32:04 +0000 (08:32 +0800)
committerAndy Green <andy@warmcat.com>
Fri, 7 Jul 2017 00:32:04 +0000 (08:32 +0800)
16 files changed:
CMakeLists.txt
lib/context.c
lib/extension.c
lib/getifaddrs.c
lib/header.c
lib/http2.c
lib/lejp-conf.c
lib/libuv.c
lib/libwebsockets.h
lib/lws-plat-win.c
lib/output.c
lib/parsers.c
lib/server.c
lws_config.h.in
test-server/test-ping.c
test-server/test-server-pthreads.c

index 4a6f6cf..9ad0174 100644 (file)
@@ -517,6 +517,12 @@ set(LWS_HAVE_WORKING_VFORK LWS_HAVE_VFORK)
 
 CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
 
+CHECK_C_SOURCE_COMPILES("#include <stdint.h> 
+       int main(void) {
+               intptr_t test = 1;
+               return 0;
+       }" LWS_HAS_INTPTR_T)
+
 # These don't work Cross...
 #CHECK_TYPE_SIZE(pid_t PID_T_SIZE)
 #CHECK_TYPE_SIZE(size_t SIZE_T_SIZE)
@@ -1807,6 +1813,7 @@ message(" LWS_HAVE_LIBCAP = ${LWS_HAVE_LIBCAP}")
 message(" LWS_HAVE_ATOLL = ${LWS_HAVE_ATOLL}")
 message(" LWS_HAVE__ATOI64 = ${LWS_HAVE__ATOI64}")
 message(" LWS_HAVE_STAT32I64 = ${LWS_HAVE_STAT32I64}")
+message(" LWS_HAS_INTPTR_T = ${LWS_HAS_INTPTR_T}")
 
 message("---------------------------------------------------------------------")
 
index 7e875ea..666f51e 100644 (file)
@@ -553,7 +553,7 @@ lws_create_vhost(struct lws_context *context,
                        for (n = 0; n < vh->count_protocols; n++)
                                if (!strcmp(pvo->value, vh->protocols[n].name)) {
                                        ((struct lws_protocol_vhost_options *)pvo)->value =
-                                                       (const char *)(long)n;
+                                                       (const char *)(lws_intptr_t)n;
                                        break;
                                }
                        if (n == vh->count_protocols)
index 187d5a5..d09b5af 100644 (file)
@@ -195,7 +195,7 @@ int lws_ext_cb_all_exts(struct lws_context *context, struct lws *wsi,
 
        while (ext && ext->callback && !handled) {
                m = ext->callback(context, ext, wsi, reason,
-                                 (void *)(long)n, arg, len);
+                                 (void *)(lws_intptr_t)n, arg, len);
                if (m < 0) {
                        lwsl_ext("Ext '%s' failed to handle callback %d!\n",
                                 wsi->active_extensions[n]->name, reason);
index 07093dc..0783019 100644 (file)
@@ -229,7 +229,7 @@ print_addr(const char *s, struct sockaddr *sa)
        printf("  %s=%d/", s, sa->sa_family);
 #ifdef LWS_HAVE_STRUCT_SOCKADDR_SA_LEN
        for (i = 0;
-              i < sa->sa_len - ((long)sa->sa_data - (long)&sa->sa_family); i++)
+              i < sa->sa_len - ((lws_intptr_t)sa->sa_data - (lws_intptr_t)&sa->sa_family); i++)
                printf("%02x", ((unsigned char *)sa->sa_data)[i]);
 #else
        for (i = 0; i < sizeof(sa->sa_data); i++)
index 8dd0d5f..c727490 100644 (file)
@@ -71,7 +71,7 @@ int lws_finalize_http_header(struct lws *wsi, unsigned char **p,
 #else
        (void)wsi;
 #endif
-       if ((long)(end - *p) < 3)
+       if ((lws_intptr_t)(end - *p) < 3)
                return 1;
        *((*p)++) = '\x0d';
        *((*p)++) = '\x0a';
index 7406513..0bde700 100644 (file)
@@ -320,7 +320,7 @@ lws_http2_parser(struct lws *wsi, unsigned char c)
                                break;
                        case LWS_HTTP2_FRAME_TYPE_WINDOW_UPDATE:
                                wsi->u.http2.hpack_e_dep &= ~(1 << 31);
-                               if ((long long)swsi->u.http2.tx_credit + (unsigned long long)wsi->u.http2.hpack_e_dep > (~(1 << 31)))
+                               if ((lws_intptr_t)swsi->u.http2.tx_credit + (lws_intptr_t)wsi->u.http2.hpack_e_dep > (~(1 << 31)))
                                        return 1; /* actually need to close swsi not the whole show */
                                swsi->u.http2.tx_credit += wsi->u.http2.hpack_e_dep;
                                if (swsi->u.http2.waiting_tx_credit && swsi->u.http2.tx_credit > 0) {
index 8fb0553..966a6a0 100644 (file)
@@ -199,8 +199,8 @@ struct jpargs {
 static void *
 lwsws_align(struct jpargs *a)
 {
-       if ((unsigned long)(a->p) & 15)
-               a->p += 16 - ((unsigned long)(a->p) & 15);
+       if ((lws_intptr_t)(a->p) & 15)
+               a->p += 16 - ((lws_intptr_t)(a->p) & 15);
 
        return a->p;
 }
index c0d5aa3..62681d3 100644 (file)
@@ -167,7 +167,7 @@ lws_uv_initvhost(struct lws_vhost* vh, struct lws* wsi)
                                &wsi->w_read.uv_watcher, wsi->desc.sockfd);
        if (n) {
                lwsl_err("uv_poll_init failed %d, sockfd=%p\n",
-                                n, (void *)(long)wsi->desc.sockfd);
+                                n, (void *)(lws_intptr_t)wsi->desc.sockfd);
 
                return -1;
        }
@@ -529,7 +529,7 @@ lws_libuv_closehandle(struct lws *wsi)
 static void
 lws_libuv_closewsi_m(uv_handle_t* handle)
 {
-       lws_sockfd_type sockfd = (lws_sockfd_type)(long long)handle->data;
+       lws_sockfd_type sockfd = (lws_sockfd_type)(lws_intptr_t)handle->data;
 
        compatible_close(sockfd);
 }
@@ -539,7 +539,7 @@ lws_libuv_closehandle_manually(struct lws *wsi)
 {
        uv_handle_t *h = (void *)&wsi->w_read.uv_watcher;
 
-       h->data = (void *)(long long)wsi->desc.sockfd;
+       h->data = (void *)(lws_intptr_t)wsi->desc.sockfd;
        /* required to defer actual deletion until libuv has processed it */
        uv_close((uv_handle_t*)&wsi->w_read.uv_watcher, lws_libuv_closewsi_m);
 }
index 2214b01..3358910 100644 (file)
@@ -33,6 +33,13 @@ extern "C" {
 #include <stdarg.h>
 #endif
 
+#if defined(LWS_HAS_INTPTR_T)
+#include <stdint.h>
+#define lws_intptr_t intptr_t
+#else
+typedef unsigned long long lws_intptr_t;
+#endif
+
 #if defined(LWS_WITH_ESP8266)
 struct sockaddr_in;
 #define LWS_POSIX 0
index 9f50cda..fc4f1fd 100644 (file)
@@ -419,7 +419,7 @@ lws_interface_to_sa(int ipv6,
        if (address == INADDR_NONE)
                return -1;
 
-       addr->sin_addr.s_addr = (unsigned long)address;
+       addr->sin_addr.s_addr = (lws_intptr_t)address;
 
        return 0;
 }
index c7430eb..be0c010 100644 (file)
@@ -613,7 +613,7 @@ LWS_VISIBLE int lws_serve_http_file_fragment(struct lws *wsi)
 
                        lwsl_notice("%s: doing range start %llu\n", __func__, wsi->u.http.range.start);
 
-                       if ((long)lws_vfs_file_seek_cur(wsi->u.http.fop_fd,
+                       if ((long long)lws_vfs_file_seek_cur(wsi->u.http.fop_fd,
                                                   wsi->u.http.range.start -
                                                   wsi->u.http.filepos) < 0)
                                goto file_had_it;
index 9699218..3f47be9 100644 (file)
@@ -357,7 +357,7 @@ int lws_header_table_detach(struct lws *wsi, int autoservice)
        }
 #endif
 
-       assert(!!pt->ah_wait_list_length == !!(int)(long)pt->ah_wait_list);
+       assert(!!pt->ah_wait_list_length == !!(lws_intptr_t)pt->ah_wait_list);
 bail:
        lwsl_info("%s: wsi %p: ah %p (tsi=%d, count = %d)\n", __func__,
          (void *)wsi, (void *)ah, wsi->tsi,
index 1873469..4c801d5 100644 (file)
@@ -470,8 +470,8 @@ lws_http_serve(struct lws *wsi, char *uri, const char *origin,
        if (spin == 5)
                lwsl_err("symlink loop %s \n", path);
 
-       n = sprintf(sym, "%08lX%08lX",
-                   (unsigned long)lws_vfs_get_length(wsi->u.http.fop_fd),
+       n = sprintf(sym, "%08llX%08lX",
+                   (unsigned long long)lws_vfs_get_length(wsi->u.http.fop_fd),
                    (unsigned long)lws_vfs_get_mod_time(wsi->u.http.fop_fd));
 
        /* disable ranges if IF_RANGE token invalid */
@@ -543,10 +543,10 @@ lws_http_serve(struct lws *wsi, char *uri, const char *origin,
                if (n > (int)strlen(pvo->name) &&
                    !strcmp(&path[n - strlen(pvo->name)], pvo->name)) {
                        wsi->sending_chunked = 1;
-                       wsi->protocol_interpret_idx = (char)(long)pvo->value;
+                       wsi->protocol_interpret_idx = (char)(lws_intptr_t)pvo->value;
                        lwsl_info("want %s interpreted by %s\n", path,
-                                   wsi->vhost->protocols[(int)(long)(pvo->value)].name);
-                       wsi->protocol = &wsi->vhost->protocols[(int)(long)(pvo->value)];
+                                   wsi->vhost->protocols[(int)(lws_intptr_t)(pvo->value)].name);
+                       wsi->protocol = &wsi->vhost->protocols[(int)(lws_intptr_t)(pvo->value)];
                        if (lws_ensure_user_space(wsi))
                                return -1;
                        break;
@@ -1928,7 +1928,7 @@ lws_adopt_descriptor_vhost(struct lws_vhost *vh, lws_adoption_type type,
 
        if (type & LWS_ADOPT_SOCKET) { /* socket desc */
                lwsl_debug("%s: new wsi %p, sockfd %d\n", __func__, new_wsi,
-                          (int)(size_t)fd.sockfd);
+                          (int)(lws_intptr_t)fd.sockfd);
 
                if (type & LWS_ADOPT_HTTP)
                        /* the transport is accepted...
@@ -1944,7 +1944,7 @@ lws_adopt_descriptor_vhost(struct lws_vhost *vh, lws_adoption_type type,
 #endif
        } else /* file desc */
                lwsl_debug("%s: new wsi %p, filefd %d\n", __func__, new_wsi,
-                          (int)(size_t)fd.filefd);
+                          (int)(lws_intptr_t)fd.filefd);
 
        /*
         * A new connection was accepted. Give the user a chance to
@@ -2467,7 +2467,7 @@ try_pollout:
                         */
                        if ((wsi->vhost->protocols[0].callback)(wsi,
                                        LWS_CALLBACK_FILTER_NETWORK_CONNECTION,
-                                       NULL, (void *)(long)accept_fd, 0)) {
+                                       NULL, (void *)(lws_intptr_t)accept_fd, 0)) {
                                lwsl_debug("Callback denied network connection\n");
                                compatible_close(accept_fd);
                                break;
index 483ad20..514afeb 100644 (file)
 #cmakedefine LWS_HAVE_TLSV1_2_CLIENT_METHOD
 #cmakedefine LWS_HAVE_SSL_SET_INFO_CALLBACK
 
+#cmakedefine LWS_HAS_INTPTR_T
+
 ${LWS_SIZEOFPTR_CODE}
index 0e0d5bc..f0f00d3 100644 (file)
@@ -162,7 +162,7 @@ callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason,
                l = 0;
 
                while (shift >= 0) {
-                       l |= ((unsigned long long)*p++) << shift;
+                       l |= ((lws_intptr_t)*p++) << shift;
                        shift -= 8;
                }
 
index cf4302c..62cb685 100644 (file)
@@ -142,7 +142,7 @@ void *thread_dumb_increment(void *threadid)
 
 void *thread_service(void *threadid)
 {
-       while (lws_service_tsi(context, 50, (int)(long)threadid) >= 0 && !force_exit)
+       while (lws_service_tsi(context, 50, (int)(lws_intptr_t)threadid) >= 0 && !force_exit)
                ;
 
        pthread_exit(NULL);
@@ -368,7 +368,7 @@ int main(int argc, char **argv)
 
        for (n = 0; n < lws_get_count_threads(context); n++)
                if (pthread_create(&pthread_service[n], NULL, thread_service,
-                                  (void *)(long)n))
+                                  (void *)(lws_intptr_t)n))
                        lwsl_err("Failed to start service thread\n");
 
        /* wait for all the service threads to exit */