Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import foo
- foo.bar([1, 2, 3])
- foo.bar([4, 5])
- int i,j;
- PyArg_ParseTuple(args, "i", &i)
- /* or */
- PyArg_ParseTuple(args, "(ii)", &i, &j);
- int *i;
- int ni;
- PyArg_ParseTuple(args, "(i...)", &ni, i);
- int
- ParseArguments(unsigned long arr[],Py_ssize_t size, PyObject *args) {
- /* Get arbitrary number of positive numbers from Py_Tuple */
- Py_ssize_t i;
- PyObject *temp_p, *temp_p2;
- for (i=0;i<size;i++) {
- temp_p = PyTuple_GetItem(args,i);
- if(temp_p == NULL) {return NULL;}
- /* Check if temp_p is numeric */
- if (PyNumber_Check(temp_p) != 1) {
- PyErr_SetString(PyExc_TypeError,"Non-numeric argument.");
- return NULL;
- }
- /* Convert number to python long and than C unsigned long */
- temp_p2 = PyNumber_Long(temp_p);
- arr[i] = PyLong_AsUnsignedLong(temp_p2);
- Py_DECREF(temp_p2);
- if (arr[i] == 0) {
- PyErr_SetString(PyExc_ValueError,"Zero doesn't allowed as argument.");
- return NULL;
- }
- if (PyErr_Occurred()) {return NULL; }
- }
- return 1;
- }
- static PyObject *
- function_name_was_here(PyObject *self, PyObject *args)
- {
- Py_ssize_t TupleSize = PyTuple_Size(args);
- Py_ssize_t i;
- struct bigcouples *temp = malloc(sizeof(struct bigcouples));
- unsigned long current;
- if(!TupleSize) {
- if(!PyErr_Occurred())
- PyErr_SetString(PyExc_TypeError,"You must supply at least one argument.");
- free(temp);
- return NULL;
- }
- unsigned long *nums = malloc(TupleSize * sizeof(unsigned long));
- if(!ParseArguments(nums, TupleSize, args)){
- /* Make a cleanup and than return null*/
- return null;
- }
Add Comment
Please, Sign In to add comment