From 90975d261c7ab39186c75d8700261faab3427de7 Mon Sep 17 00:00:00 2001 From: "phil@softsynth.com" Date: Mon, 23 Aug 2010 21:32:46 +0000 Subject: [PATCH] Fix REPOSITION-FILE, HISTORY, locked file handle and other problems. --- build/unix/Makefile | 4 +++- csrc/pf_core.c | 3 +-- csrc/pf_guts.h | 2 +- csrc/pf_inner.c | 3 +-- csrc/pf_save.c | 51 ++++++++++++++++++++++++++------------------- csrc/pfcompil.c | 5 ++++- fth/floats.fth | 23 ++++++++++++-------- fth/history.fth | 8 +++++-- fth/system.fth | 4 +--- releases.txt | 7 ++++++- 10 files changed, 67 insertions(+), 43 deletions(-) diff --git a/build/unix/Makefile b/build/unix/Makefile index de0b90f..8896f7c 100644 --- a/build/unix/Makefile +++ b/build/unix/Makefile @@ -4,7 +4,7 @@ # For more info visit http://www.softsynth.com/pforth/ # # See "help" target below. - + .SUFFIXES: .c .o # Options include: PF_SUPPORT_FP PF_NO_MALLOC PF_NO_INIT PF_DEBUG @@ -124,3 +124,5 @@ clean: rm -f $(PFDICDAT) rm -f $(PFORTHDIC) rm -f $(PFDICAPP) + rm -rf $(OBJECTDIR) $(TEMPOBJECTDIR) + diff --git a/csrc/pf_core.c b/csrc/pf_core.c index 41fa5f7..0564a65 100644 --- a/csrc/pf_core.c +++ b/csrc/pf_core.c @@ -371,12 +371,11 @@ cell_t pfIncludeFile( const char *FileName ) pfCopyMemory( &buffer[4], &FileName[len-numChars], numChars+1 ); CreateDicEntryC( ID_NOOP, buffer, 0 ); - Result = ffIncludeFile( fid ); + Result = ffIncludeFile( fid ); /* Also close the file. */ /* Create a dictionary word named ;;;; for FILE? */ CreateDicEntryC( ID_NOOP, ";;;;", 0 ); - sdCloseFile(fid); return Result; } diff --git a/csrc/pf_guts.h b/csrc/pf_guts.h index 0666108..acb92a6 100644 --- a/csrc/pf_guts.h +++ b/csrc/pf_guts.h @@ -23,7 +23,7 @@ ** PFORTH_VERSION changes when PForth is modified and released. ** See README file for version info. */ -#define PFORTH_VERSION "26" +#define PFORTH_VERSION "27" /* ** PFORTH_FILE_VERSION changes when incompatible changes are made diff --git a/csrc/pf_inner.c b/csrc/pf_inner.c index 59ddfff..0149da0 100644 --- a/csrc/pf_inner.c +++ b/csrc/pf_inner.c @@ -1289,9 +1289,8 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); if( FileID ) { SAVE_REGISTERS; - Scratch = ffIncludeFile( FileID ); + Scratch = ffIncludeFile( FileID ); /* Also closes the file. */ LOAD_REGISTERS; - sdCloseFile( FileID ); if( Scratch ) M_THROW(Scratch); } else diff --git a/csrc/pf_save.c b/csrc/pf_save.c index 128b474..f3f9ac0 100644 --- a/csrc/pf_save.c +++ b/csrc/pf_save.c @@ -343,6 +343,33 @@ error: return -1; } +/* Convert dictionary info chunk between native and on-disk (big-endian). */ +static void +convertDictionaryInfoWrite (DictionaryInfoChunk *sd) +{ +/* Convert all fields in DictionaryInfoChunk from Native to BigEndian. + * This assumes they are all 32-bit integers. + */ + int i; + uint32_t *p = (uint32_t *) sd; + for (i=0; i<((int)(sizeof(*sd)/sizeof(uint32_t))); i++) + { + Write32BigEndian( (uint8_t *)&p[i], p[i] ); + } +} + +static void +convertDictionaryInfoRead (DictionaryInfoChunk *sd) +{ +/* Convert all fields in structure from BigEndian to Native. */ + int i; + uint32_t *p = (uint32_t *) sd; + for (i=0; i<((int)(sizeof(*sd)/sizeof(uint32_t))); i++) + { + p[i] = Read32BigEndian( (uint8_t *)&p[i] ); + } +} + /**************************************************************** ** Save Dictionary in File. ** If EntryPoint is NULL, save as development environment. @@ -356,7 +383,6 @@ cell_t ffSaveForth( const char *FileName, ExecToken EntryPoint, cell_t NameSize, uint32_t NameChunkSize = 0; uint32_t CodeChunkSize; uint32_t relativeCodePtr; - int i; fid = sdOpenFile( FileName, "wb" ); if( fid == NULL ) @@ -445,16 +471,7 @@ cell_t ffSaveForth( const char *FileName, ExecToken EntryPoint, cell_t NameSize, SD.sd_CodeSize = CodeSize; -/* Convert all fields in DictionaryInfoChunk from Native to BigEndian. - * This assumes they are all 32-bit integers. - */ - { - uint32_t *p = (uint32_t *) &SD; - for( i=0; i<((int)(sizeof(SD)/sizeof(uint32_t))); i++ ) - { - Write32BigEndian( (uint8_t *)&p[i], p[i] ); - } - } + convertDictionaryInfoWrite (&SD); if( WriteChunkToFile( fid, ID_P4DI, (char *) &SD, sizeof(DictionaryInfoChunk) ) < 0 ) goto error; @@ -517,7 +534,6 @@ PForthDictionary pfLoadDictionary( const char *FileName, ExecToken *EntryPointPt uint32_t FormSize; uint32_t BytesLeft; uint32_t numr; - int i; int isDicBigEndian; DBUG(("pfLoadDictionary( %s )\n", FileName )); @@ -568,15 +584,8 @@ DBUG(("pfLoadDictionary( %s )\n", FileName )); if( numr != ChunkSize ) goto read_error; BytesLeft -= ChunkSize; -/* Convert all fields in structure from BigEndian to Native. */ - { - uint32_t *p = (uint32_t *) sd; - for( i=0; i<((int)(sizeof(*sd)/sizeof(uint32_t))); i++ ) - { - p[i] = Read32BigEndian( (uint8_t *)&p[i] ); - } - } - + convertDictionaryInfoRead (sd); + isDicBigEndian = sd->sd_Flags & SD_F_BIG_ENDIAN_DIC; if( !gVarQuiet ) diff --git a/csrc/pfcompil.c b/csrc/pfcompil.c index dcb386f..84546c4 100644 --- a/csrc/pfcompil.c +++ b/csrc/pfcompil.c @@ -927,7 +927,7 @@ ThrowCode ffOuterInterpreterLoop( void ) } /*************************************************************** -** Include a file +** Include then close a file ***************************************************************/ ThrowCode ffIncludeFile( FileStream *InputFile ) @@ -963,6 +963,9 @@ ThrowCode ffIncludeFile( FileStream *InputFile ) /* Pop file stream. */ ffPopInputStream(); +/* ANSI spec specifies that this should also close the file. */ + sdCloseFile(InputFile); + return exception; } diff --git a/fth/floats.fth b/fth/floats.fth index cb77770..9196575 100644 --- a/fth/floats.fth +++ b/fth/floats.fth @@ -406,16 +406,21 @@ false fp-require-e ! \ violate ANSI !! c-addr c@ [char] E = c-addr c@ [char] e = OR IF - 1 +-> c-addr -1 +-> u' \ skip char - c-addr c@ [char] + = \ ignore + on exponent + 1 +-> c-addr -1 +-> u' \ skip E char + u' 0> IF - 1 +-> c-addr -1 +-> u' \ skip char - THEN - c-addr u' ((number?)) - num_type_single = - IF - nshift + -> nshift - true -> flag + c-addr c@ [char] + = \ ignore + on exponent + IF + 1 +-> c-addr -1 +-> u' \ skip char + THEN + c-addr u' ((number?)) + num_type_single = + IF + nshift + -> nshift + true -> flag + THEN + ELSE + true -> flag \ allow "1E" THEN THEN ELSE diff --git a/fth/history.fth b/fth/history.fth index 5e5409e..574d6a6 100644 --- a/fth/history.fth +++ b/fth/history.fth @@ -50,6 +50,8 @@ KH-HISTORY kh_history_size erase \ \ The most recent entry is put at the beginning, \ older entries are shifted up. + +4 constant KH_LINE_EXTRA_SIZE ( 2 count bytes plus 2 size bytes ) : KH-END ( -- addr , end of history buffer ) kh-history kh_history_size + @@ -131,8 +133,10 @@ variable KH-INSIDE ( true if we are scrolling inside the history buffer ) ELSE >r ( save count ) \ Set look pointer to point to first count byte of last string. - 0 kh-look ! - r@ cell+ kh.make.room + 0 kh-look ! +\ Make room for this line of text and line header. +\ PLB20100823 Was cell+ which broke on 64-bit code. + r@ KH_LINE_EXTRA_SIZE + kh.make.room \ Set count bytes at beginning and end. r@ kh-history c! ( start count ) r@ kh.endcount.addr c! diff --git a/fth/system.fth b/fth/system.fth index 0223ab0..b9c46f3 100644 --- a/fth/system.fth +++ b/fth/system.fth @@ -738,16 +738,14 @@ variable TRACE-INCLUDE drop ." Could not find file " $type cr abort ELSE ( -- $filename good-fid ) swap include.mark.start - dup >r \ save fid for close-file depth >r - include-file + include-file \ will also close the file depth 1+ r> - IF ." Warning: stack depth changed during include!" cr .s cr 0sp THEN - r> close-file drop include.mark.end THEN trace-include @ diff --git a/releases.txt b/releases.txt index 62f3502..4830690 100644 --- a/releases.txt +++ b/releases.txt @@ -2,9 +2,14 @@ Release History for pForth - a Portable ANS-like Forth written in ANSI 'C' Documentation for pForth at http://www.softsynth.com/pforth/ -V?? +V27 - Fixed REPOSITION-FILE FILE-SIZE and FILE-POSITION. They used to use single precision offset. Now use double as specified. + - Delete object directories in Makefile clean. + - Fixed "Issue 4: Filehandle remains locked upon INCLUDE error". + http://code.google.com/p/pforth/issues/detail?id=4&can=1 + - Fixed scambled HISTORY on 64-bit systems. Was using CELL+ but really needed 4 +. + - Fixed floating point input. Now accepts "1E" as 1.0. Was Issue #2. V26 5/20/2010 - 64-bit support for M* UM/MOD etc by Aleksej Saushev. Thanks Aleksej! -- 2.20.1