unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Inheriting from foreign objects
@ 2002-04-09 18:21 Andreas Rottmann
  2002-04-10 19:47 ` Neil Jerram
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Rottmann @ 2002-04-09 18:21 UTC (permalink / raw)


Hi!

I have run into a problem: I create classes from C (C++) using
scm_make_class(). These classes all get the SCM_CLASSF_FOREIGN bit set
to treat them as foreign objects (like invoke the constructor &
desctructor supplied). 

So far, so good. However, when I derive from these classes (on the
Scheme level), the new class has also the FOREIGN bit set (it's
inherited in scm_sys_inherit_magic_x(), AFAICT), but the constructor
set NULL, which causes %allocate-instance bails out when trying to
instantiate the class.

Is there a way I can cleanly derive from C-created classes?

BTW, I'm using the current CVS code.

Regards, Andy
-- 
Andreas Rottmann         | Dru@ICQ        | 118634484@ICQ | a.rottmann@gmx.at
http://www.8ung.at/rotty | GnuPG Key: http://www.8ung.at/rotty/gpg.asc
Fingerprint              | DFB4 4EB4 78A4 5EEE 6219  F228 F92F CFC5 01FD 5B62

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Inheriting from foreign objects
  2002-04-09 18:21 Inheriting from foreign objects Andreas Rottmann
@ 2002-04-10 19:47 ` Neil Jerram
  2002-04-23 20:43   ` Thien-Thi Nguyen
  0 siblings, 1 reply; 5+ messages in thread
From: Neil Jerram @ 2002-04-10 19:47 UTC (permalink / raw)
  Cc: guile-devel

>>>>> "Andreas" == Andreas Rottmann <a.rottmann@gmx.at> writes:

    Andreas> Hi!
    Andreas> I have run into a problem: I create classes from C (C++) using
    Andreas> scm_make_class(). These classes all get the SCM_CLASSF_FOREIGN bit set
    Andreas> to treat them as foreign objects (like invoke the constructor &
    Andreas> desctructor supplied). 

    Andreas> So far, so good. However, when I derive from these classes (on the
    Andreas> Scheme level), the new class has also the FOREIGN bit set (it's
    Andreas> inherited in scm_sys_inherit_magic_x(), AFAICT), but the constructor
    Andreas> set NULL, which causes %allocate-instance bails out when trying to
    Andreas> instantiate the class.

    Andreas> Is there a way I can cleanly derive from C-created classes?

I'd say you're in virgin territory here, and that any advice you can
give on such problems, and on defining a C API for GOOPS, would be
very useful.

(Sorry that wasn't much help!  Good luck.)

        Neil


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Inheriting from foreign objects
  2002-04-10 19:47 ` Neil Jerram
@ 2002-04-23 20:43   ` Thien-Thi Nguyen
  2002-04-30 10:23     ` Andreas Rottmann
  0 siblings, 1 reply; 5+ messages in thread
From: Thien-Thi Nguyen @ 2002-04-23 20:43 UTC (permalink / raw)
  Cc: guile-devel, guile-user

   From: Neil Jerram <neil@ossau.uklinux.net>
   Date: 10 Apr 2002 20:47:13 +0100

       Andreas> Is there a way I can cleanly derive from C-created classes?

   I'd say you're in virgin territory here, and that any advice you can
   give on such problems, and on defining a C API for GOOPS, would be
   very useful.

it looks like foreign bit is set when superclass list is empty.  perhaps
a good guideline would be to use at least `(list <object>)' for `supers'
for normal operation.  btw, it doesn't look like user-supplied ctor/dtor
are suppressed based on foreign bit in any case.

[cc guile-user in order to ask survey question: which goops-related C
functions do people use now?  the answer to this helps shape definition
of the C interface to goops -- thanks!]

thi


