[Types-sig] Help?

Greg Stein gstein@lyra.org
Tue, 28 Dec 1999 13:54:24 -0800 (PST)


On Wed, 29 Dec 1999, skaller wrote:
>...
> 	PyObject *f(PyObject *self, PyObject *args)

In this form, the "self" argument is determined entirely by the C
implementation.

When the C function is a method on a C-based Type, then look in the module
for a Py_FindMethod() call. The second parameter is "self".

When the C function is a module-level function, then look at the
InitModule call. If the call is Py_InitModule() or Py_InitModule3(), then
self will always be NULL. If the call is Py_InitModule4(), then the fourth
parameter will be passed as self.

> would have args be a two argument tuple, and self NULL,
> for the call:
> 
> 	f(2,1)
> 
> Now, when f is called by _either_
> 
> 	X.g(x,1)
> 	x.g(1)
> 
> then x is the 'self' argument of the function,
> and the tuple 'args' contains only one element.
> Right?

See above. It is based on the C implementation, rather than the style of
call.

> So HOW do I convert f to a C function?
> It does not seem possible. When used as 'f',
> there are two arguments in the 'args' tuple,
> but when used as g, the first arg is the self
> pointer. The python script indicates a _single_
> function can be correctly used in both cases,
> but I cannot see how this is possible if
> a C function is used.

The C function is called in only one way. And that is based on the C
implementation and how you fetch the function (directly from a module or
via an object [of some type]).

> Sorry to ask a dumb question. Can anyone correct
> my misconceptions?

I hope that I have. Ask for more detail if I haven't been clear somewhere.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/