LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-09-2012, 01:50 AM   #1
prasanthhs
LQ Newbie
 
Registered: Aug 2007
Location: Japan
Posts: 24

Rep: Reputation: 0
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.

Last edited by prasanthhs; 08-09-2012 at 04:41 AM.
 
Old 08-09-2012, 08:30 PM   #2
prasanthhs
LQ Newbie
 
Registered: Aug 2007
Location: Japan
Posts: 24

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by prasanthhs View Post
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 !!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] passing filenames in current directory as arguments to other function samasat Linux - Newbie 4 06-11-2012 01:21 PM
Problem:Passing arguments to thread function in C Thodoris21 Programming 24 06-07-2012 06:08 AM
[SOLVED] [scripting] try to passing arguments to for cycle (inside a function) vomplete Linux - General 3 04-26-2011 07:01 PM
C++, indefinite function arguments and multiple constructor passing @_@ R00ts Programming 2 04-08-2005 03:33 PM
Passing Arguments into the Thread Function George_gk Programming 2 01-31-2005 05:03 AM


All times are GMT -5. The time now is 02:50 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration