TIP: Click on subject to list as thread! ANSI
echo: rberrypi
to: ALL
from: R.WIESER
date: 2019-12-03 08:01:00
subject: Re: RPi.GPIO-0.7.0 - a fe

Richard,

> 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.

True.    But somehow I have the strong urge to place both in a single
function, and place it inside the PWM api sourcefile, py_pwm.c.  The reason
for that ?    The PyModule_AddObject() function call gets two arguments,
"PWM" and PWMType, which the main module, py_gpio.c, doesn't need to know
anything about and should correlate with other data in the py_pwm.c file.
In short, it looks cleaner to me that way.

>> 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.

I thought so too, but have started to doubt myself :

As far as I can (now) tell, the "PWMType.tp_new = PyType_GenericNew;" line
creates a single instance and stores it, which than is referenced in all
further access thru the "tp_new" field - instead of creating a new instance
of it every time that that field is referenced, which is what I think would
happen if the PyType_GenericNew is placed in the table itself.    Does that
make any sense ?

> 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.

:-)  That is what I assumed at first..

Regards,
Rudy Wieser

--- 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™.