Project

General

Profile

Actions

Feature #6083

closed

Hide a Bignum definition

Added by ko1 (Koichi Sasada) over 12 years ago. Updated over 10 years ago.

Status:
Closed
Target version:
[ruby-core:42891]

Description

Now, the struct RBignum which is a definition of Bignum in C is located in include/ruby/ruby.h. It means we can't change implementation of Bignum. For example, using GMP as Bignum representation.

I propose to move the struct RBignum definition from include/ruby/ruby.h to bignum.c. I believe no one use struct RBignum directly (except core).

It has possibility to break binary compatibility.


Files

hide-bignum-internal.patch (4.66 KB) hide-bignum-internal.patch akr (Akira Tanaka), 02/12/2014 11:45 AM

Updated by naruse (Yui NARUSE) over 12 years ago

Binary hackers can handle C structs even if it is a hidden private struct.
So it should be enough simply to declare "struct RBignunm is not a public API".

Updated by kosaki (Motohiro KOSAKI) over 12 years ago

Binary hackers can handle C structs even if it is a hidden private struct.
So it should be enough simply to declare "struct RBignunm is not a public API".

I disagree. As far as we consider there is backdoor, every binary
compatibility effort are
not meaningful. But I believe it clearly has a worth.

Updated by mame (Yusuke Endoh) over 12 years ago

  • Status changed from Open to Assigned
  • Assignee set to matz (Yukihiro Matsumoto)

ko1 wrote:

I propose to move the struct RBignum definition from include/ruby/ruby.h to bignum.c. I believe no one use struct RBignum directly (except core).

Agreed.
I hope C API would be organized. This can be preliminary case.

naruse wrote:

Binary hackers can handle C structs even if it is a hidden private struct.
So it should be enough simply to declare "struct RBignunm is not a public API".

If you think so, it could be simpler.
README.EXT has no description about RBignum.
So we don't need to do anything.
But we can kindly do something.

--
Yusuke Endoh

Updated by ko1 (Koichi Sasada) over 12 years ago

Matz, what do you think about it?

Updated by matz (Yukihiro Matsumoto) about 12 years ago

  • Target version changed from 2.0.0 to 2.6

I am sorry but it's too late. I admit my fault.

Matz.

Updated by kosaki (Motohiro KOSAKI) about 12 years ago

Target version changed from 2.0.0 to next minor
I am sorry but it's too late. I admit my fault.

Matz, I don't like this decision. I believe we should choose next major
or 2.0.0. minor release should not have binary incompatibility as far
as possible.
Is this typo? If no, I'd like to propose pull it back. declaration
moving is not big task.

  • kosaki

Updated by ko1 (Koichi Sasada) about 12 years ago

(2012/10/31 0:31), KOSAKI Motohiro wrote:

Target version changed from 2.0.0 to next minor
I am sorry but it's too late. I admit my fault.

Matz, I don't like this decision. I believe we should choose next major
or 2.0.0. minor release should not have binary incompatibility as far
as possible.
Is this typo? If no, I'd like to propose pull it back. declaration
moving is not big task.

Maybe, we don't define what is major and what is minor.

