/*! \brief Get a smob for a configuration context. * \ingroup guile_c_iface * \par Function Description * Create a new smob representing \a cfg. * * \param cfg Configuration context to create a smob for. * \return a smob representing \a cfg. * * \since 1.10. */ SCM edascm_from_config (EdaConfig *cfg) { SCM smob; SCM_NEWSMOB (smob, geda_smob_tag, g_object_ref (cfg)); SCM_SET_SMOB_FLAGS (smob, GEDA_SMOB_CONFIG); return smob; }
/*! \brief Get a smob for a C closure. * \par Function Description * Create a new smob representing a C closure. * * \warning Do not call this function from user code; use * edascm_c_make_closure() instead. * * \param func C function to make closure around. * \param user_data User data for function. * \return a C closure smob. */ SCM edascm_from_closure (SCM (*func)(SCM, gpointer), gpointer user_data) { SCM smob; SCM_NEWSMOB2 (smob, geda_smob_tag, func, user_data); SCM_SET_SMOB_FLAGS (smob, GEDA_SMOB_CLOSURE); return smob; }
/*! \brief Get a smob for a page. * \ingroup guile_c_iface * \par Function Description * Create a new smob representing \a page. * * \param page #PAGE to create a smob for. * \return a smob representing \a page. */ SCM edascm_from_page (PAGE *page) { SCM smob; SCM_NEWSMOB (smob, geda_smob_tag, page); SCM_SET_SMOB_FLAGS (smob, GEDA_SMOB_PAGE); /* Set weak reference */ s_page_weak_ref (page, smob_weakref_notify, smob); return smob; }
/*! \brief Get the smob for a TOPLEVEL. * \ingroup guile_c_iface * \par Function Description * Create a new smob representing \a toplevel. * * \param toplevel #TOPLEVEL to create a smob for. * \return a smob representing \a toplevel. */ SCM edascm_from_toplevel (TOPLEVEL *toplevel) { SCM smob; SCM_NEWSMOB (smob, geda_smob_tag, toplevel); SCM_SET_SMOB_FLAGS (smob, GEDA_SMOB_TOPLEVEL); /* Set weak reference */ s_toplevel_weak_ref (toplevel, smob_weakref_notify, smob); return smob; }
/*! \brief Get a smob for a configuration context. * \ingroup guile_c_iface * \par Function Description * Create a new smob representing \a cfg. * * \param cfg Configuration context to create a smob for. * \return a smob representing \a cfg. */ SCM edascm_from_config (EdaConfig *cfg) { SCM smob = smob_cache_lookup (cfg); if (EDASCM_CONFIGP (smob)) { return smob; } SCM_NEWSMOB (smob, geda_smob_tag, g_object_ref (cfg)); SCM_SET_SMOB_FLAGS (smob, GEDA_SMOB_CONFIG); return smob; }
/*! \brief Get a smob for a schematic object. * \ingroup guile_c_iface * \par Function Description * Create a new smob representing \a object. * * \warning The returned smob is initially marked as owned by the C * code. If it should be permitted to be garbage-collected, you * should set the garbage-collectable flag by calling: * * \code * SCM x = edascm_from_object (object); * edascm_c_set_gc (x, 1); * \endcode * * \note We currently have to bake a TOPLEVEL pointer into the smob, * so that if the object becomes garbage-collectable we can obtain a * TOPLEVEL to use for deleting the smob without accessing the * TOPLEVEL fluid and potentially causing a race condition (see bug * 909358). * * \param object #OBJECT to create a smob for. * \return a smob representing \a object. */ SCM edascm_from_object (OBJECT *object) { SCM smob; TOPLEVEL *toplevel = edascm_c_current_toplevel (); SCM_NEWSMOB2 (smob, geda_smob_tag, object, toplevel); SCM_SET_SMOB_FLAGS (smob, GEDA_SMOB_OBJECT); /* Set weak references */ s_object_weak_ref (object, smob_weakref_notify, smob); s_toplevel_weak_ref (toplevel, smob_weakref2_notify, smob); return smob; }
/*! \brief Get a smob for a page. * \ingroup guile_c_iface * \par Function Description * Create a new smob representing \a page. * * \param page #PAGE to create a smob for. * \return a smob representing \a page. */ SCM edascm_from_page (PAGE *page) { SCM smob = smob_cache_lookup (page); if (EDASCM_PAGEP (smob)) { return smob; } SCM_NEWSMOB (smob, geda_smob_tag, page); SCM_SET_SMOB_FLAGS (smob, GEDA_SMOB_PAGE); /* Set weak reference */ s_page_weak_ref (page, smob_weakref_notify, unpack_as_pointer (smob)); smob_cache_add (page, smob); return smob; }
/*! \brief Get the smob for a TOPLEVEL. * \ingroup guile_c_iface * \par Function Description * Create a new smob representing \a toplevel. * * \param toplevel #TOPLEVEL to create a smob for. * \return a smob representing \a toplevel. */ SCM edascm_from_toplevel (TOPLEVEL *toplevel) { SCM smob = smob_cache_lookup (toplevel); if (EDASCM_TOPLEVELP (smob)) { return smob; } SCM_NEWSMOB (smob, geda_smob_tag, toplevel); SCM_SET_SMOB_FLAGS (smob, GEDA_SMOB_TOPLEVEL); /* Set weak reference */ s_toplevel_weak_ref (toplevel, smob_weakref_notify, unpack_as_pointer (smob)); smob_cache_add (toplevel, smob); return smob; }
/*! \brief Get a smob for a schematic object. * \ingroup guile_c_iface * \par Function Description * Create a new smob representing \a object. * * \warning The returned smob is initially marked as owned by the C * code. If it should be permitted to be garbage-collected, you * should set the garbage-collectable flag by calling: * * \code * SCM x = edascm_from_object (object); * edascm_c_set_gc (x, 1); * \endcode * * \note We currently have to bake a TOPLEVEL pointer into the smob, * so that if the object becomes garbage-collectable we can obtain a * TOPLEVEL to use for deleting the smob without accessing the * TOPLEVEL fluid and potentially causing a race condition (see bug * 909358). * * \param object #OBJECT to create a smob for. * \return a smob representing \a object. */ SCM edascm_from_object (OBJECT *object) { SCM smob = smob_cache_lookup (object); if (EDASCM_OBJECTP (smob)) { return smob; } TOPLEVEL *toplevel = edascm_c_current_toplevel (); SCM_NEWSMOB2 (smob, geda_smob_tag, object, toplevel); SCM_SET_SMOB_FLAGS (smob, GEDA_SMOB_OBJECT); /* Set weak references */ s_object_weak_ref (object, smob_weakref2_notify, unpack_as_pointer (smob)); smob_cache_add (object, smob); return smob; }