From 8c1404cd360afdaba0b47685c1d482ba3356dbb1 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Thu, 9 Jun 2011 09:48:26 +0200 Subject: [PATCH] version 1.4w10UCIb21 --- ChangeLog | 3 + config.h | 6 +- configure | 20 +++++----- configure.ac | 2 +- main.cpp | 2 +- pipe.cpp | 120 ++++++++++++++++++++++++++++----------------------------- pipe.h | 4 +- polyglot.spec | 2 +- uci.cpp | 2 + 9 files changed, 82 insertions(+), 79 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9b3b5ae..a2b7dfa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +=========1.4w10UCIb21=========== +- Crash bug in memory command fixed +- Small optimizations =========1.4w10UCIb20=========== - More refactoring. - No more polling for GUI input diff --git a/config.h b/config.h index 9c350da..4c57eae 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.4w10UCIb20" +#define PACKAGE_STRING "polyglot 1.4w10UCIb21" /* 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.4w10UCIb20" +#define PACKAGE_VERSION "1.4w10UCIb21" /* 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.4w10UCIb20" +#define VERSION "1.4w10UCIb21" /* Define like PROTOTYPES; this can be used by system headers. */ #define __PROTOTYPES 1 diff --git a/configure b/configure index e1418c0..eb74a04 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.4w10UCIb20. +# Generated by GNU Autoconf 2.61 for polyglot 1.4w10UCIb21. # # 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.4w10UCIb20' -PACKAGE_STRING='polyglot 1.4w10UCIb20' +PACKAGE_VERSION='1.4w10UCIb21' +PACKAGE_STRING='polyglot 1.4w10UCIb21' 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.4w10UCIb20 to adapt to many kinds of systems. +\`configure' configures polyglot 1.4w10UCIb21 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.4w10UCIb20:";; + short | recursive ) echo "Configuration of polyglot 1.4w10UCIb21:";; 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.4w10UCIb20 +polyglot configure 1.4w10UCIb21 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.4w10UCIb20, which was +It was created by polyglot $as_me 1.4w10UCIb21, 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.4w10UCIb20' + VERSION='1.4w10UCIb21' 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.4w10UCIb20, which was +This file was extended by polyglot $as_me 1.4w10UCIb21, 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.4w10UCIb20 +polyglot config.status 1.4w10UCIb21 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 998aef2..409e38d 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.4w10UCIb20], [michel.vandenbergh@uhasselt.be]) +AC_INIT([polyglot], [1.4w10UCIb21], [michel.vandenbergh@uhasselt.be]) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([mainloop.cpp]) AC_CONFIG_HEADER([config.h]) diff --git a/main.cpp b/main.cpp index a4835c9..07a02e1 100644 --- a/main.cpp +++ b/main.cpp @@ -35,7 +35,7 @@ // constants -static const char * const Version = "1.4W10UCIb20"; +static const char * const Version = "1.4W10UCIb21"; static const char * const HelpMessage = "\ SYNTAX\n\ * polyglot [configfile]\n\ diff --git a/pipe.cpp b/pipe.cpp index 163e591..7f868bd 100644 --- a/pipe.cpp +++ b/pipe.cpp @@ -68,6 +68,7 @@ void PipeStruct::Open(const char *szProcFile) { FlushConsoleInputBuffer(hInput); } nReadEnd = 0; + lpFeedEnd = NULL; InitializeCriticalSection(&CriticalSection); hEvent=CreateEvent(NULL, // default security FALSE, // auto reset @@ -131,72 +132,62 @@ void PipeStruct::set_Active(void){ LeaveCriticalSection(&CriticalSection); } - - -int PipeStruct::ReadLine(void){ +int PipeStruct::ReadData(void){ DWORD dwBytes; int ret; - int start=0; - int start1; if(!bPipe){ fgets(lpReadBuffer,LINE_INPUT_MAX_CHAR,stdin); - start=strlen(lpReadBuffer); - if(!start){ + dwBytes=strlen(lpReadBuffer); + if(!dwBytes){ set_EOF_(); lpReadBuffer[0]='\0'; + return 0; } - return start; }else{ + // Unfortunately we need to use polling here. + // Otherwise Windows returns single bytes if + // the engine runs at low priority. + // This kills performance. while(TRUE){ - // Unfortunately we need to use polling here. - // Otherwise Windows returns single bytes if - // the engine runs at low priority. - // This kills performance. - while(TRUE){ - ret=PeekNamedPipe(hInput, - NULL, // don't read anything yet - 0, // no buffer - NULL, // no we don't read anything! - &dwBytes,// now we're talking - NULL); // nono we don't read anything - if(!ret){ - set_EOF_(); - lpReadBuffer[0]='\0'; - return 0; - } - if(dwBytes>0){ - break; - }else{ - Idle(); - } - - } - ret=ReadFile(hInput, - lpReadBuffer+start, - LINE_INPUT_MAX_CHAR-start, - &dwBytes, - NULL); + ret=PeekNamedPipe(hInput, + NULL, // don't read anything yet + 0, // no buffer + NULL, // no we don't read anything! + &dwBytes,// now we're talking + NULL); // nono we don't read anything if(!ret){ set_EOF_(); lpReadBuffer[0]='\0'; return 0; + } + if(dwBytes>0){ + break; }else{ - start1=start; - start+=dwBytes; - if (memchr(lpReadBuffer+start1, '\n', dwBytes)){ - lpReadBuffer[start]='\0'; - return start; - } + Idle(); } + + } + ret=ReadFile(hInput, + lpReadBuffer, + LINE_INPUT_MAX_CHAR, + &dwBytes, + NULL); + if(!ret){ + set_EOF_(); + lpReadBuffer[0]='\0'; + return 0; } } + lpReadBuffer[dwBytes]='\0'; + return dwBytes; } void PipeStruct::ReadInput(void) { DWORD dwBytes; int ret; - ret=ReadLine(); + BOOL bSetEvent=FALSE; + ret=ReadData(); EnterCriticalSection(&CriticalSection); if(!EOF_()){ if(ret+nReadEnd>=LINE_INPUT_MAX_CHAR){ @@ -204,33 +195,23 @@ void PipeStruct::ReadInput(void) { } memcpy(lpBuffer+nReadEnd,lpReadBuffer,ret); nReadEnd += ret; + if(!lpFeedEnd){ + lpFeedEnd = (char *) memchr(lpBuffer, '\n', nReadEnd); + } + if(lpFeedEnd){ + bSetEvent=TRUE; + } } LeaveCriticalSection(&CriticalSection); - SetEvent(hEvent); -} - -void PipeStruct::LineOutput(const char *szLineStr) const { - DWORD dwBytes; - int nStrLen; - char szWriteBuffer[LINE_INPUT_MAX_CHAR]; - if(bPipe){ - nStrLen = strlen(szLineStr); - memcpy(szWriteBuffer, szLineStr, nStrLen); - szWriteBuffer[nStrLen] = '\r'; - szWriteBuffer[nStrLen + 1] = '\n'; - WriteFile(hOutput, szWriteBuffer, nStrLen + 2, &dwBytes, NULL); - }else{ - printf("%s\n",szLineStr); - fflush(stdout); + if(EOF_() || bSetEvent){ + SetEvent(hEvent); } } bool PipeStruct::GetBuffer(char *szLineStr) { - char *lpFeedEnd; int nFeedEnd; int ret; EnterCriticalSection(&CriticalSection); - lpFeedEnd = (char *) memchr(lpBuffer, '\n', nReadEnd); if (lpFeedEnd == NULL) { ret=FALSE; } else { @@ -244,6 +225,7 @@ bool PipeStruct::GetBuffer(char *szLineStr) { nFeedEnd ++; nReadEnd -= nFeedEnd; memcpy(lpBuffer, lpBuffer + nFeedEnd, nReadEnd); + lpFeedEnd = (char *) memchr(lpBuffer, '\n', nReadEnd); ret=TRUE; } LeaveCriticalSection(&CriticalSection); @@ -259,4 +241,20 @@ void PipeStruct::LineInput(char *szLineStr) { } } } + +void PipeStruct::LineOutput(const char *szLineStr) const { + DWORD dwBytes; + int nStrLen; + char szWriteBuffer[LINE_INPUT_MAX_CHAR]; + if(bPipe){ + nStrLen = strlen(szLineStr); + memcpy(szWriteBuffer, szLineStr, nStrLen); + szWriteBuffer[nStrLen] = '\r'; + szWriteBuffer[nStrLen + 1] = '\n'; + WriteFile(hOutput, szWriteBuffer, nStrLen + 2, &dwBytes, NULL); + }else{ + printf("%s\n",szLineStr); + fflush(stdout); + } +} #endif diff --git a/pipe.h b/pipe.h index eecfb1c..e90a4db 100644 --- a/pipe.h +++ b/pipe.h @@ -28,6 +28,7 @@ struct PipeStruct { CRITICAL_SECTION CriticalSection; volatile DWORD state; + volatile char * lpFeedEnd; volatile int nReadEnd; char lpBuffer[LINE_INPUT_MAX_CHAR]; char lpReadBuffer[LINE_INPUT_MAX_CHAR]; @@ -40,8 +41,7 @@ struct PipeStruct { bool Active(void); void set_Active(void); void ReadInput(void); - int ReadLine(void); - bool CheckInput(void); + int ReadData(void); bool GetBuffer(char *szLineStr); void LineInput(char *szLineStr); void LineOutput(const char *szLineStr) const; diff --git a/polyglot.spec b/polyglot.spec index ae0d193..f3a7944 100644 --- a/polyglot.spec +++ b/polyglot.spec @@ -1,6 +1,6 @@ Summary: A Winboard protocol to UCI protocol adapter Name: polyglot -Version: 1.4w10UCIb20 +Version: 1.4w10UCIb21 Release: 1 License: GPL Group: Amusement/Games diff --git a/uci.cpp b/uci.cpp index d7f63b4..35b84de 100644 --- a/uci.cpp +++ b/uci.cpp @@ -805,6 +805,7 @@ static void parse_option(uci_t * uci, const char string[]) { uci->option_nb++; opt->value=NULL; + my_string_set(&opt->value,""); opt->mode=0; opt->name = NULL; @@ -847,6 +848,7 @@ static void parse_option(uci_t * uci, const char string[]) { if (!my_string_empty(argument)) { my_string_set(&opt->default_,argument); + my_string_set(&opt->value,argument); } } else if (my_string_equal(option,"max")) { -- 1.7.0.4