This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

glue between GOOPS and C classes and GOOPS bugs/buglets


I'm trying to define GOOPS classes in C (the final goal is actually to glue 
in a library written in C++, but this is an useful first step nevertheless). 
Here is the code I'm using.  The problem I have is with marking SCM slots 
defined in C structures so that they're protected from garbage collection. 
Any suggestions?

I've also found a few problems with goops. In goops-snarf.h:
#define SCM_SLOT_SCM(C_CLASS, C_TYPE, C_SLOT, SCM_SLOT, A)	\
SCM_I_SLOT (C_CLASS, C_TYPE, C_SLOT, SCM_SLOT, scm_class_SCM,	\
	    1,							\
	    o->C_SLOT,						\
	    o->C_SLOT = x,					\
	    A)

scm_class_SCM should be scm_class_scm. Also, goops.c is not C++ friendly as 
the C++ keywords class and new are used as identifiers.
Sorry for not being able to send diffs with the internet connection I have 
at present, but fixes are very easy.
Thanks a lot,

	Maurizio Vitale



=========== cut here =========================
#include <libguile.h>
#include <goops.h>

#include "graph.h"
#include "versiondat.h"

struct graph {
  int size;
  SCM stuff;
};

static struct graph *make_graph (SCM initargs);
static size_t free_graph (struct graph *o);

SCM_CLASS (graph, "<graph>", SCM_EOL, 0, make_graph, free_graph);
SCM_SLOT_INT (graph, struct graph, size, "size", "graph:size");
SCM_PROC (s_set_graph_size, "set-graph-size!", 2, 0, 0, scm_set_graph_size);
SCM_PROC (s_get_graph_size, "get-graph-size", 1, 0, 0, scm_get_graph_size);
SCM_SLOT_SCM (graph, struct graph, stuff, "stuff", "graph:stuff");
SCM_PROC (s_set_graph_stuff, "set-graph-stuff!", 2, 0, 0, 
scm_set_graph_stuff);
SCM_PROC (s_get_graph_stuff, "get-graph-stuff", 1, 0, 0, 
scm_get_graph_stuff);

static struct graph *
make_graph (SCM initargs)
{
  struct graph *p = (struct graph *) malloc (sizeof (*p));
  scm_done_malloc (sizeof (*p));
  p->stuff = SCM_EOL;
  return p;
}

static size_t
free_graph (struct graph *o)
{
  free (o);
  return sizeof (*o);
}

SCM_PROC (s_graph_version, "graph-version", 0, 0, 0, scm_graph_version);
SCM
scm_graph_version ()
{
  return scm_makfrom0str (GRAPH_VERSION);
}

void
scm_init_graph (void)
{
  SCM graph_module = scm_make_module (scm_read_0str ("(graph)"));
  SCM old_module = scm_select_module (graph_module);

#include "graph.x"

  scm_select_module (old_module);
}

void
scm_init_graph_graphcore_module ()
{
  printf ("defining module");
  scm_register_module_xxx ("graph graphcore", (void *) scm_init_graph);
}

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]