On Tue, May 4, 2010 at 12:43 PM, Sergey Bochkanov
<sergey.bochka...@alglib.net> wrote:
> Hello, Gonzalo.
>
> You wrote 3 мая 2010 г., 20:46:41:
>
>> Although I'm more of a GPL (v2) type, and I wouldn't write BSD code
>> unless I had a very good reason, I could consider relicensing some
>> interface code like this.
>> I've actually relicensed this code to LGPL v2+ (for gmpy), but I'm not
>> sure I can go farther than that, since my code was based on GMP code
>> (itself LGPL v2+ at the time).
>
> There are exist two related conversion problems:
> 1) pylong <-> mpz conversion
> 2) pylong <-> "usual C-long" conversion
>
> (1)  is very useful for MPIR-related stuff, while (2) may be used both
> for  "Python  <->  MPIR"  and  for  general  "Python  <-> C" interface
> construction  problem.
>
> Looks  like that mpz_pylong.c/mpn_pylong.c units solve first problem -
> but  not  second  one. But (2) may be efficiently solved with standard
> PyLong_AsUnsignedLong(). Am I right?

The fastest conversion I've found is to use PyLong_AsLongAndOverflow
and then call mpz_set_PyLong (or raise an error) if overflow is set.
This approach is faster than allowing PyLong_As... to raise an
exception and then clearing the exception before calling
mpz_set_PyLong. The drawback is that PyLong_AsLongAndOverflow is only
support is Python 2.7 and later. In gmpy, there is a file
py3intcompat.c that provides a version of PyLong_AsLongAndOverflow for
older versions of Python. There is also an implementation of
PyLong_AsLongLongAndOverflow that could be helpful for Win64.

casevh

>
> Obviously, "pylong <-> mpz" will be used only by MPIR wrapper which is
> LGPL, so LGPL 2.1 is OK for me. Could you send me 2.1-licensed version
> of these files, if you OK with 2.1?
>
> --
> With best regards,
>  Sergey                          mailto:sergey.bochka...@alglib.net
>
> --
> You received this message because you are subscribed to the Google Groups 
> "mpir-devel" group.
> To post to this group, send email to mpir-de...@googlegroups.com.
> To unsubscribe from this group, send email to 
> mpir-devel+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/mpir-devel?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"mpir-devel" group.
To post to this group, send email to mpir-de...@googlegroups.com.
To unsubscribe from this group, send email to 
mpir-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/mpir-devel?hl=en.

Reply via email to