@@ -197,6 +197,20 @@ static PyObject* wrap_ssizeobjargproc(ssizeobjargproc f, PyObject* a, PyObject*
197
197
return PyLong_FromLong (f (explicit_cast (a ), PyLong_AsSsize_t (size ), explicit_cast (b )));
198
198
}
199
199
200
+ /* very special case: operator '**' has an optional third arg */
201
+ static PyObject * wrap_pow (ternaryfunc f , ...) {
202
+ int nargs = polyglot_get_arg_count ();
203
+ switch (nargs ) {
204
+ case 3 :
205
+ // TODO use 'native_to_java' on result
206
+ return f (explicit_cast (polyglot_get_arg (1 )), explicit_cast (polyglot_get_arg (2 )), Py_None );
207
+ case 4 :
208
+ // TODO use 'native_to_java' on result
209
+ return f (explicit_cast (polyglot_get_arg (1 )), explicit_cast (polyglot_get_arg (2 )), explicit_cast (polyglot_get_arg (3 )));
210
+ }
211
+ return native_to_java (NULL );
212
+ }
213
+
200
214
int PyType_Ready (PyTypeObject * cls ) {
201
215
#define ADD_IF_MISSING (attr , def ) if (!(attr)) { attr = def; }
202
216
#define ADD_METHOD (m ) ADD_METHOD_OR_SLOT(m.ml_name, get_method_flags_cwrapper(m.ml_flags), m.ml_meth, m.ml_flags, m.ml_doc)
@@ -382,7 +396,7 @@ int PyType_Ready(PyTypeObject* cls) {
382
396
ADD_SLOT ("__mul__" , numbers -> nb_multiply , -2 );
383
397
ADD_SLOT ("__rem__" , numbers -> nb_remainder , -2 );
384
398
ADD_SLOT ("__divmod__" , numbers -> nb_divmod , -2 );
385
- ADD_SLOT ("__pow__" , numbers -> nb_power , -2 );
399
+ ADD_SLOT_CONV ("__pow__" , wrap_pow , numbers -> nb_power , -3 );
386
400
ADD_SLOT ("__neg__" , numbers -> nb_negative , -1 );
387
401
ADD_SLOT ("__pos__" , numbers -> nb_positive , -1 );
388
402
ADD_SLOT ("__abs__" , numbers -> nb_absolute , -1 );
0 commit comments