Skip to content

Commit 4b17165

Browse files
committed
fix: reminants from larger first pass output show up in smaller second pass output
1 parent 8424aca commit 4b17165

2 files changed

Lines changed: 16 additions & 20 deletions

File tree

7800bas.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ extern int changedmaholescalled;
6565
int maxpasses = 2;
6666

6767
#define PREPROC_BUFFER_SIZE (256 * 1024) // 256KB buffer for preprocessed file
68-
static char *preproc_buffer = NULL;
68+
char *preproc_buffer = NULL;
6969

7070
#define BASIC_VERSION_INFO "7800basic v0.39"
7171

@@ -451,22 +451,18 @@ int main (int argc, char *argv[])
451451

452452
prout ("7800basic compilation complete.\n");
453453
freemem (deallocate_mem);
454+
// Explicitly close the main assembly file at the end of each pass.
455+
if (main_asm_fp != NULL) {
456+
fclose(main_asm_fp);
457+
main_asm_fp = NULL;
458+
current_output_fp = NULL;
459+
}
454460
}
455461

456462
header_write (header, filename);
457463
create_includes (includes_file);
458464

459465
lastrites ();
460466

461-
// Final cleanup of the preprocessed file descriptor and its buffer
462-
if (preprocessedfd != NULL && preprocessedfd != stdin) {
463-
fclose(preprocessedfd);
464-
}
465-
466-
if (preproc_buffer != NULL) {
467-
free(preproc_buffer);
468-
preproc_buffer = NULL;
469-
}
470-
471467
return 0;
472468
}

statements.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ char savelinesname[MAXINCBASIC][MAXINCBASIC];
3232
extern char stdoutfilename[256];
3333
extern FILE *preprocessedfd;
3434
extern FILE *main_asm_fp;
35+
extern char *preproc_buffer;
3536
extern FILE *current_output_fp;
3637
extern char backupname[256];
3738
extern int maxpasses;
@@ -12373,17 +12374,16 @@ void lastrites()
1237312374
remove("7800hole.1.asm");
1237412375
remove("7800hole.2.asm");
1237512376

12376-
// Close all our managed file pointers
12377-
if (current_output_fp != NULL)
12377+
// Final cleanup of the preprocessed file descriptor and its buffer.
12378+
if (preprocessedfd != NULL && preprocessedfd != stdin)
1237812379
{
12379-
fflush(current_output_fp);
12380-
if (current_output_fp != main_asm_fp)
12381-
fclose(current_output_fp);
12382-
current_output_fp = NULL;
12380+
fclose(preprocessedfd);
12381+
preprocessedfd = NULL;
1238312382
}
12384-
if (main_asm_fp != NULL)
12383+
12384+
if (preproc_buffer != NULL)
1238512385
{
12386-
fclose(main_asm_fp);
12387-
main_asm_fp = NULL;
12386+
free(preproc_buffer);
12387+
preproc_buffer = NULL;
1238812388
}
1238912389
}

0 commit comments

Comments
 (0)