From 7262e14dc1c9dd30a47424db9d370fe3bae2bf63 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Fri, 7 Jul 2017 08:32:04 +0800 Subject: [PATCH] lws_intptr_t --- CMakeLists.txt | 7 +++++++ lib/context.c | 2 +- lib/extension.c | 2 +- lib/getifaddrs.c | 2 +- lib/header.c | 2 +- lib/http2.c | 2 +- lib/lejp-conf.c | 4 ++-- lib/libuv.c | 6 +++--- lib/libwebsockets.h | 7 +++++++ lib/lws-plat-win.c | 2 +- lib/output.c | 2 +- lib/parsers.c | 2 +- lib/server.c | 16 ++++++++-------- lws_config.h.in | 2 ++ test-server/test-ping.c | 2 +- test-server/test-server-pthreads.c | 4 ++-- 16 files changed, 40 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a6f6cf..9ad0174 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 + 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("---------------------------------------------------------------------") diff --git a/lib/context.c b/lib/context.c index 7e875ea..666f51e 100644 --- a/lib/context.c +++ b/lib/context.c @@ -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) diff --git a/lib/extension.c b/lib/extension.c index 187d5a5..d09b5af 100644 --- a/lib/extension.c +++ b/lib/extension.c @@ -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); diff --git a/lib/getifaddrs.c b/lib/getifaddrs.c index 07093dc..0783019 100644 --- a/lib/getifaddrs.c +++ b/lib/getifaddrs.c @@ -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++) diff --git a/lib/header.c b/lib/header.c index 8dd0d5f..c727490 100644 --- a/lib/header.c +++ b/lib/header.c @@ -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'; diff --git a/lib/http2.c b/lib/http2.c index 7406513..0bde700 100644 --- a/lib/http2.c +++ b/lib/http2.c @@ -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) { diff --git a/lib/lejp-conf.c b/lib/lejp-conf.c index 8fb0553..966a6a0 100644 --- a/lib/lejp-conf.c +++ b/lib/lejp-conf.c @@ -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; } diff --git a/lib/libuv.c b/lib/libuv.c index c0d5aa3..62681d3 100644 --- a/lib/libuv.c +++ b/lib/libuv.c @@ -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); } diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 2214b01..3358910 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -33,6 +33,13 @@ extern "C" { #include #endif +#if defined(LWS_HAS_INTPTR_T) +#include +#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 diff --git a/lib/lws-plat-win.c b/lib/lws-plat-win.c index 9f50cda..fc4f1fd 100644 --- a/lib/lws-plat-win.c +++ b/lib/lws-plat-win.c @@ -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; } diff --git a/lib/output.c b/lib/output.c index c7430eb..be0c010 100644 --- a/lib/output.c +++ b/lib/output.c @@ -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; diff --git a/lib/parsers.c b/lib/parsers.c index 9699218..3f47be9 100644 --- a/lib/parsers.c +++ b/lib/parsers.c @@ -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, diff --git a/lib/server.c b/lib/server.c index 1873469..4c801d5 100644 --- a/lib/server.c +++ b/lib/server.c @@ -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; diff --git a/lws_config.h.in b/lws_config.h.in index 483ad20..514afeb 100644 --- a/lws_config.h.in +++ b/lws_config.h.in @@ -149,4 +149,6 @@ #cmakedefine LWS_HAVE_TLSV1_2_CLIENT_METHOD #cmakedefine LWS_HAVE_SSL_SET_INFO_CALLBACK +#cmakedefine LWS_HAS_INTPTR_T + ${LWS_SIZEOFPTR_CODE} diff --git a/test-server/test-ping.c b/test-server/test-ping.c index 0e0d5bc..f0f00d3 100644 --- a/test-server/test-ping.c +++ b/test-server/test-ping.c @@ -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; } diff --git a/test-server/test-server-pthreads.c b/test-server/test-server-pthreads.c index cf4302c..62cb685 100644 --- a/test-server/test-server-pthreads.c +++ b/test-server/test-server-pthreads.c @@ -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 */ -- 2.7.4