unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: "Jose A. Ortega Ruiz" <jao@gnu.org>
Cc: guile-devel@gnu.org
Subject: Re: program-module returns a non-module
Date: Mon, 06 Sep 2010 13:58:50 +0200	[thread overview]
Message-ID: <m3y6bfjd6t.fsf@unquote.localdomain> (raw)
In-Reply-To: <87occdujcf.fsf@newton.homeunix.net> (Jose A. Ortega Ruiz's message of "Sun, 05 Sep 2010 02:25:52 +0200")

Hi,

On Sun 05 Sep 2010 02:25, "Jose A. Ortega Ruiz" <jao@gnu.org> writes:

>   (define cp (module-ref (current-module) 'cons))
>
>   (program? cp) => #t
>   (program-module cp) => #<pointer 0xb77ccbb0>
>   (module? (program-module cp)) => #f
>
> Since `cp' above is a program, i was expecting the return value to be
> always a module: is that a wrong expectation or is this a bug?

It's a bug.

When Guile compiles a Scheme function, it doesn't emit a constants table
unless it has to. It has to if there is a quoted constant in the
function body. The constants table is also used as a cache for toplevel
variable access.

If there is a constants table, index 0 of that table will contain the
procedure's module. 

However since primitives, full continuations, partial continuations, and
foreign functions all hand-craft their bytecode trampolines, the Scheme
compiler isn't involved, so it's not there to ensure that the 0th
element of the object table is a module. It's not even clear what it
means for a primitive procedure to have a module.

There could be many solutions -- for example, flagging programs loaded
via the load-program opcode as being "module-blessed" -- but I think for
now the simple heuristic of rejecting non-module returns from
program-module will suffice. I have committed that locally and will push
soon.

Thanks for the report,

Andy
-- 
http://wingolog.org/



      parent reply	other threads:[~2010-09-06 11:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-05  0:25 program-module returns a non-module Jose A. Ortega Ruiz
2010-09-05 10:28 ` Ludovic Courtès
2010-09-06 11:59   ` Andy Wingo
2010-09-06 11:58 ` Andy Wingo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3y6bfjd6t.fsf@unquote.localdomain \
    --to=wingo@pobox.com \
    --cc=guile-devel@gnu.org \
    --cc=jao@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).