Author: Amaury Forgeot d'Arc <[email protected]>
Branch: decimal-libmpdec
Changeset: r73802:f104883f9752
Date: 2014-09-28 18:38 +0200
http://bitbucket.org/pypy/pypy/changeset/f104883f9752/

Log:    More functions

diff --git a/pypy/module/_decimal/interp_decimal.py 
b/pypy/module/_decimal/interp_decimal.py
--- a/pypy/module/_decimal/interp_decimal.py
+++ b/pypy/module/_decimal/interp_decimal.py
@@ -265,7 +265,7 @@
     def _recode_to_utf8(self, ptr):
         s = rffi.charp2str(ptr)
         if len(s) == 0 or (len(s) == 1 and 32 <= ord(s[0]) < 128):
-            return None, ptr
+            return lltype.nullptr(rffi.CCHARP.TO), ptr
         # XXX use mbstowcs()
         s = s
         ptr = rffi.str2charp(s)
@@ -816,6 +816,22 @@
         return binary_method(space, mpd_func, w_self, w_other, w_context)
     return interp2app(descr_method)
 
+# Binary function, optional context arg for conversion errors.
+def binary_method_noctx(space, mpd_func, w_self, w_other, w_context):
+    self = space.interp_w(W_Decimal, w_self)
+    context = convert_context(space, w_context)
+    w_a, w_b = convert_binop_raise(space, context, w_self, w_other)
+    w_result = W_Decimal.allocate(space)
+    mpd_func(w_result.mpd, w_a.mpd, w_b.mpd)
+    return w_result
+    
+def make_binary_method_noctx(mpd_func_name):
+    mpd_func = getattr(rmpdec, mpd_func_name)
+    @func_renamer('descr_%s' % mpd_func_name)
+    def descr_method(space, w_self, w_other, w_context=None):
+        return binary_method_noctx(space, mpd_func, w_self, w_other, w_context)
+    return interp2app(descr_method)
+
 def convert_context(space, w_context):
     if space.is_none(w_context):
         return interp_context.getcontext(space)
@@ -1134,6 +1150,8 @@
     is_normal = interp2app(W_Decimal.is_normal_w),
     is_subnormal = interp2app(W_Decimal.is_subnormal_w),
     # Binary functions, optional context arg for conversion errors
+    compare_total = make_binary_method_noctx('mpd_compare_total'),
+    compare_total_mag = make_binary_method_noctx('mpd_compare_total_mag'),
     copy_sign = interp2app(W_Decimal.copy_sign_w),
     #
     as_tuple = interp2app(W_Decimal.as_tuple_w),
diff --git a/rpython/rlib/rmpdec.py b/rpython/rlib/rmpdec.py
--- a/rpython/rlib/rmpdec.py
+++ b/rpython/rlib/rmpdec.py
@@ -52,6 +52,7 @@
         "mpd_isnormal", "mpd_issubnormal", "mpd_isspecial", "mpd_iscanonical",
         "mpd_isnan", "mpd_issnan", "mpd_isqnan",
         "mpd_qcmp", "mpd_qcompare", "mpd_qcompare_signal",
+        "mpd_compare_total", "mpd_compare_total_mag",
         "mpd_qmin", "mpd_qmax", "mpd_qmin_mag", "mpd_qmax_mag",
         "mpd_qnext_minus", "mpd_qnext_plus", "mpd_qnext_toward",
         "mpd_qquantize", "mpd_qreduce",
@@ -277,6 +278,12 @@
 mpd_qcompare_signal = external(
     'mpd_qcompare_signal',
     [MPD_PTR, MPD_PTR, MPD_PTR, MPD_CONTEXT_PTR, rffi.UINTP], lltype.Void)
+mpd_compare_total = external(
+    'mpd_compare_total',
+    [MPD_PTR, MPD_PTR, MPD_PTR], lltype.Void)
+mpd_compare_total_mag = external(
+    'mpd_compare_total_mag',
+    [MPD_PTR, MPD_PTR, MPD_PTR], lltype.Void)
 
 mpd_qmin = external(
     'mpd_qmin',
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to