LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Passing variable arguments to ctypes function of C++ (http://www.linuxquestions.org/questions/programming-9/passing-variable-arguments-to-ctypes-function-of-c-4175421156/)

prasanthhs 08-09-2012 01:50 AM

Passing variable arguments to ctypes function of C++
 
I have a problem when i pass variable arguments to ctypes function from HTML/JS->python in pyramid f/w -->C++

For example my http Get Call wil be as below:
PHP Code:

type"GET",
        
async:   false,
        
url"/web/NewModel/getValues?count=2&parameters=Param1,Param2",
        
success: function(data){
            
alert(data.GetValue

python base code
Code:

def get_Multiple_Xpaths(request):
        count = int(request.params['count'])
        requests=[]
        requests = request.params['parameters'].split(',')
        print 'count:%s' % (count)
        data=wrapperClass.getMultipleValues(count , *requests)
        print 'Final Data:%s' % (data)
        return {'Get':data}

I/F Python between python and C++
Code:

from ctypes import *
so = cdll.LoadLibrary(***)
funcHandle = so.CallC++Function
funcHandle.restype = c_char_p
def getMultipleValues(cls, count, *args):
                print 'count:%s' % (count)
                print 'Length of tuple:%s' %str(len(args))
                for a in args:
                        print 'Wrapper Param:%s' % (a)
                value=funcHandle(count, "Find" , *args) -->C++ debug prints parameters as empty. I tried to use str(*args) but it works only if *args actually has 1 argument. For multiple, it throws a type error.
                print 'Wrapper Value:%s' % (value)  ---->Returns Empty
                return value

The problem seems to be when i pass *args between 2 python functions, it is getting the values fine(when i print the values in getMultipleValues Function it prints fine). However the funcHandle Call which i use, the C++ doesnt get any value for *args which is being passed.

If i run a test program with funcHandle(count, "Find" , "parameter1" , "parameter2"), it gets the values fine.

Please advice me on what i am doing wrong here. My requirement is to pass the function with variable number of arguments as mentioned in the previous line so that C++ functions can access and process whatever it needs to. Thanks in advance. Cheers.

prasanthhs 08-09-2012 08:30 PM

Quote:

Originally Posted by prasanthhs (Post 4749627)
I have a problem when i pass variable arguments to ctypes function from HTML/JS->python in pyramid f/w -->C++

For example my http Get Call wil be as below:
PHP Code:

type"GET",
        
async:   false,
        
url"/web/NewModel/getValues?count=2&parameters=Param1,Param2",
        
success: function(data){
            
alert(data.GetValue

python base code
Code:

def get_Multiple_Xpaths(request):
        count = int(request.params['count'])
        requests=[]
        requests = request.params['parameters'].split(',')
        print 'count:%s' % (count)
        data=wrapperClass.getMultipleValues(count , *requests)
        print 'Final Data:%s' % (data)
        return {'Get':data}

I/F Python between python and C++
Code:

from ctypes import *
so = cdll.LoadLibrary(***)
funcHandle = so.CallC++Function
funcHandle.restype = c_char_p
def getMultipleValues(cls, count, *args):
                print 'count:%s' % (count)
                print 'Length of tuple:%s' %str(len(args))
                for a in args:
                        print 'Wrapper Param:%s' % (a)
                value=funcHandle(count, "Find" , *args) -->C++ debug prints parameters as empty. I tried to use str(*args) but it works only if *args actually has 1 argument. For multiple, it throws a type error.
                print 'Wrapper Value:%s' % (value)  ---->Returns Empty
                return value

The problem seems to be when i pass *args between 2 python functions, it is getting the values fine(when i print the values in getMultipleValues Function it prints fine). However the funcHandle Call which i use, the C++ doesnt get any value for *args which is being passed.

If i run a test program with funcHandle(count, "Find" , "parameter1" , "parameter2"), it gets the values fine.

Please advice me on what i am doing wrong here. My requirement is to pass the function with variable number of arguments as mentioned in the previous line so that C++ functions can access and process whatever it needs to. Thanks in advance. Cheers.

Any ideas guys..help me here !!


All times are GMT -5. The time now is 04:44 PM.