[PATCH] misc fix "filecopy" "|waitForViewport|"

3 views
Skip to first unread message

Qian Yun

unread,
May 1, 2024, 6:44:01 AM5/1/24
to fricas-devel
For "filecopy", it's absurd to do IO char by char.

For "|waitForViewport|", this is left over of the previous
"obey" -> "|run_shell_command|" change. Also avoid spawning
lot's of threads.

- Qian


diff --git a/src/graph/Gdraws/Gfun.c b/src/graph/Gdraws/Gfun.c
index 292f8b3b..2ec625c3 100644
--- a/src/graph/Gdraws/Gfun.c
+++ b/src/graph/Gdraws/Gfun.c
@@ -52,14 +52,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
* Given 2 file pointers, this function copies file ifp to file ofp
*/

+#define BUFFER_SIZE 4096
+
static void
filecopy(FILE * ifp, FILE * ofp)
{
-
- int c;
-
- while ((c = getc(ifp)) != EOF)
- putc(c, ofp);
+ size_t bytesRead;
+ char buffer[BUFFER_SIZE];
+ while ((bytesRead = fread(buffer, 1, BUFFER_SIZE, ifp)) > 0) {
+ fwrite(buffer, 1, bytesRead, ofp);
+ }
}

/*
diff --git a/src/interp/util.lisp b/src/interp/util.lisp
index 939ddd19..faced223 100644
--- a/src/interp/util.lisp
+++ b/src/interp/util.lisp
@@ -273,11 +273,11 @@ After this function is called the image is clean
and can be saved.
(defun |waitForViewport| ()
(progn
(do ()
- ((not (zerop (obey
+ ((not (zerop (|run_shell_command|
(concat
"ps "
|$ViewportProcessToWatch|
- " > /dev/null")))))
+ " > /dev/null && sleep 0.1")))))
())
(|sockSendInt| |$MenuServer| 1)
(|setIOindex| (- |$IOindex| 3))

Waldek Hebisch

unread,
May 1, 2024, 7:26:16 AM5/1/24
to fricas...@googlegroups.com
On Wed, May 01, 2024 at 06:43:56PM +0800, Qian Yun wrote:
> For "filecopy", it's absurd to do IO char by char.
>
> For "|waitForViewport|", this is left over of the previous
> "obey" -> "|run_shell_command|" change. Also avoid spawning
> lot's of threads.

OK, please commit.

--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages