TIP: Click on subject to list as thread! ANSI
echo: rberrypi
to: R.WIESER
from: RICHARD KETTLEWELL
date: 2019-12-02 21:57:00
subject: Re: RPi.GPIO-0.7.0 - a fe

"R.Wieser"  writes:
> I'm trying to make a few changes to the PWM module of RPi.GPIO 0.7.0, and
> have a couple of questions:
>
> 1) Inside "PyMODINIT_FUNC PyInit__GPIO(void)" :
>
> // Add PWM class
> if (PWM_init_PWMType() == NULL)
> ...
> Py_INCREF(&PWMType);
> PyModule_AddObject(module, "PWM", (PyObject*)&PWMType);
>
> Is there any reason (technical or otherwise) why the last two lines are not
> part of the "PWM_init_PWMType()" function just above it ?    Somehow I
> regard that function as the initialisator of the PWM class.

PWM_init_PWMType sets up the type (someting that doesn’t need to know
about any module it may end up in), PyModule_AddObject gives the type a
name in a module. They’re logically quite separate operations.

> 2) Inside "PyTypeObject *PWM_init_PWMType(void)":
>
> PWMType.tp_new = PyType_GenericNew;
>
> Is there a (technical or otherwise) reason to why the "PyTypeObject PWMType
> ={...}" structure (just above the call) does not not just contain
> "PyType_GenericNew" as the relevant element ?

There’s no technical reason. The idiom and the associated comment is
widespread so I expect that whatever material the author learn the API
from had it.

--
https://www.greenend.org.uk/rjk/

--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)

SOURCE: echomail via QWK@docsplace.org

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.