Skip to content

Commit

Permalink
More Windows build fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
snej committed Sep 7, 2023
1 parent 11be7a8 commit 61749b5
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 11 deletions.
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ add_subdirectory(vendor/mbedtls)
if (MSVC)
# MSVC:
add_definitions(-DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0A00)
add_compile_options(/W4) # TODO: Add /WX
add_compile_options(
/W4 # I think this means 'turn on lots of warnings'
/wd4068 # ignore unknown pragma
/wd4100 # ignore unused fn parameters
/wd4267 # ignore implicit integer truncation
)
else()
# Clang & GCC:
add_compile_options(
Expand Down Expand Up @@ -130,6 +135,11 @@ if(APPLE)
)
endif()

if (MSVC)
target_sources( LibCrouton PRIVATE
src/support/asprintf.c
)
endif()

#### DEMO TOOLS

Expand Down
4 changes: 4 additions & 0 deletions crouton.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@
278F7E582AA93D5A005B12F2 /* HTTPHandler.hh */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = HTTPHandler.hh; sourceTree = "<group>"; };
278F7E592AA93D5A005B12F2 /* HTTPHandler.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = HTTPHandler.cc; sourceTree = "<group>"; };
278F7E5D2AAA69B5005B12F2 /* Base.hh */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Base.hh; sourceTree = "<group>"; };
278F7E5E2AAA73BC005B12F2 /* asprintf.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = asprintf.c; sourceTree = "<group>"; };
278F7E5F2AAA73BC005B12F2 /* asprintf.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = asprintf.h; sourceTree = "<group>"; };
279D5D402A8FE08D005C3066 /* AddrInfo.hh */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = AddrInfo.hh; sourceTree = "<group>"; };
279D5D412A8FE08D005C3066 /* AddrInfo.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = AddrInfo.cc; sourceTree = "<group>"; };
279D5D442A8FE174005C3066 /* Crouton.hh */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Crouton.hh; sourceTree = "<group>"; };
Expand Down Expand Up @@ -910,6 +912,8 @@
279D5D572A9146DA005C3066 /* support */ = {
isa = PBXGroup;
children = (
278F7E5E2AAA73BC005B12F2 /* asprintf.c */,
278F7E5F2AAA73BC005B12F2 /* asprintf.h */,
27F49CD52A9E4E8E00BFB24C /* Backtrace.cc */,
27F49CD42A9E4E8E00BFB24C /* Backtrace.hh */,
2727304B2A8E811B000CCA22 /* Defer.hh */,
Expand Down
2 changes: 1 addition & 1 deletion include/Stream.hh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace crouton {

void read_start();
void _allocCallback(size_t suggested, uv_buf_t*);
void _readCallback(ssize_t nread, const uv_buf_t*);
void _readCallback(intptr_t nread, const uv_buf_t*);

uv_stream_s* _stream = nullptr; // The libuv stream
std::vector<BufferRef> _input; // Buffers of already-read data
Expand Down
1 change: 0 additions & 1 deletion src/AddrInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "AddrInfo.hh"
#include "Defer.hh"
#include "UVInternal.hh"
#include <unistd.h>

namespace crouton {
using namespace std;
Expand Down
1 change: 0 additions & 1 deletion src/FileStream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "FileStream.hh"
#include "UVInternal.hh"
#include <unistd.h>

namespace crouton {
using namespace std;
Expand Down
1 change: 0 additions & 1 deletion src/HTTPConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "UVInternal.hh"
#include "llhttp.h"
#include <sstream>
#include <strings.h>

namespace crouton {
using namespace std;
Expand Down
4 changes: 2 additions & 2 deletions src/IStream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace crouton {
MutableBytes::MutableBytes(uv_buf_t buf) :span((byte*)buf.base, buf.len) { }
ConstBytes::ConstBytes(uv_buf_t buf) :span((const byte*)buf.base, buf.len) { }

MutableBytes::operator uv_buf_t() const { return {.base = (char*)data(), .len = size()}; }
ConstBytes::operator uv_buf_t() const { return {.base = (char*)data(), .len = size()}; }
MutableBytes::operator uv_buf_t() const { return uv_buf_init((char*)data(), unsigned(size())); }
ConstBytes::operator uv_buf_t() const { return uv_buf_init((char*)data(), unsigned(size())); }

Future<size_t> IStream::read(MutableBytes buf) {
size_t bytesRead = 0;
Expand Down
5 changes: 2 additions & 3 deletions src/Stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "Stream.hh"
#include "UVInternal.hh"
#include <unistd.h>

namespace crouton {
using namespace std;
Expand Down Expand Up @@ -146,7 +145,7 @@ namespace crouton {
auto alloc = [](uv_handle_t* h, size_t suggested, uv_buf_t* uvbuf) {
static_cast<Stream*>(h->data)->_allocCallback(suggested, uvbuf);
};
auto read = [](uv_stream_t* h, ssize_t nread, const uv_buf_t* uvbuf) {
auto read = [](uv_stream_t* h, intptr_t nread, const uv_buf_t* uvbuf) {
static_cast<Stream*>(h->data)->_readCallback(nread, uvbuf);
};
check(uv_read_start(_stream, alloc, read), "reading from the network");
Expand All @@ -171,7 +170,7 @@ namespace crouton {


/// libuv is notifying me that it put data into an allocated buffer.
void Stream::_readCallback(ssize_t nread, const uv_buf_t* uvbuf) {
void Stream::_readCallback(intptr_t nread, const uv_buf_t* uvbuf) {
int err;
if (nread > 0) {
// A successful read into _readingBuf:
Expand Down
2 changes: 1 addition & 1 deletion src/mbedtls/TLSSocket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ namespace crouton::mbed {


// TLSSocket wants to read.
Future<ssize_t> read(void *buf, size_t maxLen) {
Future<intptr_t> read(void *buf, size_t maxLen) {
//cerr << "TLSStream read(" << maxLen << ") ...\n";
if (_readEOF) {
std::cerr << "WARNING: Client is reading from TLSSocket that's already at EOF\n";
Expand Down
26 changes: 26 additions & 0 deletions src/support/asprintf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright (C) 2014 insane coder (http://insanecoding.blogspot.com/, http://asprintf.insanecoding.org/)
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include "asprintf.h"

int asprintf(char** strp, const char* fmt, ...) {
int r;
va_list ap;
va_start(ap, fmt);
r = vasprintf(strp, fmt, ap);
va_end(ap);
return (r);
}
40 changes: 40 additions & 0 deletions src/support/asprintf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright (C) 2014 insane coder (http://insanecoding.blogspot.com/, http://asprintf.insanecoding.org/)
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef INSANE_ASPRINTF_H
#define INSANE_ASPRINTF_H

#ifndef __cplusplus
# include <stdarg.h>
#else
# include <cstdarg>
extern "C" {
#endif

#define insane_free(ptr) \
{ \
free(ptr); \
ptr = 0; \
}

int vasprintf(char** strp, const char* fmt, va_list ap);
int asprintf(char** strp, const char* fmt, ...);

#ifdef __cplusplus
}
#endif

#endif

0 comments on commit 61749b5

Please sign in to comment.