Project

General

Profile

Actions

Feature #14168

closed

C call to raise FrozenError

Added by tagomoris (Satoshi Tagomori) over 6 years ago. Updated over 6 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:84208]

Description

Currently we need to check the object is frozen or not by isFrozen and raise error (RuntimeError or FrozenError) under its own responsibility.
Providing such c function makes us to write much safer code/extensions.

/* now */
if (OBJ_FROZEN(self)) {
    rb_raise(rb_eRuntimeError, "can't modify frozen Factory");
}

/* what I want to do */
assert_is_not_frozen("MyAwesomeClass"); // raises RuntimeError (~2.4) or FrozenError (2.5~) if it is frozen
// or
assert_is_not_frozen(self); // classname? self VALUE?

I want to reduce macros for ruby versions in out C extensions, so this feature will help us so much.

Updated by tagomoris (Satoshi Tagomori) over 6 years ago

Naruse told me about rb_check_frozen(), and it completely works as I expected.
Please close this ticket.

tagomoris (Satoshi TAGOMORI) wrote:

Currently we need to check the object is frozen or not by isFrozen and raise error (RuntimeError or FrozenError) under its own responsibility.
Providing such c function makes us to write much safer code/extensions.

/* now */
if (OBJ_FROZEN(self)) {
    rb_raise(rb_eRuntimeError, "can't modify frozen Factory");
}

/* what I want to do */
assert_is_not_frozen("MyAwesomeClass"); // raises RuntimeError (~2.4) or FrozenError (2.5~) if it is frozen
// or
assert_is_not_frozen(self); // classname? self VALUE?

I want to reduce macros for ruby versions in out C extensions, so this feature will help us so much.

Actions #2

Updated by tagomoris (Satoshi Tagomori) over 6 years ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0