Skip to content

Customize class-of and describe for bitvectors #619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 20, 2024

Conversation

jpellegrini
Copy link
Contributor

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.

```
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 jpellegrini changed the title Customize class-of and describe for bitvectors Customize class-of and describe for bitvectors Jan 19, 2024
@jpellegrini
Copy link
Contributor Author

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
Copy link
Owner

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 .

egallesio added a commit that referenced this pull request Jan 20, 2024
`class-of` sigfaults when `class_of` field o the extended type is NULL
@egallesio egallesio merged commit 3e0828a into egallesio:master Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants