TIP: Click on subject to list as thread! ANSI
echo: rberrypi
to: ALL
from: DENNIS LEE BIEBER
date: 2019-12-16 12:30:00
subject: Re: RPi.GPIO-0.7.0 - a fe

On Mon, 16 Dec 2019 12:12:16 +0100, "R.Wieser" 
declaimed the following:


>
>According to me line "PWMType.tp_new = PyType_GenericNew;" creates a single
>instance, and than (one of the methods of) that instance is called thru
>accessing the tables "tp_new" field
>
 It does NOT create an instance -- it assigns the /function/
PyType_GenericNew to the .tp_new "slot" . LATER, somewhere, .tp_new will be
called, which results in calling this function to create the instance.

 What that line is doing is initializing the C-language representation
of a TYPE with a function that handles creating instances. The TYPE
definition is in lines 150-189. I'll admit I'm perplexed that they didn't
just make the assignment in line 188.

 PyType_Ready() appears to handle the processing of superclasses for a
class -- possibly merging in data fields that were not initialized in the
class itself.


https://docs.python.org/3/c-api/type.html
"""
PyObject* PyType_GenericNew(PyTypeObject *type, PyObject *args, PyObject
*kwds)
    Return value: New reference.

    Generic handler for the tp_new slot of a type object. Create a new
instance using the type’s tp_alloc slot.
"""
 Since the PWM type doesn't override tp_alloc, it inherits the base
PyType_GenericAlloc

 .tp_new appears to be called by type_call() line 973 (
https://github.com/python/cpython/blob/master/Objects/typeobject.c lines
954-1004)

 Given that name "type_call", I'm presuming it gets called when a Python
class is called... eg
 myPWM = RPi.GPIO.PWM(stuff)


--
 Wulfraed                 Dennis Lee Bieber         AF6VN
 wlfraed@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/

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