int main(int argc, char *argv[]){ if(argc != 2){ fprintf(stderr, "Wrong number of arguments! Usage: %s [get-branch|get-pending|get-dir]\n", argv[0]); exit(EXIT_FAILURE); } if(strcmp(argv[1], "get-branch") == 0){ get_branch(); } else if(strcmp(argv[1], "get-pending") == 0){ int pending = get_pending(); if(pending > 0){ printf("%%B(%d)%%b\n", pending); } } else if(strcmp(argv[1], "get-dir") == 0){ int files; int dirs; if(get_dirlisting(&files, &dirs)){ printf("%d/%d\n", files, dirs); } } else { fprintf(stderr, "Unknown argument: '%s'. Usage: %s [get-branch|get-pending|get-dir]\n", argv[1], argv[0]); exit(EXIT_FAILURE); } return 0; }
/* * Return TRUE if anything is pending. */ int sipIsPending() { pendingDef *pd; if ((pd = get_pending(FALSE)) == NULL) return FALSE; return (pd->cpp != NULL); }
/* * Get the address etc. of any C/C++ object waiting to be wrapped. */ int sipGetPending(void **pp, sipWrapper **op, int *fp) { pendingDef *pd; if ((pd = get_pending(TRUE)) == NULL) return -1; *pp = pd->cpp; *op = pd->owner; *fp = pd->flags; return 0; }
/* * Convert a new C/C++ pointer to a Python instance. */ PyObject *sipWrapSimpleInstance(void *cppPtr, const sipTypeDef *td, sipWrapper *owner, int flags) { static PyObject *nullargs = NULL; pendingDef old_pending, *pd; PyObject *self; if (nullargs == NULL && (nullargs = PyTuple_New(0)) == NULL) return NULL; if (cppPtr == NULL) { Py_INCREF(Py_None); return Py_None; } /* * Object creation can trigger the Python garbage collector which in turn * can execute arbitrary Python code which can then call this function * recursively. Therefore we save any existing pending object before * setting the new one. */ if ((pd = get_pending(TRUE)) == NULL) return NULL; old_pending = *pd; pd->cpp = cppPtr; pd->owner = owner; pd->flags = flags; self = PyObject_Call((PyObject *)sipTypeAsPyTypeObject(td), nullargs, NULL); *pd = old_pending; return self; }