Writing a CPython extension - calling another sibbling method ?

Michael Torrie torriem at gmail.com
Tue Nov 19 15:38:07 EST 2019


On 11/19/19 10:12 AM, R.Wieser wrote:
> Feel free to post code showing that it can be done.   The extension is
> RPi.GPIO, the method is "output", and the extra argument is the pinnaming
> scheme (BCM or BOARD).   Success! :-p

If you mentioned RPi.GPIO before, I apologize for my mistake.  That's
very helpful to know.

As for posting code to show it can be done, If I knew what the pin
naming scheme was (how do you use it from python?), and if I knew how
you modified py_output_gpio to do something with that, I sure would give
it a shot.

>> We're working in the dark here
> 
> Are you sure ?   
> MRAB didn't seem to have too much problems with both
> recognising and understanding what I was busy with - he posted a spot-on
> example, containing not more, but also not anything less than what I was
> asking for.

MRAB understood and answered the specific question, yes.

But I thought, and remain convinced, that there were probably other ways
of solving it that didn't involve mucking with C code. Because forking
the RPi.GPIO code means that every time there's a change or update to it
you know have to redo everything each time.

You mentioned you're working with RPi.GPIO, so why not just use the real
function names in your questions?  After grepping I've determined that
you are really wanting to work with the C function py_output_gpio().
Why not just say that?  Doesn't take very much extra time but will get
more people willing to respond who might know.

> I did not find any example that showed me what I needed to know - simply one
> CPython function calling another one.    And yes, I've found multiple
> documentation pages, including the "Extending and Embedding the Python
> Interpreter" ones.  Alas, no dice.
Fair enough.

> By the way, the whole solution consists outof the following:
> 
> static PyObject *py_proc1(PyObject *self, int ExtraArg, PyObject *args)
> {
> ....
>   Py_RETURN_NONE
> }
> 
> static PyObject *py_proc2(PyObject *self, PyObject *args)
> {
>    return py_proc1(self, 42, args)
> }

Glad it worked out for you.  That "int ExtraArg" bit looks a bit
strange; I thought everything that was exposed to the Python side of
things had to be wrapped in PyObject.  Guess I'm wrong?



More information about the Python-list mailing list