@@ -315,18 +315,22 @@ typedef struct { |
315 | 315 | PyObject *default_value; |
316 | 316 | } anextawaitableobject; |
317 | 317 |
|
| 318 | +#define anextawaitableobject_CAST(op) ((anextawaitableobject *)(op)) |
| 319 | + |
318 | 320 | static void |
319 | | -anextawaitable_dealloc(anextawaitableobject *obj) |
| 321 | +anextawaitable_dealloc(PyObject *op) |
320 | 322 | { |
| 323 | + anextawaitableobject *obj = anextawaitableobject_CAST(op); |
321 | 324 | _PyObject_GC_UNTRACK(obj); |
322 | 325 | Py_XDECREF(obj->wrapped); |
323 | 326 | Py_XDECREF(obj->default_value); |
324 | 327 | PyObject_GC_Del(obj); |
325 | 328 | } |
326 | 329 |
|
327 | 330 | static int |
328 | | -anextawaitable_traverse(anextawaitableobject *obj, visitproc visit, void *arg) |
| 331 | +anextawaitable_traverse(PyObject *op, visitproc visit, void *arg) |
329 | 332 | { |
| 333 | + anextawaitableobject *obj = anextawaitableobject_CAST(op); |
330 | 334 | Py_VISIT(obj->wrapped); |
331 | 335 | Py_VISIT(obj->default_value); |
332 | 336 | return 0; |
@@ -363,7 +367,7 @@ anextawaitable_getiter(anextawaitableobject *obj) |
363 | 367 | } |
364 | 368 |
|
365 | 369 | static PyObject * |
366 | | -anextawaitable_iternext(anextawaitableobject *obj) |
| 370 | +anextawaitable_iternext(PyObject *op) |
367 | 371 | { |
368 | 372 | /* Consider the following class: |
369 | 373 | * |
@@ -385,6 +389,7 @@ anextawaitable_iternext(anextawaitableobject *obj) |
385 | 389 | * Then `await anext(gen)` can just call |
386 | 390 | * gen.__anext__().__next__() |
387 | 391 | */ |
| 392 | + anextawaitableobject *obj = anextawaitableobject_CAST(op); |
388 | 393 | PyObject *awaitable = anextawaitable_getiter(obj); |
389 | 394 | if (awaitable == NULL) { |
390 | 395 | return NULL; |
@@ -403,11 +408,14 @@ anextawaitable_iternext(anextawaitableobject *obj) |
403 | 408 |
|
404 | 409 |
|
405 | 410 | static PyObject * |
406 | | -anextawaitable_proxy(anextawaitableobject *obj, char *meth, PyObject *arg) { |
| 411 | +anextawaitable_proxy(anextawaitableobject *obj, char *meth, PyObject *arg) |
| 412 | +{ |
407 | 413 | PyObject *awaitable = anextawaitable_getiter(obj); |
408 | 414 | if (awaitable == NULL) { |
409 | 415 | return NULL; |
410 | 416 | } |
| 417 | + // 'arg' may be a tuple (if coming from a METH_VARARGS method) |
| 418 | + // or a single object (if coming from a METH_O method). |
411 | 419 | PyObject *ret = PyObject_CallMethod(awaitable, meth, "O", arg); |
412 | 420 | Py_DECREF(awaitable); |
413 | 421 | if (ret != NULL) { |
@@ -427,20 +435,26 @@ anextawaitable_proxy(anextawaitableobject *obj, char *meth, PyObject *arg) { |
427 | 435 |
|
428 | 436 |
|
429 | 437 | static PyObject * |
430 | | -anextawaitable_send(anextawaitableobject *obj, PyObject *arg) { |
| 438 | +anextawaitable_send(PyObject *op, PyObject *arg) |
| 439 | +{ |
| 440 | + anextawaitableobject *obj = anextawaitableobject_CAST(op); |
431 | 441 | return anextawaitable_proxy(obj, "send", arg); |
432 | 442 | } |
433 | 443 |
|
434 | 444 |
|
435 | 445 | static PyObject * |
436 | | -anextawaitable_throw(anextawaitableobject *obj, PyObject *arg) { |
437 | | - return anextawaitable_proxy(obj, "throw", arg); |
| 446 | +anextawaitable_throw(PyObject *op, PyObject *args) |
| 447 | +{ |
| 448 | + anextawaitableobject *obj = anextawaitableobject_CAST(op); |
| 449 | + return anextawaitable_proxy(obj, "throw", args); |
438 | 450 | } |
439 | 451 |
|
440 | 452 |
|
441 | 453 | static PyObject * |
442 | | -anextawaitable_close(anextawaitableobject *obj, PyObject *arg) { |
443 | | - return anextawaitable_proxy(obj, "close", arg); |
| 454 | +anextawaitable_close(PyObject *op, PyObject *args) |
| 455 | +{ |
| 456 | + anextawaitableobject *obj = anextawaitableobject_CAST(op); |
| 457 | + return anextawaitable_proxy(obj, "close", args); |
444 | 458 | } |
445 | 459 |
|
446 | 460 |
|
@@ -464,9 +478,9 @@ PyDoc_STRVAR(close_doc, |
464 | 478 |
|
465 | 479 |
|
466 | 480 | static PyMethodDef anextawaitable_methods[] = { |
467 | | - {"send",(PyCFunction)anextawaitable_send, METH_O, send_doc}, |
468 | | - {"throw",(PyCFunction)anextawaitable_throw, METH_VARARGS, throw_doc}, |
469 | | - {"close",(PyCFunction)anextawaitable_close, METH_VARARGS, close_doc}, |
| 481 | + {"send", anextawaitable_send, METH_O, send_doc}, |
| 482 | + {"throw", anextawaitable_throw, METH_VARARGS, throw_doc}, |
| 483 | + {"close", anextawaitable_close, METH_VARARGS, close_doc}, |
470 | 484 | {NULL, NULL} /* Sentinel */ |
471 | 485 | }; |
472 | 486 |
|
@@ -484,7 +498,7 @@ PyTypeObject _PyAnextAwaitable_Type = { |
484 | 498 | sizeof(anextawaitableobject), /* tp_basicsize */ |
485 | 499 | 0, /* tp_itemsize */ |
486 | 500 | /* methods */ |
487 | | - (destructor)anextawaitable_dealloc, /* tp_dealloc */ |
| 501 | + anextawaitable_dealloc, /* tp_dealloc */ |
488 | 502 | 0, /* tp_vectorcall_offset */ |
489 | 503 | 0, /* tp_getattr */ |
490 | 504 | 0, /* tp_setattr */ |
@@ -501,12 +515,12 @@ PyTypeObject _PyAnextAwaitable_Type = { |
501 | 515 | 0, /* tp_as_buffer */ |
502 | 516 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
503 | 517 | 0, /* tp_doc */ |
504 | | - (traverseproc)anextawaitable_traverse, /* tp_traverse */ |
| 518 | + anextawaitable_traverse, /* tp_traverse */ |
505 | 519 | 0, /* tp_clear */ |
506 | 520 | 0, /* tp_richcompare */ |
507 | 521 | 0, /* tp_weaklistoffset */ |
508 | 522 | PyObject_SelfIter, /* tp_iter */ |
509 | | - (unaryfunc)anextawaitable_iternext, /* tp_iternext */ |
| 523 | + anextawaitable_iternext, /* tp_iternext */ |
510 | 524 | anextawaitable_methods, /* tp_methods */ |
511 | 525 | }; |
512 | 526 |
|
|