Compare commits

...

1 commit

Author SHA1 Message Date
f04b4a1f68 windows tests 2023-11-06 20:17:02 +01:00
8 changed files with 40 additions and 15 deletions

1
.gitignore vendored
View file

@ -43,3 +43,4 @@ src/-lstdc++.res
# Neural network for the NNUE evaluation
**/*.nnue
/.vs

View file

@ -73,6 +73,7 @@ class Stockfish {
}
},
onError: (error) {
print('The init isolate encountered an error $error');
developer.log('The init isolate encountered an error $error',
name: 'Stockfish');
_cleanUp(1);
@ -108,6 +109,8 @@ class Stockfish {
throw StateError('Stockfish is not ready ($stateValue)');
}
print("sending: " + line);
final unicodePointer = '$line\n'.toNativeUtf8();
final pointer = unicodePointer.cast<Char>();
_bindings.stockfish_stdin_write(pointer);
@ -210,6 +213,7 @@ Future<bool> _spawnIsolates(List<SendPort> mainAndStdout) async {
try {
await Isolate.spawn(_isolateStdout, mainAndStdout[1]);
} catch (error) {
print('Failed to spawn stdout isolate: $error');
developer.log('Failed to spawn stdout isolate: $error', name: 'Stockfish');
return false;
}
@ -217,6 +221,7 @@ Future<bool> _spawnIsolates(List<SendPort> mainAndStdout) async {
try {
await Isolate.spawn(_isolateMain, mainAndStdout[0]);
} catch (error) {
print('Failed to spawn stdout isolate: $error');
developer.log('Failed to spawn main isolate: $error', name: 'Stockfish');
return false;
}

View file

@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.18)
project(flutter_stockfish_plugin VERSION 0.0.1 LANGUAGES CXX)
file(GLOB_RECURSE cppPaths "Stockfish/src/*.cpp")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -flto")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O3 -flto") #-DNDEBUG -fno-exceptions -funroll-loops
set(NNUE_NAME nn-5af11540bbfe.nnue)
add_library(flutter_stockfish_plugin SHARED

View file

@ -105,7 +105,7 @@ struct Tie: public streambuf { // MSVC requires split streambuf for cin and cout
class Logger {
Logger() : in(cin.rdbuf(), file.rdbuf()), out(cout.rdbuf(), file.rdbuf()) {}
Logger() : in(fakein.rdbuf(), file.rdbuf()), out(fakeout.rdbuf(), file.rdbuf()) {}
~Logger() { start(""); }
ofstream file;
@ -118,9 +118,9 @@ public:
if (l.file.is_open())
{
cout.rdbuf(l.out.buf);
cin.rdbuf(l.in.buf);
l.file.close();
fakeout.rdbuf(l.out.buf);
fakein.rdbuf(l.in.buf);
l.file.close();
}
if (!fname.empty())
@ -133,8 +133,8 @@ public:
exit(EXIT_FAILURE);
}
cin.rdbuf(&l.in);
cout.rdbuf(&l.out);
fakein.rdbuf(&l.in);
fakeout.rdbuf(&l.out);
}
}
};
@ -753,10 +753,14 @@ void init([[maybe_unused]] int argc, char* argv[]) {
#ifdef _MSC_VER
// Under windows argv[0] may not have the extension. Also _get_pgmptr() had
// issues in some windows 10 versions, so check returned values carefully.
char* pgmptr = nullptr;
if (!_get_pgmptr(&pgmptr) && pgmptr != nullptr && *pgmptr)
argv0 = pgmptr;
#endif
wchar_t buffer[MAX_PATH];
if (GetModuleFileNameW(nullptr, buffer, MAX_PATH) != 0)
{
char narrowBuffer[MAX_PATH];
WideCharToMultiByte(CP_UTF8, 0, buffer, -1, narrowBuffer, MAX_PATH, NULL, NULL);
argv0 = narrowBuffer;
}
#endif
#else
pathSeparator = "/";
#endif

View file

@ -70,7 +70,6 @@ std::ostream& operator<<(std::ostream&, SyncCout);
#define sync_cout fakeout << IO_LOCK
#define sync_endl fakeendl << IO_UNLOCK
// align_ptr_up() : get the first aligned element of an array.
// ptr must point to an array of size at least `sizeof(T) * N + alignment` bytes,
// where N is the number of elements in the array.

View file

@ -33,7 +33,7 @@ int stockfish_main() {
char *argv[] = {(char *)""};
int exitCode = main(argc, argv);
fakeout << QUITOK << "\n";
fakeout << exitCode << "\n";
#if _WIN32
Sleep(100);
@ -49,6 +49,7 @@ int stockfish_main() {
ssize_t stockfish_stdin_write(char *data) {
std::string val(data);
fakeout << val << fakeendl;
fakein << val << fakeendl;
return val.length();
}

View file

@ -1,6 +1,7 @@
#include "stream_fix.h"
bool FakeStream::try_get_line(std::string& val) {
bool FakeStream::try_get_line(std::string &val)
{
std::unique_lock<std::mutex> lock(mutex_guard);
if (string_queue.empty() || closed) return false;
val = string_queue.front();
@ -26,6 +27,17 @@ bool std::getline(FakeStream& is, std::string& str) {
return true;
}
/*FakeStream &operator<<(FakeStream &os, SyncFakeout sc) {
static std::mutex m;
if (sc == SyncFakeout::IO_LOCK)
m.lock();
if (sc == SyncFakeout::IO_UNLOCK)
m.unlock();
return os;
}*/
FakeStream fakeout;
FakeStream fakein;
std::string fakeendl("\n");

View file

@ -8,7 +8,7 @@
template <typename T>
inline std::string stringify(const T& input) {
std::ostringstream output; // from www .ja va 2s . com
std::ostringstream output;
output << input;
return output.str();
}
@ -55,6 +55,9 @@ namespace std {
bool getline(FakeStream& is, std::string& str);
} // namespace std
//enum SyncFakeout { IO_LOCK, IO_UNLOCK };
//FakeStream &operator<<(FakeStream &os, SyncFakeout sc);
// #define endl fakeendl
// #define cout fakeout
// #define cin fakein