Ver código fonte

Try to get rid of GCC conversion warning

Test according to this solution:
http://stackoverflow.com/questions/22041983/conversion-to-unsigned-char-from-int-may-alter-its-value
bel2125 8 anos atrás
pai
commit
e3493d07b4
2 arquivos alterados com 23 adições e 8 exclusões
  1. 10 6
      src/civetweb.c
  2. 13 2
      src/mod_lua.inl

+ 10 - 6
src/civetweb.c

@@ -9387,8 +9387,7 @@ mg_websocket_write_exec(struct mg_connection *conn,
 
 
 	int retval = -1;
 	int retval = -1;
 
 
-	header[0] = (unsigned char)0x80u
-	            + (((unsigned char)(unsigned)opcode) & (unsigned char)0xFu);
+	header[0] = 0x80u | (opcode & 0xf);
 
 
 	/* Frame format: http://tools.ietf.org/html/rfc6455#section-5.2 */
 	/* Frame format: http://tools.ietf.org/html/rfc6455#section-5.2 */
 	if (dataLen < 126) {
 	if (dataLen < 126) {
@@ -13617,6 +13616,10 @@ free_context(struct mg_context *ctx)
 #endif
 #endif
 
 
 		pthread_key_delete(sTlsKey);
 		pthread_key_delete(sTlsKey);
+
+#if defined(USE_LUA)
+		lua_exit_optional_libraries();
+#endif
 	}
 	}
 
 
 	/* deallocate system name string */
 	/* deallocate system name string */
@@ -13754,6 +13757,11 @@ mg_start(const struct mg_callbacks *callbacks,
 			mg_free(ctx);
 			mg_free(ctx);
 			return NULL;
 			return NULL;
 		}
 		}
+
+#if defined(USE_LUA)
+		lua_init_optional_libraries();
+#endif
+
 	} else {
 	} else {
 		/* TODO (low): istead of sleeping, check if sTlsKey is already
 		/* TODO (low): istead of sleeping, check if sTlsKey is already
 		 * initialized. */
 		 * initialized. */
@@ -13767,10 +13775,6 @@ mg_start(const struct mg_callbacks *callbacks,
 #endif
 #endif
 	pthread_setspecific(sTlsKey, &tls);
 	pthread_setspecific(sTlsKey, &tls);
 
 
-#if defined(USE_LUA)
-	lua_init_optional_libraries();
-#endif
-
 	ok = 0 == pthread_mutex_init(&ctx->thread_mutex, &pthread_mutex_attr);
 	ok = 0 == pthread_mutex_init(&ctx->thread_mutex, &pthread_mutex_attr);
 #if !defined(ALTERNATIVE_QUEUE)
 #if !defined(ALTERNATIVE_QUEUE)
 	ok &= 0 == pthread_cond_init(&ctx->sq_empty, NULL);
 	ok &= 0 == pthread_cond_init(&ctx->sq_empty, NULL);

+ 13 - 2
src/mod_lua.inl

@@ -1829,14 +1829,25 @@ lua_websocket_close(struct mg_connection *conn, void *ws_arg)
 }
 }
 #endif
 #endif
 
 
+static void *lib_handle_uuid = NULL;
 
 
 static void
 static void
 lua_init_optional_libraries(void)
 lua_init_optional_libraries(void)
 {
 {
 #if !defined(_WIN32)
 #if !defined(_WIN32)
-	void *dll_handle = dlopen("libuuid.so", RTLD_LAZY);
-	pf_uuid_generate.p = dlsym(dll_handle, "uuid_generate");
+	lib_handle_uuid = dlopen("libuuid.so", RTLD_LAZY);
+	pf_uuid_generate.p = dlsym(lib_handle_uuid, "uuid_generate");
 #else
 #else
 	pf_uuid_generate.p = 0;
 	pf_uuid_generate.p = 0;
 #endif
 #endif
 }
 }
+
+static void
+lua_exit_optional_libraries(void)
+{
+#if !defined(_WIN32)
+	dlclose(lib_handle_uuid);
+#endif
+	pf_uuid_generate.p = 0;
+	lib_handle_uuid = NULL;
+}