Skip to content

Commit

Permalink
Fix apparently longstanding FORM OBJECT! bug
Browse files Browse the repository at this point in the history
Forming of an object would print the object line by line, each with a
newline, and then remove the last character in the mold buffer to get
rid of the last newline.  There was no accounting for if nothing had
been added.

It's strange that this was in the 12-Dec-2012 open source release and
it hadn't been a (known) problem yet...seems like it would be common:

https://github.com/rebol/rebol/blob/25033f897b2bd466068d7663563cd3ff64740b94/src/core/s-mold.c#L880
  • Loading branch information
hostilefork committed Nov 5, 2015
1 parent 0c76e51 commit decba66
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/core/s-mold.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ static void Form_Object(const REBVAL *value, REB_MOLD *mold)
REBVAL *keys = BLK_HEAD(keylist);
REBVAL *vals = VAL_OBJ_VALUES(value); // first value is context
REBCNT n;
REBFLG had_output = FALSE;

// Prevent endless mold loop:
if (Find_Same_Block(MOLD_LOOP, value) > 0) {
Expand All @@ -864,10 +865,16 @@ static void Form_Object(const REBVAL *value, REB_MOLD *mold)

// Mold all words and their values:
for (n = 1; n < SERIES_TAIL(keylist); n++) {
if (!VAL_GET_EXT(keys + n, EXT_WORD_HIDE))
if (!VAL_GET_EXT(keys + n, EXT_WORD_HIDE)) {
had_output = TRUE;
Emit(mold, "N: V\n", VAL_TYPESET_SYM(keys + n), vals + n);
}
}
Remove_Sequence_Last(mold->series);

// Remove the final newline...but only if WE added something to the buffer
if (had_output)
Remove_Sequence_Last(mold->series);

Remove_Array_Last(MOLD_LOOP);
}

Expand Down

0 comments on commit decba66

Please sign in to comment.