GAWK 3.0.95 - Bug (er, problem) report on extension stuff 
Author Message
 GAWK 3.0.95 - Bug (er, problem) report on extension stuff

I got the examples in the extension subdir working, but I think I've found a
problem.  Using the forktest example, I decided to replace the call to
system() with a library call to sleep().  So, I cut&pasted the waitpid code,
and edited it.  Here is the new ending of fork.c:

--- Cut Here ---
/* Note that I've customized the error messages a little bit */
static NODE *
do_sleep(tree)
NODE *tree;
{
        NODE *sleepnode;
        int ret = -1;

        printf("Here we are in do_sleep, and tree->param_cnt=%d\n",
                tree->param_cnt);
        if  (do_lint && tree->param_cnt > 1)
                lintwarn("sleep: called with too many (more than 1) arguments");

        sleepnode = get_argument(tree, 0);
        if (sleepnode != NULL) {
                ret = sleep((int) force_number(sleepnode));
                if (ret < 0)
                        update_ERRNO();
        } else if (do_lint)
                lintwarn("sleep: called with no arguments (Wow!)");

        /* Set the return value */
        set_value(tmp_number((AWKNUM) ret));

        /* Just to make the interpreter happy */
        return tmp_number((AWKNUM) 0);

Quote:
}

/* dlload --- load new builtins in this library */

NODE *
dlload(tree, dl)
NODE *tree;
void *dl;
{
        make_builtin("fork", do_fork, 0);
        make_builtin("waitpid", do_waitpid, 1);
        make_builtin("sleep", do_sleep, 1); /* This line added */
        return tmp_number((AWKNUM) 0);

Quote:
}

--- Cut Here ---

I compiled the lib via:

        gcc -shared -Wall -DHAVE_CONFIG_H -c -O -g -I.. fork.c &&
            ld -o fork.so -shared fork.o

and here's the modified version of forktest.awk:

--- Cut Here ---
BEGIN {
        extension("./fork.so", "dlload")

        printf "before fork, pid = %d, ppid = %d\n", PROCINFO["pid"],
                        PROCINFO["ppid"]

        fflush()
        ret = fork()
        if (ret < 0)
                printf("ret = %d, ERRNO = %s\n", ret, ERRNO)
        else if (ret == 0)
                printf "child, pid = %d, ppid = %d\n", PROCINFO["pid"],
                        PROCINFO["ppid"]
        else {
                sleep()
                sleep(1,5)
                sleep(3)
                printf "parent, ret = %d\n", ret
                printf "parent, pid = %d, ppid = %d\n", PROCINFO["pid"],
                        PROCINFO["ppid"]
        }

Quote:
}

--- Cut Here ---

And here's the output:

234 %) ../gawk --lint -f testfork.awk
gawk: testfork.awk:2: warning: `extension' is a gawk extension
gawk: testfork.awk:7: warning: `fflush' is a Bell Labs extension
gawk: testfork.awk:23: warning: function `sleep' called but never defined
gawk: testfork.awk:23: warning: function `fork' called but never defined
gawk: testfork.awk:2: warning: `extension' is a gawk extension
before fork, pid = 30187, ppid = 15046
Here we are in do_sleep, and tree->param_cnt=1
child, pid = 30188, ppid = 30187
gawk: ext.c:130: warning: sleep: called with no arguments (Wow!)
gawk: testfork.awk:16: warning: function `sleep' called with more arguments
than declared
Here we are in do_sleep, and tree->param_cnt=1
Here we are in do_sleep, and tree->param_cnt=1
parent, ret = 30188
parent, pid = 30187, ppid = 15046
235 %)

Comments/questions:
        1) Note that the param_cnt is always 1.
        2) I'm curious that this line:
           gawk: ext.c:130: warning: sleep: called with no arguments (Wow!)

           Why does it say ext.c:130 instead of fork.c:line# ?
        3) I'm curious that this line:
           gawk: testfork.awk:16: warning: function `sleep' called with more arguments

           Where is this coming from?  I was surprised to see this message
           and not the message that was in my code.
        4) I assume that the last parameter to make_builtin() is the number
           of args that the function takes.  What is the last arg to
           get_argument, as in the line below:

                sleepnode = get_argument(tree, 0);

I think the first one is a bug, the rest are only questions.



Tue, 19 Aug 2003 22:33:39 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. GAWK 3.0.95 - question on the extensions stuff

2. gawk 3.0.95, beta for gawk 3.1.0, now available

3. Gawk bug, gawk won't nawk.

4. Recent emails from A. Robbins, regarding latest GAWK (3.0.95)

5. GAWK 3.0.95 - some questions/comments on PC compilation(s)

6. GAWK 2.15.6 for Windows NT/95, DOS32

7. gawk for 95/NT

8. X11 extension bug report for 64-bit machines

9. Document'er and Diagram'er ???

10. bug in win32process.CreateProcessAsUser?

11. gawk: dynamic extension and pgawk support for Win32

12. gawk 3.x: "static" extensions

 

 
Powered by phpBB® Forum Software