Is there a function similar to PyArg_ParseTuple and PyArg_ParseTupleAndKeywords, without using a variable argument list?
I have a c++ extension that takes a long list of input arguments. Parsing them in the format of PyArg_ParseTuple and PyArg_ParseTupleAndKeywords is just ugly to look at. I'm hoping to be able to pass my argument list in the form of ([keyword1, format1, ptr1], [keyword2, format2, ptr2], ...). Are there existing functions or packages to do so?
Related
I need to tell the pass to look out for a specific function in the file. And I want to specify which function to look out for 'on the go' i.e when I run the pass. Any idea how I can do that? It's sort of like passing arguments to a function in theory.
Add a command line option using cl::opt<string> and set it when running your pass.
Alternatively, if you are producing an IR from C or C++ using clang, you can utilize __attribute((__annotate__(("foo")))) to mark functions you are interested in.
I am building a project on android, this project uses many swscanf_s, but android doesn't support swscanf_s, so I wonder is it possible to implement swscanf_s via swscanf?
note: the difference between swscanf_s and swscanf http://en.cppreference.com/w/c/io/fwscanf
swscanf_s: %c, %s, and %[ conversion specifiers each expect two arguments
I have thought about it for a long time
use regular expression to parse the format string, the problem is that android doesn't support vswscanf either.
implement swscanf_s as a variadic template. we can assume all buffer size arguments are integral and other arguments are pointer, so if I can extract all pointer arguments then pass them to swscanf, it will work. unfortunately, I also failed.
Do you have any idea? I hope the implementation wouldn't be too complicated or it will be lower-cost to replace all swscanf_s.
Other solution will also be helpful. Thanks
I am trying to implement a function that creates a list from two int lists to form pairs. But when I try to run zip, it tells me that this is an unbound variable. Is there any other function which does the same job in the library or some definition of zip with using the folding procedures?
Try ListPair.zip or ListPair.zipEq. See also the specification of the ListPair structure in the standard basis library.
I have a C++ routine MyClass::myFunction(char * message). which returns a message by writing in the message buffer. This routine is exported to python via SWIG. When the routine is called, I assume that the char * points to a python allocated memory area associated to the string.
Now, the SWIG documentation says that modifying the contents of this buffer is a baaad idea, which makes sense because strings are supposed to be immutable. So the question now is: what is the proper way of dealing with this case?
Sounds like you need the cstring.i library:
The cstring.i library file provides a collection of macros for dealing
with functions that either mutate string arguments or which try to
output string data through their arguments.
Particularly the %cstring_mutable macro:
%include <cstring.i>
%cstring_mutable(char *ustr);
...
void make_upper(char *ustr);
In Python:
>>> make_upper("hello world")
'HELLO WORLD'
The parameter name matters. In this case any function with a char *ustr parameter will be affected. So either make your parameter name unique or make all your mutable string parameters have the same name.
Note that there's also an expansion option that might be useful in your case.
I'm using Boost to embed Python in my application. For example, I want to check that the following function receives an integer and a string as the first and second parameters (the function is defined in C++).
someFunction(123, 'words')
If I find that the parameters are incorrect, how can I notify the scripter about which line they need to correct, for example?
If you wrap the function using usual def("someFunction",someFunction,...), caller will get automatically notified about c++ signature which could not be matched with objects passed from python, like this (the method takes one dictionary argument, is called with 3 numbers instead):
>>> scene.updateAttrs(1,2,3)
ArgumentError: Python argument types in
Serializable.updateAttrs(Scene, int, int, int)
did not match C++ signature:
updateAttrs(Serializable {lvalue}, boost::python::dict)
Can you post some code to see what is your problem?
Raise an exception with all the information you want them to know, just like you would in Python. In fact, that answer seems so obvious, it makes me think I'm missing something in your question.