Skip to content

Commit 55796d9

Browse files
committed
fix cmakefile for windows and compiling warnings
1 parent 3bac557 commit 55796d9

File tree

10 files changed

+24
-11
lines changed

10 files changed

+24
-11
lines changed

include/co/thread.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ inline void mutex_unlock(mutex_t* m) { LeaveCriticalSection(m); }
2424

2525
typedef CONDITION_VARIABLE cond_t;
2626
inline void cond_init(cond_t* c) { InitializeConditionVariable(c); }
27-
inline void cond_destroy(cond_t* c) {}
27+
inline void cond_destroy(cond_t*) {}
2828
inline void cond_wait(cond_t* c, mutex_t* m) { SleepConditionVariableCS(c, m, INFINITE); }
2929
inline bool cond_wait(cond_t* c, mutex_t* m, uint32 ms) { return SleepConditionVariableCS(c, m, ms) == TRUE; }
3030
inline void cond_notify(cond_t* c) { WakeAllConditionVariable(c); }
@@ -41,7 +41,7 @@ typedef DWORD tls_t;
4141
inline void tls_init(tls_t* k) { *k = TlsAlloc(); assert(*k != TLS_OUT_OF_INDEXES); }
4242
inline void tls_destroy(tls_t k) { TlsFree(k); }
4343
inline void* tls_get(tls_t k) { return TlsGetValue(k); }
44-
inline void tls_set(tls_t k, void* v) { BOOL r = TlsSetValue(k, v); assert(r); }
44+
inline void tls_set(tls_t k, void* v) { BOOL r = TlsSetValue(k, v); assert(r); (void)r; }
4545

4646
} // xx
4747
} // co

src/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ endif()
6969

7070
if(WIN32)
7171
target_compile_definitions(co PUBLIC WIN32_LEAN_AND_MEAN)
72-
if(not MSVC)
72+
target_compile_definitions(co PRIVATE _WINSOCK_DEPRECATED_NO_WARNINGS)
73+
if(NOT MSVC)
7374
target_compile_definitions(co PRIVATE _FILE_OFFSET_BITS=64)
7475
target_link_libraries(co PUBLIC ws2_32)
7576
endif()

src/fs_win.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#ifdef _WIN32
22
#include "co/fs.h"
33

4+
#ifndef WIN32_LEAN_AND_MEAN
45
#define WIN32_LEAN_AND_MEAN
6+
#endif
7+
#ifdef _MSC_VER
58
#pragma warning (disable:4800)
9+
#endif
610
#include <Windows.h>
711

812
namespace fs {

src/os_win.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include "co/os.h"
44
#include <signal.h>
55

6+
#ifndef WIN32_LEAN_AND_MEAN
67
#define WIN32_LEAN_AND_MEAN
8+
#endif
79
#include <Windows.h>
810

911
namespace os {

src/so/http.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ namespace http {
4242
#ifdef HAS_LIBCURL
4343
struct curl_ctx {
4444
curl_ctx()
45-
: l(NULL), upload(NULL), upsize(0), s(-1), cs(-1), action(0), ms(0) {
45+
: l(NULL), upload(NULL), upsize(0),
46+
s((curl_socket_t)-1), cs((curl_socket_t)-1), action(0), ms(0) {
4647
multi = curl_multi_init();
4748
easy = curl_easy_init();
4849
memset(err, 0, sizeof(err));
@@ -359,7 +360,7 @@ void Client::do_io() {
359360
}
360361
}
361362

362-
int multi_socket_cb(CURL* easy, curl_socket_t s, int action, void* userp, void* socketp) {
363+
int multi_socket_cb(CURL*, curl_socket_t s, int action, void* userp, void*) {
363364
CHECK(userp != NULL);
364365
curl_ctx* ctx = (curl_ctx*)userp;
365366
switch (action) {
@@ -430,7 +431,7 @@ size_t easy_read_cb(char* p, size_t size, size_t nmemb, void* userp) {
430431
return n;
431432
}
432433

433-
curl_socket_t easy_opensocket_cb(void* userp, curlsocktype purpose, struct curl_sockaddr* addr) {
434+
curl_socket_t easy_opensocket_cb(void* userp, curlsocktype, struct curl_sockaddr* addr) {
434435
curl_ctx* ctx = (curl_ctx*)userp;
435436
curl_socket_t fd = co::socket(addr->family, addr->socktype, addr->protocol);
436437
if (fd == (sock_t)-1) {
@@ -447,12 +448,12 @@ curl_socket_t easy_opensocket_cb(void* userp, curlsocktype purpose, struct curl_
447448
return CURL_SOCKET_BAD;
448449
}
449450

450-
int easy_closesocket_cb(void* userp, curl_socket_t fd) {
451+
int easy_closesocket_cb(void*, curl_socket_t fd) {
451452
if (fd != (curl_socket_t)-1) return co::close(fd);
452453
return 0;
453454
}
454455

455-
int easy_sockopt_cb(void* userp, curl_socket_t fd, curlsocktype purpose) {
456+
int easy_sockopt_cb(void*, curl_socket_t, curlsocktype) {
456457
return CURL_SOCKOPT_ALREADY_CONNECTED;
457458
}
458459

src/so/rpc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Ping : public Service {
4242

4343
virtual const char* name() const { return "ping"; }
4444

45-
virtual void process(const Json& req, Json& res) {
45+
virtual void process(const Json&, Json& res) {
4646
res.add_member("err", 200);
4747
res.add_member("errmsg", "pong");
4848
}

src/time_win.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include <time.h>
55
#include <winsock2.h> // for struct timeval
66

7+
#ifndef WIN32_LEAN_AND_MEAN
78
#define WIN32_LEAN_AND_MEAN
9+
#endif
810
#include <Windows.h>
911

1012
namespace now {

src/unitest.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#ifdef _MSC_VER
1010
#pragma warning(disable:4503)
1111
#endif
12+
#ifndef WIN32_LEAN_AND_MEAN
1213
#define WIN32_LEAN_AND_MEAN
14+
#endif
1315
#include <Windows.h>
1416
#endif
1517

src/xmake.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ target("libco")
1515

1616
if is_plat("windows", "mingw") then
1717
add_defines("WIN32_LEAN_AND_MEAN")
18+
add_defines("_WINSOCK_DEPRECATED_NO_WARNINGS")
1819
add_files("__/StackWalker.cpp")
1920
add_files("co/detours/creatwth.cpp")
2021
add_files("co/detours/detours.cpp")

unitest/fastring.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ DEF_test(fastring) {
7070
s.append(u);
7171
EXPECT_EQ(s, "xxxx");
7272

73-
int i = 'x';
74-
s.append(i);
73+
char c = 'x';
74+
s.append(c);
7575
EXPECT_EQ(s, "xxxxx");
7676

7777
EXPECT_EQ(fastring("x") + 'x', "xx");

0 commit comments

Comments
 (0)