Skip to content
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

Allow Class#allocate to be prohibited #5979

Merged
merged 1 commit into from Apr 10, 2023
Merged

Conversation

dearblue
Copy link
Contributor

@dearblue dearblue commented Apr 9, 2023

Calling Class#allocate with UnboundMethod#bind_call usually succeeds without problems.
If this behavior does not make us happy, we can now prohibit it with MRB_SET_INSTANCE_TT(klass, MRB_TT_UNDEF).

At the same time, it applies to the Binding, Complex, Data, Float, Integer, Method, Rational and UnboundMethod classes.

Calling `Class#allocate` with `UnboundMethod#bind_call` usually succeeds without problems.
If this behavior does not make us happy, we can now prohibit it with `MRB_SET_INSTANCE_TT(klass, MRB_TT_UNDEF)`.

At the same time, it applies to the `Binding`, `Complex`, `Data`, `Float`, `Integer`, `Method`, `Rational` and `UnboundMethod` classes.
@dearblue dearblue requested a review from matz as a code owner April 9, 2023 12:24
@matz matz merged commit 0df3e68 into mruby:master Apr 10, 2023
11 checks passed
@dearblue dearblue deleted the allocate-undef branch May 6, 2023 12:15
dearblue added a commit to dearblue/mruby that referenced this pull request Dec 22, 2023
The method introduced by mruby#5979 causes a fault by swapping classes.

```console
% bin/mruby -e 'Method = Proc; p Object.method(:inspect)'
zsh: segmentation fault (core dumped)  bin/mruby -e 'Method = Proc; p Object.method(:inspect)'
```

After applying this patch, a `TypeError` exception will be raised.

```console
% bin/mruby -e 'Method = Proc; p Object.method(:inspect)'
trace (most recent call last):
        [1] -e:1
-e:1:in method: allocation failure of Proc (TypeError)
```

However, if the `mrb_vtype` is the same object, the same care must still be taken as before.

```console
% bin/mruby -e 'Method = Binding; p method(:puts).eval("12345")'
trace (most recent call last):
        [1] -e:1
-e:1:in eval: wrong argument type nil (expected Proc) (TypeError)
```
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.

None yet

2 participants