[plt-scheme] Extensions

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

Hi,

I have several questions about extensions. This is a lengthy
letter.
Sorry.

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

First:
------
Consider the attached files (they are at the back):
- test.c : This is a standard C file which defines a "test"
module.
  In the module there is one function called "test". This
function
  sets some flags under Windows to control floating point
operations.
  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.

Second:
-------
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
/nodefaultlib:libcmt
However I cannot specify this for mzc, it reports an unknown
flag.
So I would like to use something like this:
mzc ++ldf /nodefaultlib:libcmt ++ldl my.lib -ld test.dll
test.obj
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.


Third:
------
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 */
#define MAKE_MODULE

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


static Scheme_Object *test(int argc, Scheme_Object **argv)
{
  int ndiv;
  
  if(!SCHEME_INTP(argv[0]))
  {
    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 */
    cw &=~(EM_OVERFLOW|EM_UNDERFLOW|EM_ZERODIVIDE|EM_DENORMAL);

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

  return scheme_false;
}


/*
--------------------------------------------------------------------------
Infrastructure for MzScheme
--------------------------------------------------------------------------
*/

Scheme_Object *scheme_reload(Scheme_Env *env)
{
  Scheme_Object *proc;
  
#ifdef MAKE_MODULE
  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);
  scheme_finish_primitive_module(menv);
#else
  proc = scheme_make_prim_w_arity(crv_div, "test", 1, 1);
  scheme_add_global("test", proc, env);
#endif
  
  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()
{
#ifdef MAKE_MODULE
  /* This extension defines a module named `idmodule': */
  return scheme_intern_symbol("test"); 
#else
  return scheme_false;
#endif
} 

----------------------------- 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!
http://ad.adverticum.net/b/cl,1,6022,99786,162268/click.prm




Posted on the users mailing list.