[plt-scheme] GC surprise collection
On Sun, 5 Sep 2004 07:02:39 -0700, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> At Sun, 5 Sep 2004 01:30:32 +0900, Daniel Silva wrote:
> > moduleobject.c:
> >
> > PyObject* PyModule_New(char *name)
> > {
> > Scheme_Object* ns = scheme_make_namespace(0, 0);
> > assert(SCHEME_NAMESPACEP(o));
> > return PyModule_SpyNew(name, PySchemeNS_New((Scheme_Env*) ns));
> > }
>
> The `o' above is supposed to be `ns', right?
Whoops. Yep, copy&paste rename typo.
> Assuming the usual assert(), and assuming that PyModule_SpyNew() is a
> function (not a macro), then there's no GC between the return of
> scheme_make_namespace() and call to PySchemeNS_New()...
>
> > schemensobject.c:
> >
> > PyObject* PySchemeNS_New(Scheme_Env* ns)
> > {
> > assert(SCHEME_NAMESPACEP((Scheme_Object*)ns));
> > ...
> > return (PyObject*) ...;
> > }
>
> ... so I don't see how this assertion can fail.
>
> Maybe you can create a complete (but as small as possible) example to
> demonstrate the problem.
When I isolate it in a small example, the error doesn't come up
anymore. Sorry, I'll ask again when I can reproduce it...
/* shell:
mzc --cc ext.c
mzc --ld ext.so ext.o
mzscheme:
(load-extension "ext.so")
(ext-test "foo")
*/
#include <escheme.h>
#include <assert.h>
typedef struct {
void* ob_type;
} PyObject;
#define MALLOC scheme_malloc
PyObject* PyModule_SpyNew(char *name, PyObject* schemens);
PyObject* PySchemeNS_New(Scheme_Env* ns);
PyObject* PyModule_New(char *name)
{
Scheme_Object* ns = scheme_make_namespace(0, 0);
assert(SCHEME_NAMESPACEP(ns));
return PyModule_SpyNew(name, PySchemeNS_New((Scheme_Env*) ns));
}
PyObject* PySchemeNS_New(Scheme_Env* ns)
{
PyObject* ret;
assert(SCHEME_NAMESPACEP((Scheme_Object*)ns));
printf("PySchemeNS_New\n");
return ret = (PyObject*) MALLOC(sizeof(PyObject));
}
PyObject* PyModule_SpyNew(char *name, PyObject* schemens)
{
PyObject* ret;
printf("PyModule_SpyNew\n");
return ret = (PyObject*) MALLOC(sizeof(PyObject));
}
Scheme_Object* ext_test(int argc, Scheme_Object* argv[])
{
PyObject* pymod;
assert(SCHEME_STRINGP(argv[0]));
pymod = PyModule_New(SCHEME_STR_VAL(argv[0]));
return pymod ? scheme_true : scheme_false;
}
Scheme_Object* scheme_module_name() { return scheme_false; }
Scheme_Object* scheme_reload(Scheme_Env* env)
{
scheme_add_global( "ext-test",
scheme_make_prim_w_arity(ext_test, "ext-test", 1, 1),
env );
return scheme_void;
}
Scheme_Object* scheme_initialize(Scheme_Env* env)
{
return scheme_reload(env);
}