unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* program-module returns a non-module
@ 2010-09-05  0:25 Jose A. Ortega Ruiz
  2010-09-05 10:28 ` Ludovic Courtès
  2010-09-06 11:58 ` Andy Wingo
  0 siblings, 2 replies; 4+ messages in thread
From: Jose A. Ortega Ruiz @ 2010-09-05  0:25 UTC (permalink / raw)
  To: guile-devel


Hi,

When called on a program (procedure object) implemented in C,
program-module returns something that is not a module:

  (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?

Cheers,
jao
-- 
Ignorance more frequently begets confidence than does knowledge
  - Charles Darwin




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: program-module returns a non-module
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2010-09-05 10:28 UTC (permalink / raw)
  To: guile-devel

Hello,

"Jose A. Ortega Ruiz" <jao@gnu.org> writes:

> When called on a program (procedure object) implemented in C,
> program-module returns something that is not a module:
>
>   (define cp (module-ref (current-module) 'cons))
>
>   (program? cp) => #t
>   (program-module cp) => #<pointer 0xb77ccbb0>
>   (module? (program-module cp)) => #f

Apparently ‘program-module’ assumes that the first object in a program
object table is the module in question, but that is no longer true:

  scheme@(guile-user)> (program-objects (lambda x x))
  $56 = #f
  scheme@(guile-user)> (program-objects cons)
  $57 = #(#<pointer 0x7f2992042d60> cons)

except for programs referring to global bindings:

  scheme@(guile-user)> (program-objects (lambda x getaddrinfo))
  $60 = #(#<directory (guile-user) 109c090> getaddrinfo)

Hmm ‘compile-assembly.scm’ has this ‘*module*’ variable, which seems to
relate to this.  Needs more investigation...

Ludo’.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: program-module returns a non-module
  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:58 ` Andy Wingo
  1 sibling, 0 replies; 4+ messages in thread
From: Andy Wingo @ 2010-09-06 11:58 UTC (permalink / raw)
  To: Jose A. Ortega Ruiz; +Cc: guile-devel

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/



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: program-module returns a non-module
  2010-09-05 10:28 ` Ludovic Courtès
@ 2010-09-06 11:59   ` Andy Wingo
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Wingo @ 2010-09-06 11:59 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel

On Sun 05 Sep 2010 12:28, ludo@gnu.org (Ludovic Courtès) writes:

> Hmm ‘compile-assembly.scm’ has this ‘*module*’ variable, which seems to
> relate to this.  Needs more investigation...

Together with make-object-table's consing a #f onto the front of the
returned table, this ensures that any object table has space for a
module.

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-09-06 11:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).