From 7a725efa2a3a2faa207fe29886b8b42cc21d0aea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Sun, 2 Aug 2020 14:26:55 +0200
Subject: [PATCH] Revert "Stdio.Buffer: Check for PIKE_T_FUNCTION before acting
 on objects."

This reverts commit 01543a00e48294140995709915891d7f7745bdb2.

This commit was part of a set of speculative fixes that
introduced other issues (SIGSEGV in testsuite).
---
 src/modules/_Stdio/buffer.cmod | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/modules/_Stdio/buffer.cmod b/src/modules/_Stdio/buffer.cmod
index e6cdc58d63..ed42aa5224 100644
--- a/src/modules/_Stdio/buffer.cmod
+++ b/src/modules/_Stdio/buffer.cmod
@@ -455,14 +455,16 @@ PIKECLASS Buffer
 
   PMOD_EXPORT void io_actually_trigger_output( Buffer *io )
   {
-    if (io->output.tu.named_type == PIKE_T_FUNCTION) {
-      if (UNLIKELY(!io->output.u.object->prog)) {
-        /* Destructed object. */
-        free_svalue(&io->output);
-        return;
-      }
+    if (UNLIKELY(!io->output.u.object->prog)) {
+      /* Destructed object. */
+      free_svalue(&io->output);
+      SET_SVAL(io->output, PIKE_T_INT, NUMBER_NUMBER, integer, 0);
+      return;
+    }
 
+    if ( io->output.u.object ) {
       move_svalue(Pike_sp++, &io->output);
+      SET_SVAL(io->output, PIKE_T_INT, NUMBER_NUMBER, integer, 0);
       apply_svalue(Pike_sp-1, 0);
       pop_n_elems(2);
     }
@@ -988,8 +990,11 @@ PIKECLASS Buffer
     if (f)
       assign_svalue(&io->output, f);
     else {
-      if (io->output.tu.named_type == PIKE_T_FUNCTION)
+      if (io->output.u.object) {
         free_svalue(&io->output);
+        io->output.u.object = 0;	// free_svalue() puts in -1
+      }
+      SET_SVAL(io->output, PIKE_T_INT, NUMBER_NUMBER, integer, 0);
     }
   }
 
-- 
GitLab