[gjs: 5/13] console: Remove unused arguments



commit c29f25d74835188d04028a847ddefe68548e6350
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Apr 20 15:29:30 2019 -0700

    console: Remove unused arguments
    
    There are two versions of gjs_console_readline(), one uses readline and
    one does not, depending on whether the readline library is available to
    compile with. In the readline case, the FILE* argument was never used.
    In the non-readline case, it supposedly supported an arbitrary file
    pointer but was only ever called with stdin. We just change it to stdin
    everywhere.
    
    The JSContext is not needed in this function, either.

 modules/console.cpp | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
---
diff --git a/modules/console.cpp b/modules/console.cpp
index 05384a04..3fdc5514 100644
--- a/modules/console.cpp
+++ b/modules/console.cpp
@@ -238,9 +238,7 @@ public:
 
 #ifdef HAVE_READLINE_READLINE_H
 GJS_USE
-static bool
-gjs_console_readline(JSContext *cx, char **bufp, FILE *file, const char *prompt)
-{
+static bool gjs_console_readline(char** bufp, const char* prompt) {
     char *line;
     line = readline(prompt);
     if (!line)
@@ -252,13 +250,11 @@ gjs_console_readline(JSContext *cx, char **bufp, FILE *file, const char *prompt)
 }
 #else
 GJS_USE
-static bool
-gjs_console_readline(JSContext *cx, char **bufp, FILE *file, const char *prompt)
-{
+static bool gjs_console_readline(char** bufp, const char* prompt) {
     char line[256];
     fprintf(stdout, "%s", prompt);
     fflush(stdout);
-    if (!fgets(line, sizeof line, file))
+    if (!fgets(line, sizeof line, stdin))
         return false;
     *bufp = g_strdup(line);
     return true;
@@ -314,7 +310,6 @@ gjs_console_interact(JSContext *context,
     char *temp_buf = NULL;
     int lineno;
     int startline;
-    FILE *file = stdin;
 
     JS::SetWarningReporter(context, gjs_console_warning_reporter);
 
@@ -330,8 +325,8 @@ gjs_console_interact(JSContext *context,
         startline = lineno;
         buffer = g_string_new("");
         do {
-            if (!gjs_console_readline(context, &temp_buf, file,
-                                      startline == lineno ? "gjs> " : ".... ")) {
+            if (!gjs_console_readline(
+                    &temp_buf, startline == lineno ? "gjs> " : ".... ")) {
                 eof = true;
                 break;
             }
@@ -364,9 +359,6 @@ gjs_console_interact(JSContext *context,
 
     g_fprintf(stdout, "\n");
 
-    if (file != stdin)
-        fclose(file);
-
     argv.rval().setUndefined();
     return true;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]