_______________________________
SCM
scm_make_class (SCM meta, char *s_name, SCM supers, size_t size,
		void * (*constructor) (SCM initargs),
		size_t (*destructor) (void *))
{
  SCM name, class;
  name = scm_str2symbol (s_name);
  if (SCM_NULLP (supers))
    supers = scm_list_1 (scm_class_foreign_object);
  class = scm_basic_basic_make_class (meta, name, supers, SCM_EOL);
  scm_sys_inherit_magic_x (class, supers);

  if (destructor != 0)
    {
      SCM_SET_SLOT (class, scm_si_destructor, (SCM) destructor);
      SCM_SET_CLASS_DESTRUCTOR (class, scm_free_foreign_object);
    }
  else if (size > 0)
    {
      SCM_SET_CLASS_DESTRUCTOR (class, scm_struct_free_light);
      SCM_SET_CLASS_INSTANCE_SIZE (class, size);
    }

  SCM_SET_SLOT (class, scm_si_layout, scm_str2symbol (""));
  SCM_SET_SLOT (class, scm_si_constructor, (SCM) constructor);

  return class;
}

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Inheriting from foreign objects
  2002-04-23 20:43   ` Thien-Thi Nguyen
@ 2002-04-30 10:23     ` Andreas Rottmann
  2002-05-15 12:30       ` Thien-Thi Nguyen
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Rottmann @ 2002-04-30 10:23 UTC (permalink / raw)


Thien-Thi Nguyen <ttn@giblet.glug.org> writes:

>    From: Neil Jerram <neil@ossau.uklinux.net>
>    Date: 10 Apr 2002 20:47:13 +0100
> 
>        Andreas> Is there a way I can cleanly derive from C-created classes?
> 
>    I'd say you're in virgin territory here, and that any advice you can
>    give on such problems, and on defining a C API for GOOPS, would be
>    very useful.
> 
> it looks like foreign bit is set when superclass list is empty.  perhaps
> a good guideline would be to use at least `(list <object>)' for `supers'
> for normal operation.  

I can't test your statement, since I have switched to create a
'normal' class and have a special slot being a smob containing the
pointer to the C++ object.

> btw, it doesn't look like user-supplied ctor/dtor
> are suppressed based on foreign bit in any case.
> 
When you inherit from a 'foreign' class, the constructor/destructor
fields of the new class are set NULL.

I suggest you write some 'test' code that uses the various
goops-related C functions, as that would both make them easier to
understand and they can be validated this way.

> [cc guile-user in order to ask survey question: which goops-related C
> functions do people use now?  the answer to this helps shape definition
> of the C interface to goops -- thanks!]
> 
I use, in my C++ <-> GOOPS bindings:

scm_load_goops()
scm_make()
scm_basic_make_class()
scm_sys_allocate_instance()
scm_sys_initialize_object()
scm_slot_set_x()
SCM_IS_A_P()
scm_add_method()
scm_generic_function_methods()
scm_method_procedure()
scm_method_specializers()
scm_slot_exists_p()
scm_slot_ref()

I may have overlooked some.

BTW: Has anybody of the developers looked at my GOOPS-related
bugreport yet? Since I have included a program documenting the bug it
shouldn't be too hard to investigate...

Regards, Andy
-- 
Andreas Rottmann         | Dru@ICQ        | 118634484@ICQ | a.rottmann@gmx.at
http://www.8ung.at/rotty | GnuPG Key: http://www.8ung.at/rotty/gpg.asc
Fingerprint              | DFB4 4EB4 78A4 5EEE 6219  F228 F92F CFC5 01FD 5B62

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Inheriting from foreign objects
  2002-04-30 10:23     ` Andreas Rottmann
@ 2002-05-15 12:30       ` Thien-Thi Nguyen
  0 siblings, 0 replies; 5+ messages in thread
From: Thien-Thi Nguyen @ 2002-05-15 12:30 UTC (permalink / raw)
  Cc: guile-devel, guile-user

   From: Andreas Rottmann <a.rottmann@gmx.at>
   Date: 30 Apr 2002 12:23:06 +0200

   I suggest you write some 'test' code that uses the various
   goops-related C functions, as that would both make them easier to
   understand and they can be validated this way.

i've added "write goops test cases in C" under "Eventually" in the TODO.

   > [cc guile-user in order to ask survey question: which goops-related C
   > functions do people use now?  the answer to this helps shape definition
   > of the C interface to goops -- thanks!]
   > 
   I use, in my C++ <-> GOOPS bindings: [...]

recorded in $workbook/policy/api.text -- thanks.

   BTW: Has anybody of the developers looked at my GOOPS-related
   bugreport yet? Since I have included a program documenting the bug it
   shouldn't be too hard to investigate...

i believe this is bug `goops-1'.

thi

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-05-15 12:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-04-09 18:21 Inheriting from foreign objects Andreas Rottmann
2002-04-10 19:47 ` Neil Jerram
2002-04-23 20:43   ` Thien-Thi Nguyen
2002-04-30 10:23     ` Andreas Rottmann
2002-05-15 12:30       ` Thien-Thi Nguyen

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).