libgeda

scheme_smob.c File Reference

Scheme representations of gEDA C structures. More...

#include <config.h>
#include "libgeda_priv.h"
#include "libgedaguile_priv.h"
#include "scheme_smob.x"
Include dependency graph for scheme_smob.c:

Go to the source code of this file.

Functions

static void smob_weakref_notify (void *target, void *smob)
 Weak reference notify function for gEDA smobs.
static void smob_weakref2_notify (void *target, void *smob)
 Weak reference notify function for double-length gEDA smobs.
static size_t smob_free (SCM smob)
 Free a gEDA smob.
static int smob_print (SCM smob, SCM port, scm_print_state *pstate)
 Print a representation of a gEDA smob.
static SCM smob_equalp (SCM obj1, SCM obj2)
 Check gEDA smobs for equality.
SCM edascm_from_toplevel (TOPLEVEL *toplevel)
 Get the smob for a TOPLEVEL.
SCM edascm_from_page (PAGE *page)
 Get a smob for a page.
PAGEedascm_to_page (SCM smob)
 Get a page from a smob.
SCM edascm_from_object (OBJECT *object)
 Get a smob for a schematic object.
OBJECTedascm_to_object (SCM smob)
 Get a schematic object from a smob.
void edascm_c_set_gc (SCM smob, int gc)
 Set whether a gEDA object may be garbage collected.
int edascm_is_object (SCM smob)
 Test whether a smob is a OBJECT instance.
int edascm_is_page (SCM smob)
 Test whether a smob is a PAGE instance.
 SCM_DEFINE (page_p,"%page?", 1, 0, 0,(SCM page_smob),"Test whether the value is a gEDA PAGE instance.")
 Test whether a smob is a PAGE instance.
 SCM_DEFINE (object_p,"%object?", 1, 0, 0,(SCM object_smob),"Test whether the value is a gEDA OBJECT instance.")
 Test whether a smob is an OBJECT instance.
static void init_module_geda_core_smob ()
 Create the (geda core smob) Scheme module.
void edascm_init_smob ()
 Initialise the basic gEDA smob types.

Variables

scm_t_bits geda_smob_tag

Detailed Description

In order for Scheme code to be able to manipulate libgeda data structures, it is convenient for it to be able to get handles to several of the different C structures that libgeda uses, in particular TOPLEVEL, PAGE and OBJECT.

A particular issue is that, in principle, Guile can stash a variable somewhere and only try and access it much later, possibly after the underlying C structure has already been freed.

In order to avoid this situation causing a segmentation fault, weak references are used. In the case of PAGE and TOPLEVEL handles, the usage is quite straightforward; Scheme code can never create or destroy a TOPLEVEL; and although a PAGE can be created by Scheme code, it must explicitly be destroyed if the Scheme code doesn't want the PAGE to hang around after it returns.

OBJECT handles are a more complex case. It's possible that Scheme code may legitimately want to create an OBJECT and do something with it (or, similarly, pull an OBJECT out of a PAGE), without needing to carefully keep track of the OBJECT to avoid dropping it on the floor. In that case, users should be able to rely on the garbage collector.

For that reason, an OBJECT is marked to be destroyed by garbage-collection in two cases:

  1. If they have been created by Scheme code, but not yet added to a PAGE.
  2. If they have been removed from a PAGE by Scheme code, but not yet re-added to a PAGE.
See also:
weakref.c

Definition in file scheme_smob.c.


Function Documentation

static void smob_weakref_notify ( void *  target,
void *  smob 
) [static]
Function Description
Clears a gEDA smob's pointer when the target object is destroyed.

Definition at line 70 of file scheme_smob.c.

static void smob_weakref2_notify ( void *  target,
void *  smob 
) [static]
Function Description
Clears a gEDA smob's second pointer when the target object is destroyed.
See also:
edascm_from_object().

Definition at line 83 of file scheme_smob.c.

static size_t smob_free ( SCM  smob) [static]
Function Description
Finalizes a gEDA smob for deletion, removing the weak reference.

Used internally to Guile.

Definition at line 95 of file scheme_smob.c.

Here is the call graph for this function:

static int smob_print ( SCM  smob,
SCM  port,
scm_print_state *  pstate 
) [static]
Function Description
Outputs a string representing the gEDA smob to a Scheme output port. The format used is "#<geda-TYPE b7ef65d0>", where TYPE is a string describing the C structure represented by the gEDA smob.

Used internally to Guile.

Definition at line 162 of file scheme_smob.c.

static SCM smob_equalp ( SCM  obj1,
SCM  obj2 
) [static]
Function description
Returns SCM_BOOL_T if obj1 represents the same gEDA structure as obj2 does. Otherwise, returns SCM_BOOL_F.

Used internally to Guile.

Definition at line 207 of file scheme_smob.c.

SCM_DEFINE ( page_p  ,
"%page?"  ,
,
,
,
(SCM page_smob)  ,
"Test whether the value is a gEDA PAGE instance."   
)
Function Description
If page_smob is a PAGE instance, returns SCM_BOOL_T; otherwise returns SCM_BOOL_F.
Note:
Scheme API: Implements the page? procedure in the (geda core smob) module.
Parameters:
[in]page_smobGuile value to test.
Returns:
SCM_BOOL_T iff page_smob is a PAGE instance.

Definition at line 403 of file scheme_smob.c.

SCM_DEFINE ( object_p  ,
"%object?"  ,
,
,
,
(SCM object_smob)  ,
"Test whether the value is a gEDA OBJECT instance."   
)
Function Description
If object_smob is an OBJECT instance, returns SCM_BOOL_T; otherwise returns SCM_BOOL_F.
Note:
Scheme API: Implements the object? procedure in the (geda core smob) module.
Parameters:
[in]object_smobGuile value to test.
Returns:
SCM_BOOL_T iff object_smob is an OBJECT instance.

Definition at line 422 of file scheme_smob.c.

static void init_module_geda_core_smob ( ) [static]
Function Description
Defines procedures in the (geda core smob) module. The module can be accessed using (use-modules (geda core smob)).

Definition at line 436 of file scheme_smob.c.

void edascm_init_smob ( )
Function Description
Registers the gEDA core smob types and some procedures acting on them. gEDA only uses a single Guile smob, and uses the flags field to multiplex the several different underlying C structures that may be represented by that smob. Should only be called by edascm_init().

Definition at line 455 of file scheme_smob.c.

Here is the call graph for this function:


Variable Documentation

scm_t_bits geda_smob_tag

The tag used to identify gEDA data structures in Scheme.

Definition at line 63 of file scheme_smob.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines