From 07265afaa167049a447b4c5f43e5ef90c7451a49 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Thu, 9 Jun 2011 09:50:06 +0200 Subject: [PATCH] version 1.4w10UCIb24 --- ChangeLog | 5 ++++ README | 10 +++++--- config.h | 6 ++-- configure | 20 +++++++++--------- configure.ac | 2 +- engine.cpp | 24 ++++++++++++---------- epd.cpp | 2 +- main.cpp | 2 +- makefile.gcc | 31 ++++++++++++++++++++++++--- option.cpp | 61 ++++++++++++++++++++++++++++--------------------------- pipe.cpp | 38 ++++++++++++++++++++++++---------- pipe.h | 4 ++- polyglot.man | 9 ++++--- polyglot.pod | 8 +++--- polyglot.spec | 2 +- xboard2uci.cpp | 2 +- 16 files changed, 139 insertions(+), 87 deletions(-) diff --git a/ChangeLog b/ChangeLog index b1562e2..1ce2f42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +=========1.4w10UCIb24=========== +- Portability fixes for WIN9X (Eric Mullins). +- Portability fixes for MSVC++ (Eric Mullins). +- Default setting of RepeatPV is now true. +- Do not read data if input buffer is full (Windows). =========1.4w10UCIb22=========== - Polyglot now completely poll free... =========1.4w10UCIb21=========== diff --git a/README b/README index 58c4006..7af6caf 100644 --- a/README +++ b/README @@ -427,9 +427,11 @@ CONFIG FILE FORMAT RepeatPV (default: true) When true, PolyGlot repeats the last pv string (which also contains score,depth and time usage) it got from the engine. Some engines - however do not send a new pv string just before sending the move - and the now old pv string might confuse debugtools that parse the - winboard debug files. + however do not send a new pv string just before sending the move. + In that case the output of PolyGlot would be inconsistent. When + RepeatPV is false PolyGlot does not repeat the last pv string. Due + to the way kibitzing is implemented, KibitzMove is disabled in that + case. [Engine] section @@ -503,4 +505,4 @@ SEE ALSO - 2009-01-16 POLYGLOT(6) + 2009-07-20 POLYGLOT(6) diff --git a/config.h b/config.h index f602e78..17b64ef 100644 --- a/config.h +++ b/config.h @@ -115,13 +115,13 @@ #define PACKAGE_NAME "polyglot" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "polyglot 1.4w10UCIb22" +#define PACKAGE_STRING "polyglot 1.4w10UCIb24" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "polyglot" /* Define to the version of this package. */ -#define PACKAGE_VERSION "1.4w10UCIb22" +#define PACKAGE_VERSION "1.4w10UCIb24" /* Define to 1 if the C compiler supports function prototypes. */ #define PROTOTYPES 1 @@ -150,7 +150,7 @@ #define TIME_WITH_SYS_TIME 1 /* Version number of package */ -#define VERSION "1.4w10UCIb22" +#define VERSION "1.4w10UCIb24" /* Define like PROTOTYPES; this can be used by system headers. */ #define __PROTOTYPES 1 diff --git a/configure b/configure index ebfd2d0..16d6bb9 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.61 for polyglot 1.4w10UCIb22. +# Generated by GNU Autoconf 2.61 for polyglot 1.4w10UCIb24. # # Report bugs to . # @@ -574,8 +574,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='polyglot' PACKAGE_TARNAME='polyglot' -PACKAGE_VERSION='1.4w10UCIb22' -PACKAGE_STRING='polyglot 1.4w10UCIb22' +PACKAGE_VERSION='1.4w10UCIb24' +PACKAGE_STRING='polyglot 1.4w10UCIb24' PACKAGE_BUGREPORT='michel.vandenbergh@uhasselt.be' ac_unique_file="mainloop.cpp" @@ -1216,7 +1216,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures polyglot 1.4w10UCIb22 to adapt to many kinds of systems. +\`configure' configures polyglot 1.4w10UCIb24 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1282,7 +1282,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of polyglot 1.4w10UCIb22:";; + short | recursive ) echo "Configuration of polyglot 1.4w10UCIb24:";; esac cat <<\_ACEOF @@ -1368,7 +1368,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -polyglot configure 1.4w10UCIb22 +polyglot configure 1.4w10UCIb24 generated by GNU Autoconf 2.61 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, @@ -1382,7 +1382,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by polyglot $as_me 1.4w10UCIb22, which was +It was created by polyglot $as_me 1.4w10UCIb24, which was generated by GNU Autoconf 2.61. Invocation command line was $ $0 $@ @@ -2072,7 +2072,7 @@ fi # Define the identity of the package. PACKAGE='polyglot' - VERSION='1.4w10UCIb22' + VERSION='1.4w10UCIb24' cat >>confdefs.h <<_ACEOF @@ -7344,7 +7344,7 @@ exec 6>&1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by polyglot $as_me 1.4w10UCIb22, which was +This file was extended by polyglot $as_me 1.4w10UCIb24, which was generated by GNU Autoconf 2.61. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -7397,7 +7397,7 @@ Report bugs to ." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -polyglot config.status 1.4w10UCIb22 +polyglot config.status 1.4w10UCIb24 configured by $0, generated by GNU Autoconf 2.61, with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" diff --git a/configure.ac b/configure.ac index 2875e95..3e195b8 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.61) -AC_INIT([polyglot], [1.4w10UCIb22], [michel.vandenbergh@uhasselt.be]) +AC_INIT([polyglot], [1.4w10UCIb24], [michel.vandenbergh@uhasselt.be]) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([mainloop.cpp]) AC_CONFIG_HEADER([config.h]) diff --git a/engine.cpp b/engine.cpp index f5c53c6..b6c0f4b 100644 --- a/engine.cpp +++ b/engine.cpp @@ -321,6 +321,19 @@ engine_t Engine[1]; // functions +void set_affinity(engine_t *engine, int affin){ + if(affin==-1) return; + { typedef void (WINAPI *SPAM)(HANDLE, int); + SPAM pSPAM; + + pSPAM = (SPAM) GetProcAddress( + GetModuleHandle(TEXT("kernel32.dll")), + "SetProcessAffinityMask"); + if(NULL != pSPAM) // [HGM] avoid crash on Win95 by first checking if API call exists + pSPAM((engine->io).hProcess,affin); + } +} + DWORD GetWin32Priority(int nice) { /* @@ -338,21 +351,11 @@ IDLE_PRIORITY_CLASS 0x00000040 return 0x00000040; } - - -void set_affinity(engine_t *engine, int affin){ - if(affin==-1) return; - SetProcessAffinityMask((engine->io).hProcess,affin); -} - -// Eric Mullins! - void engine_set_nice_value(engine_t *engine, int value){ SetPriorityClass((engine->io).hProcess, GetWin32Priority(value)); } - void engine_send_queue(engine_t * engine,const char *szFormat, ...) { nQueuePtr += vsprintf(szQueueString + nQueuePtr, szFormat, (va_list) (&szFormat + 1)); } @@ -375,7 +378,6 @@ void engine_close(engine_t * engine){ (engine->io).Kill(); } - void engine_open(engine_t * engine){ int affinity; char *my_dir; diff --git a/epd.cpp b/epd.cpp index 75a229c..fab728a 100644 --- a/epd.cpp +++ b/epd.cpp @@ -282,7 +282,7 @@ static void epd_test_file(const char file_name[]) { if (correct) { depth_tot += double(FirstDepth); time_tot += FirstTime; - node_tot += double(FirstNodeNb); + node_tot += double(sint64(FirstNodeNb)); } printf("%2d: %-15s %s %4d",tot,id,correct?"OK":"--",hit); diff --git a/main.cpp b/main.cpp index 64ee304..a54aefe 100644 --- a/main.cpp +++ b/main.cpp @@ -35,7 +35,7 @@ // constants -static const char * const Version = "1.4W10UCIb22"; +static const char * const Version = "1.4W10UCIb24"; static const char * const HelpMessage = "\ SYNTAX\n\ * polyglot [configfile]\n\ diff --git a/makefile.gcc b/makefile.gcc index 5e18172..56ced5f 100644 --- a/makefile.gcc +++ b/makefile.gcc @@ -1,6 +1,29 @@ -# what's this?? -# This is not a makefile.... +EXE = polyglot.exe -# Anyway here is the command for compiling polyglot under Mingw/Cygwin +OBJS = attack.o board.o book.o book_make.o book_merge.o colour.o engine.o\ + epd.o fen.o game.o gui.o hash.o io.o line.o list.o main.o mainloop.o\ + move.o move_do.o move_gen.o move_legal.o option.o parse.o pgn.o piece.o\ + pipe.o posix.o random.o san.o search.o square.o uci.o uci2uci.o util.o\ + xboard2uci.o -g++ -O2 -mno-cygwin -D_WIN32 *.cpp -opolyglot +# set up for NO cygwin +CYGF = -mno-cygwin +CYGL = -lmsvcrt + +CC = g++ +DEFS = -DNDEBUG +OPTS = -Os -frename-registers -funit-at-a-time -fstrict-aliasing -fstrength-reduce +CFLAGS = -Wall -pipe $(DEFS) $(OPTS) $(CYGF) +LFLAGS = -fpic -s $(CYGF) +LIBS = $(CYGL) + +all: $(EXE) + +clean: + rm -rf $(OBJS) $(EXE) + +$(EXE): $(OBJS) + $(CC) $(LFLAGS) $(LIBS) $(OBJS) -o $(EXE) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< diff --git a/option.cpp b/option.cpp index 5cb5024..979b715 100644 --- a/option.cpp +++ b/option.cpp @@ -16,56 +16,57 @@ static const bool UseDebug = false; // variables +#define NNB { NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL } option_t Option[] = { - { "OptionFile", "string","0","0", "polyglot.ini", NULL,0,{}, PG}, + { "OptionFile", "string","0","0", "polyglot.ini", NULL,0,NNB, PG}, // options - { "EngineName", "string","0","0", "" , NULL,0,{}, PG}, - { "EngineDir", "string","0","0", "." , NULL,0,{}, PG}, - { "EngineCommand", "string","0","0", "" , NULL,0,{}, PG}, + { "EngineName", "string","0","0", "" , NULL,0,NNB, PG}, + { "EngineDir", "string","0","0", "." , NULL,0,NNB, PG}, + { "EngineCommand", "string","0","0", "" , NULL,0,NNB, PG}, - { "Log", "check","0","0", "false" , NULL,0,{}, PG|XBOARD|UCI}, - { "LogFile", "string","0","0", "polyglot.log", NULL,0,{}, PG|XBOARD|UCI}, + { "Log", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD|UCI}, + { "LogFile", "string","0","0", "polyglot.log", NULL,0,NNB, PG|XBOARD|UCI}, - { "UCI", "string","0","0", "false" , NULL,0,{}, PG}, + { "UCI", "string","0","0", "false" , NULL,0,NNB, PG}, - { "UseNice", "check","0","0", "false" , NULL,0,{}, PG|XBOARD|UCI}, - { "NiceValue", "spin", "0","20", "5" , NULL,0,{}, PG|XBOARD|UCI}, + { "UseNice", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD|UCI}, + { "NiceValue", "spin", "0","20", "5" , NULL,0,NNB, PG|XBOARD|UCI}, - { "Chess960", "check","0","0", "false" , NULL,0,{}, PG|XBOARD}, + { "Chess960", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD}, - { "Resign", "check","0","0", "false" , NULL,0,{}, PG|XBOARD}, - { "ResignMoves", "spin","0","10000", "3" , NULL,0,{}, PG|XBOARD}, - { "ResignScore", "spin","0","10000", "600" , NULL,0,{}, PG|XBOARD}, + { "Resign", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD}, + { "ResignMoves", "spin","0","10000", "3" , NULL,0,NNB, PG|XBOARD}, + { "ResignScore", "spin","0","10000", "600" , NULL,0,NNB, PG|XBOARD}, - { "MateScore", "spin","0","1000000", "10000" , NULL,0,{}, PG|XBOARD}, + { "MateScore", "spin","0","1000000", "10000" , NULL,0,NNB, PG|XBOARD}, - { "Book", "check","0","0", "false" , NULL,0,{}, PG|XBOARD|UCI}, - { "BookFile", "string","0","0", "book.bin" , NULL,0,{}, PG|XBOARD|UCI}, + { "Book", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD|UCI}, + { "BookFile", "string","0","0", "book.bin" , NULL,0,NNB, PG|XBOARD|UCI}, - { "BookRandom", "check","0","0", "true" , NULL,0,{}, PG|XBOARD|UCI}, - { "BookLearn", "check","0","0", "false" , NULL,0,{}, PG|XBOARD}, + { "BookRandom", "check","0","0", "true" , NULL,0,NNB, PG|XBOARD|UCI}, + { "BookLearn", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD}, - { "KibitzMove", "check","0","0", "false" , NULL,0,{}, PG|XBOARD}, - { "KibitzPV", "check","0","0", "false" , NULL,0,{}, PG|XBOARD}, + { "KibitzMove", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD}, + { "KibitzPV", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD}, - { "KibitzCommand", "string","0","0", "tellall" , NULL,0,{}, PG|XBOARD}, - { "KibitzDelay", "check","0","10000", "5" , NULL,0,{}, PG|XBOARD}, + { "KibitzCommand", "string","0","0", "tellall" , NULL,0,NNB, PG|XBOARD}, + { "KibitzDelay", "check","0","10000", "5" , NULL,0,NNB, PG|XBOARD}, - { "ShowPonder", "check","0","0", "false" , NULL,0,{}, PG|XBOARD}, + { "ShowPonder", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD}, // work-arounds - { "UCIVersion", "spin","1","2", "2" , NULL,0,{}, PG|XBOARD}, - { "CanPonder", "check","1","2", "false" , NULL,0,{}, PG|XBOARD}, - { "SyncStop", "check","1","2", "false" , NULL,0,{}, PG|XBOARD}, - { "Affinity", "spin","-1","32", "-1" , NULL,0,{}, PG}, - { "RepeatPV", "check","0","0", "false" , NULL,0,{}, PG|XBOARD}, - { "PromoteWorkAround","check","0","0", "false" , NULL,0,{}, PG|XBOARD}, + { "UCIVersion", "spin","1","2", "2" , NULL,0,NNB, PG|XBOARD}, + { "CanPonder", "check","1","2", "false" , NULL,0,NNB, PG|XBOARD}, + { "SyncStop", "check","1","2", "false" , NULL,0,NNB, PG|XBOARD}, + { "Affinity", "spin","-1","32", "-1" , NULL,0,NNB, PG}, + { "RepeatPV", "check","0","0", "true" , NULL,0,NNB, PG|XBOARD}, + { "PromoteWorkAround","check","0","0", "false" , NULL,0,NNB, PG|XBOARD}, - { NULL, NULL,"0","0", NULL , NULL,0,{}, 0}, + { NULL, NULL,"0","0", NULL , NULL,0,NNB, 0}, }; // prototypes diff --git a/pipe.cpp b/pipe.cpp index 5d07844..48f0c72 100644 --- a/pipe.cpp +++ b/pipe.cpp @@ -4,10 +4,15 @@ // functions -DWORD WINAPI ThreadProc(LPVOID lpParam){ +DWORD WINAPI ThreadProc(LPVOID lpParam){ PipeStruct *p=(PipeStruct *) lpParam; while(!p->EOF_()){ - p->ReadInput(); + if(p->nReadEndReadInput(); + }else{ + // wait until there is room in buffer + Sleep(10); + } } return 0; } @@ -15,7 +20,7 @@ DWORD WINAPI ThreadProc(LPVOID lpParam){ void PipeStruct::Open(const char *szProcFile) { - DWORD dwMode; + DWORD dwMode, dwThreadId; HANDLE hStdinRead, hStdinWrite, hStdoutRead, hStdoutWrite; SECURITY_ATTRIBUTES sa; STARTUPINFO si; @@ -68,7 +73,7 @@ void PipeStruct::Open(const char *szProcFile) { dwMode & ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT)); FlushConsoleInputBuffer(hInput); } - fdInput=_open_osfhandle((intptr_t) hInput,_O_RDONLY); + fdInput=_open_osfhandle((long) hInput,_O_RDONLY); if(fdInput==-1){ my_fatal("PipeStruct::Open(): %s",my_error()); } @@ -84,14 +89,19 @@ void PipeStruct::Open(const char *szProcFile) { FALSE, // not signaled NULL // nameless ); + if(!hEvent){ + my_fatal("PipeStruct::Open(): %s",my_error()); + } hThread=CreateThread(NULL, // default security 0, // default stacksize ThreadProc, // worker function this, // tell worker about ourselves 0, // run immediately - NULL // nameless + &dwThreadId // dropped, but needed for the call to work in Win9x ); - + if(!hThread){ + my_fatal("PipeStruct::Open(): %s",my_error()); + } set_Active(); } @@ -144,14 +154,16 @@ void PipeStruct::set_Active(void){ int PipeStruct::ReadData(void){ DWORD dwBytes; char * ret; - - ret=fgets(lpReadBuffer,LINE_INPUT_MAX_CHAR,fpInput); - dwBytes=strlen(lpReadBuffer); + // No protection. Access to nReadEnd is atomic. + // It is not a problem that nReadEnd becomes smaller after the call. + // This just means we have read less than we could have. + ret=fgets(lpReadBuffer,LINE_INPUT_MAX_CHAR-nReadEnd,fpInput); if(!ret){ set_EOF_(); lpReadBuffer[0]='\0'; return 0; } + dwBytes=strlen(lpReadBuffer); lpReadBuffer[dwBytes]='\0'; return dwBytes; } @@ -160,19 +172,23 @@ void PipeStruct::ReadInput(void) { DWORD dwBytes; int ret; BOOL bSetEvent=FALSE; + // ReadData is outside the critical section otherwise everything + // would block during the blocking read ret=ReadData(); EnterCriticalSection(&CriticalSection); if(!EOF_()){ if(ret+nReadEnd>=LINE_INPUT_MAX_CHAR){ - my_fatal("PipeStruct::ReadInput(): buffer overflow\n"); + my_fatal("PipeStruct::ReadInput(): Internal error: buffer overflow\n"); } - memcpy(lpBuffer+nReadEnd,lpReadBuffer,ret); + memcpy(lpBuffer+nReadEnd,lpReadBuffer,ret+1); nReadEnd += ret; if(!lpFeedEnd){ lpFeedEnd = (char *) memchr(lpBuffer, '\n', nReadEnd); } if(lpFeedEnd){ bSetEvent=TRUE; + }else if(nReadEnd>=LINE_INPUT_MAX_CHAR-1){ + my_fatal("PipeStruct::ReadInput(): LINE_INPUT_MAX_CHAR is equal to %d which is too small to contain a full line of engine output or GUI input.\n",LINE_INPUT_MAX_CHAR); } } LeaveCriticalSection(&CriticalSection); diff --git a/pipe.h b/pipe.h index a8b086b..ad01c18 100644 --- a/pipe.h +++ b/pipe.h @@ -10,7 +10,9 @@ // constants -const int LINE_INPUT_MAX_CHAR = 10*4096; +// This should be bigger than the maximum length of an engine output or GUI +// input line. +const int LINE_INPUT_MAX_CHAR = 40960; // defines diff --git a/polyglot.man b/polyglot.man index 4dda26b..e97f815 100644 --- a/polyglot.man +++ b/polyglot.man @@ -129,7 +129,7 @@ .\" ======================================================================== .\" .IX Title "POLYGLOT 6" -.TH POLYGLOT 6 "2009-01-16" "" "" +.TH POLYGLOT 6 "2009-07-20" "" "" .SH "NAME" PolyGlot \- Winboard protocol to UCI protocol adapter \- book engine for Polyglot books @@ -542,9 +542,10 @@ incorrect form (and of course promotes into a queen). .IX Item "RepeatPV (default: true)" When true, PolyGlot repeats the last pv string (which also contains score,depth and time usage) it got from the engine. Some engines -however do not send a new pv string just before sending the move and -the now old pv string might confuse debugtools that parse the winboard -debug files. +however do not send a new pv string just before sending the move. +In that case the output of PolyGlot would be inconsistent. +When RepeatPV is false PolyGlot does not repeat the last pv string. +Due to the way kibitzing is implemented, KibitzMove is disabled in that case. .Sh "[Engine] section" .IX Subsection "[Engine] section" This section contains engine \s-1UCI\s0 options. PolyGlot does not diff --git a/polyglot.pod b/polyglot.pod index 71fd17c..be5d260 100644 --- a/polyglot.pod +++ b/polyglot.pod @@ -506,10 +506,10 @@ incorrect form (and of course promotes into a queen). When true, PolyGlot repeats the last pv string (which also contains score,depth and time usage) it got from the engine. Some engines -however do not send a new pv string just before sending the move and -the now old pv string might confuse debugtools that parse the winboard -debug files. - +however do not send a new pv string just before sending the move. +In that case the output of PolyGlot would be inconsistent. +When RepeatPV is false PolyGlot does not repeat the last pv string. +Due to the way kibitzing is implemented, KibitzMove is disabled in that case. =back diff --git a/polyglot.spec b/polyglot.spec index 8ccf2f1..851557d 100644 --- a/polyglot.spec +++ b/polyglot.spec @@ -1,6 +1,6 @@ Summary: A Winboard protocol to UCI protocol adapter Name: polyglot -Version: 1.4w10UCIb22 +Version: 1.4w10UCIb24 Release: 1 License: GPL Group: Amusement/Games diff --git a/xboard2uci.cpp b/xboard2uci.cpp index 687d632..72e81e4 100644 --- a/xboard2uci.cpp +++ b/xboard2uci.cpp @@ -839,7 +839,7 @@ static void comp_move(int move) { ASSERT(State->state==THINK); ASSERT(!XB->analyse); - if(option_get_bool("RepeatPV")==true) + if(option_get_bool("RepeatPV")) send_pv(); // to update time and nodes // send the move -- 1.7.0.4