* about `smob' generated by swig
@ 2007-03-26 11:18 William Xu
0 siblings, 0 replies; 5+ messages in thread
From: William Xu @ 2007-03-26 11:18 UTC (permalink / raw)
To: guile-user
Hi,
Swig could generate pointer types in C to smob. But users still have to
define smob related operations(like mark, free, etc) by hand?
--
William
It was a JOKE!! Get it?? I was receiving messages from DAVID LETTERMAN!!
YOW!!
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: about `smob' generated by swig
@ 2007-03-28 4:57 Marco Maggi
2007-03-28 8:17 ` William Xu
0 siblings, 1 reply; 5+ messages in thread
From: Marco Maggi @ 2007-03-28 4:57 UTC (permalink / raw)
To: guile-user
"William Xu" wrote:
> Swig could generate pointer types in C to smob. But users
> still have to define smob related operations(like mark,
> free, etc) by hand?
Mh, no. I have never used SWIG but if I read [1] and [2]
and by inspecting "Examples/guile" in the source
distribution of SWIG 1.3.31, it seems to me that every
unknown data type used as parameter to functions is treated
like a pointer.
[1] <http://www.swig.org/Doc1.1/HTML/SWIG.html#n3>
[2] "swig-1.3.31/Doc/Manual/Guile.html"
That is: SWIG generates a SMOB holding two values:
1 - the pointer to the data instance;
2 - a string holding the name of the unknown type;
and uses that as reference to the unknown type; the data
instance itself is just a block of memory, it is *not*
wrapped in an automatically defined SMOB. Let's call the
SWIG generated SMOB: 'reference' SMOB. A reference SMOB is
of a type defined by SWIG, so we have to do nothing to
handle its memory: by looking in a "*_wrap.c" file I see
that there are SMOB type definitions whose drivers are
referenced by variables like 'swig_tag' and
'swig_collectable_tag', and SWIG implements the driver
functions for them.
When SWIG processes a function that has some C language
type as argument or return value, it just uses the
corresponding SMOB type as defined by Guile to handle it, so
we have to do nothing.
When SWIG processes a function that has unknown types as
argument or return value, it wraps the function with one
that uses reference SMOBs.
The reference SMOB drivers have no mark function. AFAICS
there is no way to tell SWIG to invoke a mark function to
mark fields in a custom data structure; that is: if a
function builds and returns a structure:
struct my_type_t {
int a;
SCM b;
};
there is no way to mark 'b'. We have to register it with
'scm_gc_protect_object()'.
It is my understanding that it is possible to register a
destroy function to be invoke when garbage collection runs,
to free the data referenced by a reference SMOB; but I was
not able to find how to do it.
Anyway a destructor for custom data referenced by
reference SMOBs has to be written, and then you can use it
in a guardian and with 'after-gc-hook'.
By the way: to write a SMOB driver is not difficult if
you know some C language. Are you sure that you need
SWIG?
--
Marco Maggi
"They say jump!, you say how high?"
Rage Against the Machine - "Bullet in the Head"
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: about `smob' generated by swig
2007-03-28 4:57 Marco Maggi
@ 2007-03-28 8:17 ` William Xu
0 siblings, 0 replies; 5+ messages in thread
From: William Xu @ 2007-03-28 8:17 UTC (permalink / raw)
To: guile-user
"Marco Maggi" <marco.maggi-ipsu@poste.it> writes:
> "William Xu" wrote:
>> Swig could generate pointer types in C to smob. But users
>> still have to define smob related operations(like mark,
>> free, etc) by hand?
>
> Mh, no. I have never used SWIG but if I read [1] and [2]
> and by inspecting "Examples/guile" in the source
> distribution of SWIG 1.3.31, it seems to me that every
> unknown data type used as parameter to functions is treated
> like a pointer.
>
> [1] <http://www.swig.org/Doc1.1/HTML/SWIG.html#n3>
> [2] "swig-1.3.31/Doc/Manual/Guile.html"
>
> That is: SWIG generates a SMOB holding two values:
>
> 1 - the pointer to the data instance;
> 2 - a string holding the name of the unknown type;
Yes, it's more like a smob type pointer. Consider this,
void bar(unsigned char *s)
{
printf("s = %s\n", s);
}
One problem is that how i create and pass a `unsigned char*' parameter
to `bar'. If SWIG requires me to write smob creation myself, that's a
pain...
> By the way: to write a SMOB driver is not difficult if
> you know some C language. Are you sure that you need
> SWIG?
As we know, one of guile or scheme's big shortcomings is lack of
libraries. On the contrary, C libraries are pretty full. Hence, if SWIG
can do a good job on wrapping C codes for guile, that would really be
great..
--
William
I used to be disgusted, now I find I'm just amused.
-- Elvis Costello
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: about `smob' generated by swig
@ 2007-03-29 5:34 Marco Maggi
2007-04-01 5:28 ` William Xu
0 siblings, 1 reply; 5+ messages in thread
From: Marco Maggi @ 2007-03-29 5:34 UTC (permalink / raw)
To: guile-user
"William Xu" wrote:
> Yes, it's more like a smob type pointer. Consider this,
>
> void bar(unsigned char *s)
> {
> printf("s = %s\n", s);
> }
>
> One problem is that how i create and pass a `unsigned
> char*' parameter to `bar'. If SWIG requires me to write
> smob creation myself, that's a pain...
AFAICT you have to write a C constructor:
unsigned char *
make_one_thing (int dim)
{
unsigned char * p = malloc(dim);
put_something_in(p);
return p;
}
and SWIG will generate the Scheme/C wrapper, something
like:
static SCM
_wrap_make_one_thing (SCM s_0)
{
unsigned char * result = 0 ;
int arg0;
SCM gswig_result;
arg0 = scm_to_int(s_0);
result = (unsigned char *)new_matrix(arg0);
gswig_result = SWIG_NewPointerObj (result,
SWIGTYPE_p_unsigned_char, 0);
return gswig_result;
}
so you do not have to write the SMOB driver.
--
Marco Maggi
"They say jump!, you say how high?"
Rage Against the Machine - "Bullet in the Head"
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-04-01 5:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-26 11:18 about `smob' generated by swig William Xu
-- strict thread matches above, loose matches on Subject: below --
2007-03-28 4:57 Marco Maggi
2007-03-28 8:17 ` William Xu
2007-03-29 5:34 Marco Maggi
2007-04-01 5:28 ` William Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).