[plt-scheme] Extensions

From: Ivanyi Peter (pivanyi at freemail.hu)
Date: Mon Nov 13 10:42:24 EST 2006


I have several questions about extensions. This is a lengthy

All these are on Windows XP (English) PLT-Scheme 352.

Consider the attached files (they are at the back):
- test.c : This is a standard C file which defines a "test"
  In the module there is one function called "test". This
  sets some flags under Windows to control floating point
  In PLT-Scheme 301 I could use this code however in version
352 this
  code crashes mzscheme. Can someone tell me what has
changed between
  the versions? (I need this code for my numerical library
to signal
  over and underflow, NaN, etc...)
- test.scm : This is the scheme file to test the extension.
- build.bat : I use this batch to build the extension.

I have another problem when I want to build my extension.
For some reason, I am not sure why, the linker wants to link in
both libraries: LIBCD.LIB and LIBCMT.LIB .
I do not know why this is, but I could avoid this by using
the flag
However I cannot specify this for mzc, it reports an unknown
So I would like to use something like this:
mzc ++ldf /nodefaultlib:libcmt ++ldl my.lib -ld test.dll
but I have to use:
link /dll /nodefaultlib:libcmt /out:test.dll my.lib
"c:\Program Files\PLT\lib\msvc\libmzsch352_000.lib" ...

Any idea how to solve this? Why is that an unknown flag? I
though mzc accepts
all flags and just passes them to the compiler or linker.

I would like to make an executable which "includes" or
"uses" an extension.
(However as you can see above the extension is a module.)
How can I do that?
The problem is that in DrScheme this is allowed:

(load-extension "./test.dll")
(module test mzscheme
  (require test)
  (display (test 10))

but when I try to build it as:

mzc --exe test.exe test.scm

mzc reports that it would expect a module, but found
something else.
I am interested in any solution to this problem.

Thanks for any help.

Best regards,

Peter Ivanyi

-----------------------------  test.c

/* define it if it is a scheme module */

#include <string.h>
#include "escheme.h"
#include <float.h>

static Scheme_Object *test(int argc, Scheme_Object **argv)
  int ndiv;
    scheme_signal_error("test: arg %d: must be an integer", 0);

  ndiv = SCHEME_INT_VAL(argv[0]);
    /* Get the default control word. */
    int cw = _controlfp( 0,0 );

    /* Set the exception masks OFF, turn exceptions on. */
    /* |EM_INEXACT not needed */

    /* Set the control word. */
    _controlfp( cw, MCW_EM );

  return scheme_false;

Infrastructure for MzScheme

Scheme_Object *scheme_reload(Scheme_Env *env)
  Scheme_Object *proc;
  Scheme_Env *menv;

  menv =
scheme_primitive_module(scheme_intern_symbol("test"), env);
  proc = scheme_make_prim_w_arity(test, "test", 1, 1);
  /* All added names are automatically exported by the
module: */
  scheme_add_global("test", proc, menv);
  proc = scheme_make_prim_w_arity(crv_div, "test", 1, 1);
  scheme_add_global("test", proc, env);
  return scheme_void; 

Scheme_Object *scheme_initialize(Scheme_Env *env)
  /* First load is same as every load: */
  return scheme_reload(env);

Scheme_Object *scheme_module_name()
  /* This extension defines a module named `idmodule': */
  return scheme_intern_symbol("test"); 
  return scheme_false;

----------------------------- end of test.c

----------------------------- test.scm

(load-extension "./test.dll")
(require test)
(display (test 10))

------------------------------ end of test.scm

------------------------------ build.bat

@echo off

del test.obj test.dll

mzc --cc test.c

mzc --ld test.dll test.obj

Fotóalbum.hu - Tölts fel képeid, oszd meg másokkal, készítsd
el online fotóalbumod!

Posted on the users mailing list.