From: Martin Bosslet Date: 2012-02-26T00:51:10+09:00 Subject: [ruby-core:42921] [ruby-trunk - Feature #6065] Allow Bignum marshalling/unmarshalling from C API Issue #6065 has been updated by Martin Bosslet. Akira Tanaka wrote: > 2012/2/25 Martin Bosslet : > I don't think rb_big_pack/rb_big_unpack is tightly coupled to > internal of Bignum. > What the points they expose internal of Bignum? I meant that it would become tightly coupled without further comment on the expected transfer format. If the internal representation happens to be exactly the same as the one we hand to externals, and there is no further comment, this part of the interface could be easily overlooked when we change something with the internal representation in the future. I think basically we are on the same side, it's just me having trouble to express myself precisely enough :) I wanted to point out the fact that even if internal and external representation would happen to be the same we should already treat them as two separate things in our mind and be aware that the external representation would be fixed the moment we publish the functionality in public API. > Note that the format is written in a comment in bignum.c. You're right, the comment there would already specify the format, but I think what Yusuke proposed (copying gmplib's approach) would be the perfect solution in my eyes, suiting anybody's needs - a client can simply choose what format they want to have. Additionally, its dynamic nature would already enforce a clear separation between internal and external representation. ---------------------------------------- Feature #6065: Allow Bignum marshalling/unmarshalling from C API https://bugs.ruby-lang.org/issues/6065 Author: Martin Bosslet Status: Assigned Priority: Normal Assignee: Kenta Murata Category: core Target version: 2.0.0 Currently, there's no public C API to create a Bignum. There is rb_big_pack and rb_big_unpack that will do the job, but they are not portable. Could we offer public functionality that is independent of the internal representation for the task of marshaling/unmarshalling a Bignum to raw C data types? I'd like to propose something like - creating a bignum: VALUE rb_big_from_ary(unsigned long *longs, size_t num_longs, int signed) - retrieving a representation of a Bignum (longs are allocated): size_t rb_big_to_ary(VALUE big, unsigned long **longs, int *signed) For getting a representation, rb_big2str could also be used, but the above would simplify things when developing an extension that is in need of Bignum support. Names and signatures are of course open for discussion, the example should just serve as an indication of what I'm aiming at. To avoid ambiguity, it would have to be defined how the longs are ordered and how the signed flag is to be interpreted - I would suggest a very simple representation: Let "longs" be the representation of the absolute value of the bignum in little- or big-endian order, where each of the longs themselves should probably be in the same order, in order to eliminate ambivalence. Signed is either 0 or 1, so no two's complement or anything involved. I would volunteer to provide a patch for this if we would agree on something. -- http://bugs.ruby-lang.org/