Index: source/lib/sysdep/os/win/wposix/wfilesystem.h =================================================================== --- source/lib/sysdep/os/win/wposix/wfilesystem.h +++ source/lib/sysdep/os/win/wposix/wfilesystem.h @@ -30,8 +30,12 @@ #include // for S_IFREG etc. #if MSC_VERSION +#include // for read & lseek typedef unsigned int mode_t; // defined by MinGW but not VC #define stat _stat64 // we need 64-bit st_size and time_t +#else +extern int read (int fd, void* buf, size_t nbytes); // thunk +extern off_t lseek(int fd, off_t ofs, int whence); // thunk #endif // permission masks when creating files (_wsopen_s doesn't distinguish @@ -57,8 +61,6 @@ // // -extern int read (int fd, void* buf, size_t nbytes); // thunk extern int write(int fd, void* buf, size_t nbytes); // thunk -extern off_t lseek(int fd, off_t ofs, int whence); // thunk #endif // #ifndef INCLUDED_WFILESYSTEM Index: source/lib/sysdep/os/win/wposix/wfilesystem.cpp =================================================================== --- source/lib/sysdep/os/win/wposix/wfilesystem.cpp +++ source/lib/sysdep/os/win/wposix/wfilesystem.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -261,21 +261,22 @@ // identifier. therefore, translate from MS CRT names via thunk functions. // efficiency is less important, and the overhead could be optimized away. -int read(int fd, void* buf, size_t nbytes) -{ - return _read(fd, buf, (int)nbytes); -} - int write(int fd, void* buf, size_t nbytes) { return _write(fd, buf, (int)nbytes); } +#if !defined(MSC_VERSION) off_t lseek(int fd, off_t ofs, int whence) { return _lseeki64(fd, ofs, whence); } +int read(int fd, void* buf, size_t nbytes) +{ + return _read(fd, buf, (int)nbytes) +} +#endif int wtruncate(const OsPath& pathname, off_t length) { Index: source/scriptinterface/FunctionWrapper.h =================================================================== --- source/scriptinterface/FunctionWrapper.h +++ source/scriptinterface/FunctionWrapper.h @@ -60,13 +60,13 @@ /** * Convenient struct to get info on a [class] [const] function pointer. - * TODO VS19: I ran into a really weird bug with an auto specialisation on this taking function pointers. - * It'd be good to add it back once we upgrade. + * Prefer the args_info variant which avoids decltype. */ - template struct args_info; + template struct args_info_t; + template struct args_info : public args_info_t {}; template - struct args_info + struct args_info_t { static constexpr const size_t nb_args = sizeof...(Types); using return_type = R; @@ -75,9 +75,9 @@ }; template - struct args_info : public args_info { using object_type = C; }; + struct args_info_t : public args_info_t { using object_type = C; }; template - struct args_info : public args_info {}; + struct args_info_t : public args_info_t {}; /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// @@ -186,7 +186,7 @@ * Wrap std::apply for the case where we have an object method or a regular function. */ template - static typename args_info::return_type call(T* object, tuple& args) + static typename args_info::return_type call(T* object, tuple& args) { if constexpr(std::is_same_v) { @@ -269,10 +269,8 @@ template using ObjectGetter = T*(*)(const ScriptRequest&, JS::CallArgs&); - // TODO: the fact that this takes class and not auto is to work around an odd VS17 bug. - // It can be removed with VS19. - template - using GetterFor = ObjectGetter::object_type>; + template + using GetterFor = ObjectGetter::object_type>; /** * The meat of this file. This wraps a C++ function into a JSNative, @@ -287,16 +285,16 @@ * * @param thisGetter to get the object, if necessary. */ - template thisGetter = nullptr> + template thisGetter = nullptr> static bool ToJSNative(JSContext* cx, unsigned argc, JS::Value* vp) { - using ObjType = typename args_info::object_type; + using ObjType = typename args_info::object_type; JS::CallArgs args = JS::CallArgsFromVp(argc, vp); ScriptRequest rq(cx); // If the callable is an object method, we must specify how to fetch the object. - static_assert(std::is_same_v::object_type, void> || thisGetter != nullptr, + static_assert(std::is_same_v::object_type, void> || thisGetter != nullptr, "ScriptFunction::Register - No getter specified for object method"); // GCC 7 triggers spurious warnings @@ -316,7 +314,7 @@ #endif bool went_ok = true; - typename args_info::arg_types outs = ConvertFromJS(rq, args, went_ok, static_cast::arg_types*>(nullptr)); + typename args_info::arg_types outs = ConvertFromJS(rq, args, went_ok, static_cast::arg_types*>(nullptr)); if (!went_ok) return false; @@ -326,9 +324,9 @@ * For now we check for pending JS exceptions, but it would probably be nicer * to standardise on something, or perhaps provide an "errorHandler" here. */ - if constexpr (std::is_same_v::return_type>) + if constexpr (std::is_same_v::return_type>) call(obj, outs); - else if constexpr (std::is_same_v::return_type>) + else if constexpr (std::is_same_v::return_type>) args.rval().set(call(obj, outs)); else Script::ToJSVal(rq, args.rval(), call(obj, outs)); @@ -367,28 +365,28 @@ /** * Return a function spec from a C++ function. */ - template thisGetter = nullptr, u16 flags = JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT> + template thisGetter = nullptr, u16 flags = JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT> static JSFunctionSpec Wrap(const char* name) { - return JS_FN(name, (&ToJSNative), args_info::nb_args, flags); + return JS_FN(name, (&ToJSNative), args_info::nb_args, flags); } /** * Return a JSFunction from a C++ function. */ - template thisGetter = nullptr, u16 flags = JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT> + template thisGetter = nullptr, u16 flags = JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT> static JSFunction* Create(const ScriptRequest& rq, const char* name) { - return JS_NewFunction(rq.cx, &ToJSNative, args_info::nb_args, flags, name); + return JS_NewFunction(rq.cx, &ToJSNative, args_info::nb_args, flags, name); } /** * Register a function on the native scope (usually 'Engine'). */ - template thisGetter = nullptr, u16 flags = JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT> + template thisGetter = nullptr, u16 flags = JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT> static void Register(const ScriptRequest& rq, const char* name) { - JS_DefineFunction(rq.cx, rq.nativeScope, name, &ToJSNative, args_info::nb_args, flags); + JS_DefineFunction(rq.cx, rq.nativeScope, name, &ToJSNative, args_info::nb_args, flags); } /** @@ -396,10 +394,10 @@ * Prefer the version taking ScriptRequest unless you have a good reason not to. * @see Register */ - template thisGetter = nullptr, u16 flags = JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT> + template thisGetter = nullptr, u16 flags = JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT> static void Register(JSContext* cx, JS::HandleObject scope, const char* name) { - JS_DefineFunction(cx, scope, name, &ToJSNative, args_info::nb_args, flags); + JS_DefineFunction(cx, scope, name, &ToJSNative, args_info::nb_args, flags); } };