473,326 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Python C Interface: finding out the called method's name in CPyMethod?

Purpose: Dynamically multiplex PyMethodDefs to QT Slots

Hi,

I would like to create a PyObject using the C API which can dispatch calls
to it's methods
to just ONE C function, which then forwards the call depending on the
method name and argument types/number
to other classes.

E.g. I would dynamically create:

PyMethodDef methods_QObject[] = {
{"method1", methodHandler, METH_VARARGS, NULL},
{"method2", methodHandler, METH_VARARGS, NULL},
{"method3", methodHandler, METH_VARARGS, NULL},
... more methods, read dynamically from a C++ Runtime system...
}
static PyObject *methodHandler(PyObject *sipSelf,PyObject *sipArgs)
{
// Now my problem arises, all methods point to this dispatcher
// and I would like to know the called method name something like:

const char* method = Py_..._getCurrentInvocationName(sipSelf);

// now do something dependend on method and sipArgs...
qobject->qt_invoke(method,args)
}

Your will say, hey, why does he want to do that, since I could just
implement "method1Handler", "method2Handler", ...

BUT, this would mean creating wrapper code like in the SIP library or SWIG
etc. which needs to be compiled on each change.
I want to do it dynamically, since I have a generic way to forward the
calls and I don't want to recreate the wrappers just to create
some dummy forwarders. I can create PyMethodDef dynamically, but I cannot
create C forwarder functions dynamically.

So, it there a way to find out the called method name from a PyMethod C
function?

Or maybe there is a way deeper in Python, can I extend the method
dispatcher of a PyObject, so get all call before the lookup
to tp_dict is done?

best regards,
Florian
Jul 18 '05 #1
1 1634
> So, it there a way to find out the called method name from a PyMethod C
function?


There is a straightforward method using the inspect module in Python:
http://www.python.org/doc/current/li...ect-stack.html

You could create a function in Python that calls current_frame(), pulls
out the name of your C method, and returns it.

- Josiah

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bill Davy | last post by:
I am working with MSVC6 on Windows XP. I have created an MSVC project called SHIP I have a file SHIP.i with "%module SHIP" as the first line (file is below). I run SHIP.i through SWIG 1.3.24...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.