On 2.0.x, we shouldn't change binary compatibility.
But 2.1.x or later, I think it is acceptable.
(and some people don't accept :))

--
// SASADA Koichi at atdot dot net

Updated by kosaki (Motohiro KOSAKI) about 12 years ago

On Wed, Oct 31, 2012 at 9:26 AM, SASADA Koichi wrote:

(2012/10/31 0:31), KOSAKI Motohiro wrote:

Target version changed from 2.0.0 to next minor
I am sorry but it's too late. I admit my fault.

Matz, I don't like this decision. I believe we should choose next major
or 2.0.0. minor release should not have binary incompatibility as far
as possible.
Is this typo? If no, I'd like to propose pull it back. declaration
moving is not big task.

Maybe, we don't define what is major and what is minor.

On 2.0.x, we shouldn't change binary compatibility.
But 2.1.x or later, I think it is acceptable.
(and some people don't accept :))

Ok, please ignore my last mail then. :)

Updated by Anonymous about 12 years ago

Hi,

In message "Re: [ruby-core:48640] Re: [ruby-trunk - Feature #6083] Hide a Bignum definition"
on Wed, 31 Oct 2012 15:31:08 +0900, KOSAKI Motohiro writes:

|> Target version changed from 2.0.0 to next minor
|> I am sorry but it's too late. I admit my fault.
|
|Matz, I don't like this decision. I believe we should choose next major
|or 2.0.0. minor release should not have binary incompatibility as far
|as possible.
|Is this typo? If no, I'd like to propose pull it back. declaration
|moving is not big task.

Hiding (or no hiding) Bignum definition would not change binary
compatibility, probably you mean source compatibility?

But keeping compatibility during the release cycle is important, I
admit. So I changed my mind. If there's no big opposition, I can
accept this proposal.

						matz.

Updated by matz (Yukihiro Matsumoto) about 12 years ago

  • Target version changed from 2.6 to 2.0.0

Updated by mame (Yusuke Endoh) about 12 years ago

  • Target version changed from 2.0.0 to 3.0

If there's no big opposition, I can accept this proposal.

Sorry, but I must voice big opposition.

Unfortunately, hiding RBignum will cause significant incompatibility.
The macro RBIGNUM_BDIGITS uses RBignum internally. Many extension
libraries actually uses RBIGNUM_BDIGITS to construct a bignum object.

So, to hide RBignum, we must carefully design a new alternative API
to construct a bignum. It will take a time.
Worse, source compatibility will break anyway because it is almost
impossible to make it the same as the current RBIGNUM_BDIGITS.

(Consider replacing the internal representation with GMP.
RBIGNUM_BDIGITS must malloc a BDIGIT array and export GMP into the
array. But no one will free the allocated memory.)

Thus, I'm moving this to "Next Major". Again, I'm sorry.

--
Yusuke Endoh

Updated by shyouhei (Shyouhei Urabe) about 12 years ago

+1 for next major.

No one is against this basic concept of hiding Bignums, meseems. It's just a bad timing for us.

Updated by ko1 (Koichi Sasada) about 12 years ago

(2012/11/01 11:05), shyouhei (Shyouhei Urabe) wrote:

+1 for next major.

+1 for next major or next minor.

We need discussion about how to break binary compatibility in another
thread :)

--
// SASADA Koichi at atdot dot net

Updated by mame (Yusuke Endoh) about 12 years ago

2012/11/2 SASADA Koichi :

(2012/11/01 11:05), shyouhei (Shyouhei Urabe) wrote:

+1 for next major.

+1 for next major or next minor.

We need discussion about how to break binary compatibility in another
thread :)

Note that this issue (#6083) will break source compatibility.

--
Yusuke Endoh

Updated by akr (Akira Tanaka) almost 11 years ago

I made a patch for this issue.

It just moves struct RBignum and related macros from include/ruby/ruby.h to internal.h, not bignum.c.
It is because other files (such as gc.c, marshal.c, etc.) access internal of struct RBignum.

Updated by matz (Yukihiro Matsumoto) almost 11 years ago

Even though this breaks source compatibility, it is worth changing it (to mark dangerous operation).
So go ahead.

Matz.

Updated by akr (Akira Tanaka) almost 11 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

Applied in changeset r44957.


  • include/ruby/ruby.h,
    internal.h,
    ext/-test-/bignum/bigzero.c: Hide a Bignum definition.
    [ruby-core:42891] [Feature #6083]

Updated by tenderlovemaking (Aaron Patterson) over 10 years ago

Hi,

r44957 breaks the sqlite3 gem. I guess it uses the RBIGNUM_LEN macro:

https://github.com/sparklemotion/sqlite3-ruby/blob/2070182f461f1e2d76b9d40aa45fed2d04e9a4d6/ext/sqlite3/statement.c#L271-274

What should we use as a replacement? @naruse (Yui NARUSE), I think you added this check to the sqlite3 gem:

https://github.com/sparklemotion/sqlite3-ruby/commit/7dbd82d3

Thanks!

Updated by akr (Akira Tanaka) over 10 years ago

nobu wrote a patch: https://github.com/nobu/sqlite3-ruby/compare/bignum-conversion?expand=1

I'm not sure the status to merge it to the upstream.
(I think the patch should be similified by removing code for nails != 0.)

Note that the original condition, RBIGNUM_LEN(result) * SIZEOF_BDIGITS <= 8, is wrong.
It tests -264 < x < 264 but it should test -263 <= x < 263 which accepts NUM2LL.

Updated by tenderlovemaking (Aaron Patterson) over 10 years ago

Ah, thanks! I think I can get it merged upstream.

Updated by nobu (Nobuyoshi Nakada) over 10 years ago

I've forgotten to push the latest commit, which removes unused code for nails != 0.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0