egallesio / STklos

STklos Scheme
http://stklos.net
GNU General Public License v2.0
67 stars 17 forks source link

Customize `class-of` and `describe` for bitvectors #619

Closed jpellegrini closed 5 months ago

jpellegrini commented 5 months ago
stklos> (import (srfi 178))
stklos> #*11
stklos> (class-of #*11)

Program received signal SIGSEGV, Segmentation fault.

This is because #*11 is of a type which is only defined in srfi-178.c, and object.c can't tell what it is.

We do as we did in SRFI 25, and customize class-of and describe for bitvectors.

jpellegrini commented 5 months ago

But it's still strange that it segfaults without this patch.

DEFINE_PRIMITIVE("class-of", class_of, subr1, (SCM obj))
{
...
  if (HAS_USER_TYPEP(obj)) {
    SCM tmp = STk_extended_class_of(obj);
    if (tmp) return tmp;
  }
...
  return UnknownClass;
}

So it should return UnknownClass.

Anyway, the patch seems to work well for bitvectors.

egallesio commented 5 months ago

But it's still strange that it segfaults without this patch.

DEFINE_PRIMITIVE("class-of", class_of, subr1, (SCM obj))
{
...
  if (HAS_USER_TYPEP(obj)) {
    SCM tmp = STk_extended_class_of(obj);
    if (tmp) return tmp;
  }
...
  return UnknownClass;
}

So it should return UnknownClass.

Anyway, the patch seems to work well for bitvectors.

This is my fault. I have extended STk_extended_class_of: we can now have a class or a function which returns a class. I forgot to test if the value is NULL. I correct this immediately and I'll merge your PR. Thanks for seeing this @jpellegrini .