[#105104] [Ruby master Bug#18141] Marshal load with proc yield strings before they are fully initialized — "byroot (Jean Boussier)" <noreply@...>

Issue #18141 has been reported by byroot (Jean Boussier).

10 messages 2021/09/01

[#105114] [Ruby master Feature#18143] Add a new method to change GC.stress only in the given block such as GC.with_stress(flag) {...} — "kou (Kouhei Sutou)" <noreply@...>

Issue #18143 has been reported by kou (Kouhei Sutou).

8 messages 2021/09/02

[#105180] [Ruby master Bug#18156] 3.0.2 configuration checks by default for C++ compiler instead of C? — "vo.x (Vit Ondruch)" <noreply@...>

Issue #18156 has been reported by vo.x (Vit Ondruch).

11 messages 2021/09/08

[#105191] [Ruby master Bug#18159] Integrate functionality of dead_end gem into Ruby — duerst <noreply@...>

Issue #18159 has been reported by duerst (Martin Dst).

37 messages 2021/09/11

[#105269] [Ruby master Bug#18169] Local copies of gemified libraries are being released out of sync with their gems — "headius (Charles Nutter)" <noreply@...>

Issue #18169 has been reported by headius (Charles Nutter).

15 messages 2021/09/15

[#105276] [Ruby master Bug#18170] Exception#inspect should not include newlines — "mame (Yusuke Endoh)" <noreply@...>

Issue #18170 has been reported by mame (Yusuke Endoh).

29 messages 2021/09/16

[#105310] [Ruby master Misc#18174] DevelopersMeeting20211021Japan — "mame (Yusuke Endoh)" <noreply@...>

Issue #18174 has been reported by mame (Yusuke Endoh).

14 messages 2021/09/16

[#105313] [Ruby master Misc#18175] Propose Jean Boussier (@byroot) as a core committer — "tenderlovemaking (Aaron Patterson)" <noreply@...>

Issue #18175 has been reported by tenderlovemaking (Aaron Patterson).

11 messages 2021/09/16

[#105354] [Ruby master Feature#18181] Introduce Enumerable#min_with_value, max_with_value, and minmax_with_value — "kyanagi (Kouhei Yanagita)" <noreply@...>

Issue #18181 has been reported by kyanagi (Kouhei Yanagita).

16 messages 2021/09/20

[#105361] [Ruby master Feature#18183] make SecureRandom.choose public — "olleicua (Antha Auciello)" <noreply@...>

Issue #18183 has been reported by olleicua (Antha Auciello).

17 messages 2021/09/21

[#105377] [Ruby master Bug#18187] Float#clamp() returns ArgumentError (comparison of Float with 1 failed) — "SouravGoswami (Sourav Goswami)" <noreply@...>

Issue #18187 has been reported by SouravGoswami (Sourav Goswami).

7 messages 2021/09/22

[#105391] [Ruby master Bug#18189] `rb_cString` can be NULL during `Init_Object` — "ioquatix (Samuel Williams)" <noreply@...>

Issue #18189 has been reported by ioquatix (Samuel Williams).

9 messages 2021/09/23

[#105428] [Ruby master Bug#18194] No easy way to format exception messages per thread/fiber scheduler context. — "ioquatix (Samuel Williams)" <noreply@...>

Issue #18194 has been reported by ioquatix (Samuel Williams).

16 messages 2021/09/26

[#105450] [Ruby master Feature#18228] Add a `timeout` option to `IO.copy_stream` — "byroot (Jean Boussier)" <noreply@...>

Issue #18228 has been reported by byroot (Jean Boussier).

11 messages 2021/09/27

[#105452] [Ruby master Feature#18229] Proposal to merge YJIT — "maximecb (Maxime Chevalier-Boisvert)" <noreply@...>

Issue #18229 has been reported by maximecb (Maxime Chevalier-Boisvert).

21 messages 2021/09/27

[#105500] [Ruby master Feature#18231] `RubyVM.keep_script_lines` — "ko1 (Koichi Sasada)" <noreply@...>

Issue #18231 has been reported by ko1 (Koichi Sasada).

19 messages 2021/09/30

[#105504] [Ruby master Bug#18232] Ractor.make_shareable is broken in code loaded with RubyVM::InstructionSequence.load_from_binary — "byroot (Jean Boussier)" <noreply@...>

Issue #18232 has been reported by byroot (Jean Boussier).

7 messages 2021/09/30

[ruby-core:105152] [Ruby master Bug#18007] Help developers of C extensions meet requirements in "doc/extension.rdoc"

From: "nagachika (Tomoyuki Chikanaga)" <noreply@...>
Date: 2021-09-05 05:56:10 UTC
List: ruby-core #105152
Issue #18007 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED to 2.6: REQUIRED, 2.7: REQUIRED, 3.0: DONE

ruby_3_0 c42208f8e24402fe1aa8747901fba275bfb0d56b merged revision(s) c0f4e4ca6d0f76985bca79314b232b787c8f008e.

----------------------------------------
Bug #18007: Help developers of C extensions meet requirements in "doc/extension.rdoc"
https://bugs.ruby-lang.org/issues/18007#change-93559

* Author: mdalessio (Mike Dalessio)
* Status: Closed
* Priority: Normal
* Backport: 2.6: REQUIRED, 2.7: REQUIRED, 3.0: DONE
----------------------------------------
A pull request for this feature has been submitted at https://github.com/ruby/ruby/pull/4604

## Problem being solved

This option is intended to help developers of C extensions to check if their code meets the requirements explained in "doc/extension.rdoc". Specifically, I want to ensure that `T_DATA` object classes undefine or redefine the alloc function.

https://github.com/ruby/ruby/blob/6963f8f743b42f9004a0879cd66c550f18987352/doc/extension.rdoc#label-Write+the+C+Code says:
> Since Object.allocate allocates an ordinary T_OBJECT type (instead of T_DATA), it's important to either use rb_define_alloc_func() to overwrite it or rb_undef_alloc_func() to delete it.

(note: which matters when using TypedData_Make_Struct/TypedData_Wrap_Struct as the native pointer is supplied without calling the class alloc function).

There is currently no easy way for an author of a C extension to easily see where they have made the mistake of letting the default alloc function remain for their class (and therefore `class.new` creating a T_OBJECT instead of T_DATA and not setting the data pointer).

## Description of the solution

Compiled with this option, Ruby will warn when a `T_DATA` object is created whose class has not undefined or redefined the alloc function.

A new function is defined, `rb_data_object_check`. That function is called from `rb_data_object_wrap()` and
`rb_data_typed_object_wrap()` (which implement the `Data_Wrap_Struct` family of macros).

The warning, when emitted, looks like this:

```
warning: T_DATA class Nokogiri::XML::Document should undefine or redefine the alloc function, please see doc/extension.rdoc
```

## Examples of this problem in the wild

Using this option, I found that [many of Nokogiri's classes needed to undefine `allocate`](https://github.com/sparklemotion/nokogiri/commit/c5ba3a5).

This PR also updates these core Ruby classes by undefining `allocate`:

- `ObjectSpace::InternalObjectWrapper`
- `Socket::Ifaddr`

## Questions for reviewers

__Does this check really need to be behind a configuration option?__ Performance impact is very small (see benchmarks below), but I put it behind a flag because I am worried that there may be a many C extensions that would emit warnings at runtime, and the users of those extensions cannot fix the problem and so would mostly just be annoyed.

__Should this warning be emitted with the `deprecated` category?__

## Benchmarking

I benchmarked this code by allocating `Nokogiri::XML::NodeSet`s in a loop. This is a class with a [relatively simple `allocate` function](https://github.com/sparklemotion/nokogiri/blob/6d688d8c0f3351797e9576d3710acf458582bb30/ext/nokogiri/xml_node_set.c#L441-L464).

The runs cover the four combinations of enabled/disabled, and warnings/no-warnings.

```
ruby 3.1.0dev (2021-06-25T04:02:18Z flavorjones-extens.. de943189aa) [x86_64-linux]
Warming up --------------------------------------
disabled, warn=false   490.143k i/100ms
Calculating -------------------------------------
disabled, warn=false      4.863M (1.5%) i/s -     49.014M in  10.081177s

ruby 3.1.0dev (2021-06-25T04:02:18Z flavorjones-extens.. de943189aa) [x86_64-linux]
Warming up --------------------------------------
 disabled, warn=true   483.070k i/100ms
Calculating -------------------------------------
 disabled, warn=true      4.839M (ア 1.4%) i/s -     48.790M in  10.083899s

Comparison:
disabled, warn=false:  4863064.0 i/s
 disabled, warn=true:  4839310.1 i/s - same-ish: difference falls within error


ruby 3.1.0dev (2021-06-25T04:02:18Z flavorjones-extens.. de943189aa) [x86_64-linux]
Warming up --------------------------------------
 enabled, warn=false   484.398k i/100ms
Calculating -------------------------------------
 enabled, warn=false      4.840M (ア 1.9%) i/s -     48.440M in  10.011854s

Comparison:
disabled, warn=false:  4863064.0 i/s
 enabled, warn=false:  4840123.2 i/s - same-ish: difference falls within error
 disabled, warn=true:  4839310.1 i/s - same-ish: difference falls within error


ruby 3.1.0dev (2021-06-25T04:02:18Z flavorjones-extens.. de943189aa) [x86_64-linux]
Warming up --------------------------------------
  enabled, warn=true   492.200k i/100ms
Calculating -------------------------------------
  enabled, warn=true      4.866M (ア 2.1%) i/s -     48.728M in  10.017455s

Comparison:
  enabled, warn=true:  4866434.8 i/s
disabled, warn=false:  4863064.0 i/s - same-ish: difference falls within error
 enabled, warn=false:  4840123.2 i/s - same-ish: difference falls within error
 disabled, warn=true:  4839310.1 i/s - same-ish: difference falls within error
```

My conclusion is that the performance impact is very small, and we could omit the option if the Ruby core maintainers decide this behavior should be on by default.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next