From 17f53ec11a29228a448065510d28a91d3c6415aa Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 4 Nov 2010 23:45:44 +0100 Subject: [PATCH] enable two-value form of builtin pow() --- Cython/Compiler/Builtin.py | 7 +++++++ tests/compile/builtinfuncs.pyx | 1 + tests/run/builtin_pow.pyx | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 tests/run/builtin_pow.pyx diff --git a/Cython/Compiler/Builtin.py b/Cython/Compiler/Builtin.py index 63609c2b..096af2e8 100644 --- a/Cython/Compiler/Builtin.py +++ b/Cython/Compiler/Builtin.py @@ -44,6 +44,7 @@ builtin_function_table = [ #('open', "ss", "O", "PyFile_FromString"), #('ord', "", "", ""), ('pow', "OOO", "O", "PyNumber_Power"), + ('pow', "OO", "O", "__Pyx_PyNumber_Power2"), #('range', "", "", ""), #('raw_input', "", "", ""), #('reduce', "", "", ""), @@ -152,6 +153,11 @@ builtin_structs_table = [ ]) ] +pow2_utility_code = UtilityCode( +proto = """ +#define __Pyx_PyNumber_Power2(a, b) PyNumber_Power(a, b, Py_None) +""") + getattr3_utility_code = UtilityCode( proto = """ static PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); /*proto*/ @@ -383,6 +389,7 @@ Py_XDECREF(__Pyx_PyFrozenSet_Type); __Pyx_PyFrozenSet_Type = NULL; builtin_utility_code = { 'exec' : pyexec_utility_code, 'getattr3' : getattr3_utility_code, + 'pow' : pow2_utility_code, 'intern' : intern_utility_code, 'set' : py23_set_utility_code, 'frozenset' : py23_set_utility_code, diff --git a/tests/compile/builtinfuncs.pyx b/tests/compile/builtinfuncs.pyx index 795826c8..096ee870 100644 --- a/tests/compile/builtinfuncs.pyx +++ b/tests/compile/builtinfuncs.pyx @@ -15,6 +15,7 @@ cdef int f() except -1: i = len(x) x = open(y, z) x = pow(y, z, w) + x = pow(y, z) x = reload(y) x = repr(y) setattr(x, y, z) diff --git a/tests/run/builtin_pow.pyx b/tests/run/builtin_pow.pyx new file mode 100644 index 00000000..8b4b4f04 --- /dev/null +++ b/tests/run/builtin_pow.pyx @@ -0,0 +1,32 @@ + +def pow3(a,b,c): + """ + >>> pow3(2,3,5) + 3 + >>> pow3(3,3,5) + 2 + """ + return pow(a,b,c) + +def pow3_const(): + """ + >>> pow3_const() + 3 + """ + return pow(2,3,5) + +def pow2(a,b): + """ + >>> pow2(2,3) + 8 + >>> pow2(3,3) + 27 + """ + return pow(a,b) + +def pow2_const(): + """ + >>> pow2_const() + 8 + """ + return pow(2,3) -- 2.26.2