Closed basiliscos closed 6 years ago
What about returning the same rop aswell to make the usage of convert more functional?
Hm, it seems we need 2 params then - number of written words AND the rop
?
You slice rop
into a potentially smaller array as
return rop[0 .. writeCount]
provided that writeCount <= rop.length
and typeof(rop[0])
is mpz word type.
Okay, got it, will do (a bit later) today.
The version with gc-allocating slice should have signature like
T[] convert(T)(WordOrder order, size_t size, Endianess endian, size_t nails)?
right?
Yes, except that the size
parameter is not needed since it is the word-size, which in your case is T.sizeof
.
The documentation of mpz_import
is an excellent (terrible) example of faith-based programming which no language tries to mimic anymore. It's not at all easy to decode how all these parameters will be combined. I'll have to think about this for a while.
Best way to test this is to write a loop that mpz_exports and then mpz_imports a large set of numbers and then checks that you get back in the import what you sent into the export. I'd pick a set of odd numbers such as 0, +-1, +-3, +-9, +-27, etc.
Error: setting length in @nogc function gmp.z._MpZ!false._MpZ.convert!ubyte.convert may cause a GC allocation
How to disablle @nogc:
attribute for the 2nd convert
version?
Unfortunately there is no way disable @nogc:
. Can you move the convert function up to before the definition of @nogc
?
Note that @nogc:
is not needed as that attribute is inferred on all the members in template structs, in our case _MpZ(bool copyable = false)
. But I'm keeping it here for now just to make sure that I don't accidentally make use of GC-allocations when I shouldn't.
Yeah, that's looks good!
Can we merge the current PR? I plan to do mpz_import
as separate PR
Done! Thanks. Ok to go ahead with import now!
Why do you prefer the naming convert? The standard naming is 'to' defined in std.conv.
Why do you prefer the naming convert? The standard naming is 'to' defined in std.conv.
Well, I was'nt aware of to
. Could you, please, fix it?
Yep. Shall we call the static factory function (that wraps mpz_import
) from
then?
Okay, if from
suits more. I was sure that simple constructor should be enough.
Use a normal constructor for now, I'm not certain what's best in this case.
I asked the forums about what's the best naming in this case. We can wait and see which ideas that get the most votes at: https://forum.dlang.org/post/nsoomaqffwffgovlboma@forum.dlang.org
Here is a first attempt. Please, share your opinion.
I also will need of
mpz_import
, but I think about implemeinting it as a constructor