本文整理汇总了C++中PyObject_Call函数的典型用法代码示例。如果您正苦于以下问题:C++ PyObject_Call函数的具体用法?C++ PyObject_Call怎么用?C++ PyObject_Call使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyObject_Call函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: _call_dialect
/*
* Return an instance of the dialect type, given a Python instance or kwarg
* description of the dialect
*/
static PyObject *
_call_dialect(PyObject *dialect_inst, PyObject *kwargs)
{
PyObject *ctor_args;
PyObject *dialect;
ctor_args = Py_BuildValue(dialect_inst ? "(O)" : "()", dialect_inst);
if (ctor_args == NULL)
return NULL;
dialect = PyObject_Call((PyObject *)&Dialect_Type, ctor_args, kwargs);
Py_DECREF(ctor_args);
return dialect;
}
开发者ID:0xcc,项目名称:pyston,代码行数:17,代码来源:_csv.c
示例2: Node_traverse
static PyObject * Node_traverse(Node *self, PyObject *args, PyObject *kwargs)
{
PyObject *f, *nargs, *it, *rc;
f = PyTuple_GetItem(args, 0);
if (!f) {
PyErr_SetString(PyExc_TypeError, "function takes at least 1 argument");
return NULL;
}
if (!PyCallable_Check(f)) {
PyErr_SetString(PyExc_TypeError, "first parameter must be a callable object");
return NULL;
}
it = PyObject_GetIter(args);
nargs = PySequence_Tuple(it);
Py_DECREF(it);
Py_INCREF(self);
if (PyTuple_SetItem(nargs, 0, (PyObject *)self))
goto err;
if (!(rc = PyObject_Call(f, nargs, kwargs)))
goto err;
Py_DECREF(rc);
Py_DECREF(nargs);
if (NOT_NONE(self->left)) {
rc = Node_traverse(self->left, args, kwargs);
if (rc)
Py_DECREF(rc);
else
return NULL;
}
if (NOT_NONE(self->right)) {
rc = Node_traverse(self->right, args, kwargs);
if (rc)
Py_DECREF(rc);
else
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
err:
Py_DECREF(nargs);
return NULL;
}
开发者ID:manover,项目名称:bintree,代码行数:51,代码来源:avl.c
示例3: gcc_python_finish_invoking_callback
static void
gcc_python_finish_invoking_callback(PyGILState_STATE gstate,
int expect_wrapped_data, PyObject *wrapped_gcc_data,
void *user_data)
{
struct callback_closure *closure = (struct callback_closure *)user_data;
PyObject *args = NULL;
PyObject *result = NULL;
location_t saved_loc = input_location;
enum plugin_event saved_event;
assert(closure);
/* We take ownership of wrapped_gcc_data.
For some callbacks types it will always be NULL; for others, it's only
NULL if an error has occurred: */
if (expect_wrapped_data && !wrapped_gcc_data) {
goto cleanup;
}
if (cfun) {
/* Temporarily override input_location to the top of the function: */
input_location = cfun->function_start_locus;
}
args = gcc_python_closure_make_args(closure, 1, wrapped_gcc_data);
if (!args) {
goto cleanup;
}
saved_event = current_event;
current_event = closure->event;
result = PyObject_Call(closure->callback, args, closure->kwargs);
current_event = saved_event;
if (!result) {
/* Treat an unhandled Python error as a compilation error: */
gcc_python_print_exception("Unhandled Python exception raised within callback");
}
// FIXME: the result is ignored
cleanup:
Py_XDECREF(wrapped_gcc_data);
Py_XDECREF(args);
Py_XDECREF(result);
PyGILState_Release(gstate);
input_location = saved_loc;
}
开发者ID:h4ck3rm1k3,项目名称:gcc-python-plugin,代码行数:51,代码来源:gcc-python-callbacks.c
示例4: csv_reader
static PyObject *
csv_reader(PyObject *module, PyObject *args, PyObject *keyword_args)
{
PyObject * iterator, * dialect = NULL, *ctor_args;
ReaderObj * self = PyObject_GC_New(ReaderObj, &Reader_Type);
if (!self)
return NULL;
self->dialect = NULL;
self->input_iter = self->fields = NULL;
self->fields = NULL;
self->input_iter = NULL;
self->had_parse_error = 0;
self->field = NULL;
self->field_size = 0;
self->field_len = 0;
self->state = START_RECORD;
if (!PyArg_UnpackTuple(args, "", 1, 2, &iterator, &dialect)) {
Py_DECREF(self);
return NULL;
}
self->input_iter = PyObject_GetIter(iterator);
if (self->input_iter == NULL) {
PyErr_SetString(PyExc_TypeError,
"argument 1 must be an iterator");
Py_DECREF(self);
return NULL;
}
ctor_args = Py_BuildValue(dialect ? "(O)" : "()", dialect);
if (ctor_args == NULL) {
Py_DECREF(self);
return NULL;
}
self->dialect = (DialectObj *)PyObject_Call((PyObject *)&Dialect_Type,
ctor_args, keyword_args);
Py_DECREF(ctor_args);
if (self->dialect == NULL) {
Py_DECREF(self);
return NULL;
}
self->fields = PyList_New(0);
if (self->fields == NULL) {
Py_DECREF(self);
return NULL;
}
return (PyObject *)self;
}
开发者ID:Oize,项目名称:pspstacklesspython,代码行数:51,代码来源:_csv.c
示例5: Py_BuildValue
/* Pobieranie obiektu podobnego do pliku i wyświetlanie bajtów w strumieniu stdout */
static PyObject *py_consume_file(PyObject *self, PyObject *args) {
PyObject *obj;
PyObject *read_meth;
PyObject *result = NULL;
PyObject *read_args;
if (!PyArg_ParseTuple(args,"O", &obj)) {
return NULL;
}
/* Pobieranie metody read przekazanego obiektu */
if ((read_meth = PyObject_GetAttrString(obj, "read")) == NULL) {
return NULL;
}
/* Tworzenie listy argumentów dla metody read() */
read_args = Py_BuildValue("(i)", CHUNK_SIZE);
while (1) {
PyObject *data;
PyObject *enc_data;
char *buf;
Py_ssize_t len;
/* Wywołanie metody read() */
if ((data = PyObject_Call(read_meth, read_args, NULL)) == NULL) {
goto final;
}
/* Wykrywanie końca pliku */
if (PySequence_Length(data) == 0) {
Py_DECREF(data);
break;
}
/* Kodowanie znaków Unicode jako bajtów na potrzeby kodu w języku C */
if ((enc_data = PyUnicode_AsEncodedString(data, "utf-8", "strict")) == NULL) {
Py_DECREF(data);
goto final;
}
/* Pobieranie danych z bufora */
PyBytes_AsStringAndSize(enc_data, &buf, &len);
/* Wyświetlanie w strumieniu stdout (do zastąpienia bardziej użytecznym kodem) */
write(1, buf, len);
/* Operacje porządkujące */
Py_DECREF(enc_data);
Py_DECREF(data);
}
开发者ID:anpadoma,项目名称:python_receptury3,代码行数:51,代码来源:sample.c
示例6: Py_BuildValue
/* Consume a "file-like" object and write bytes to stdout */
static PyObject *py_consume_file(PyObject *self, PyObject *args) {
PyObject *obj;
PyObject *read_meth;
PyObject *result = NULL;
PyObject *read_args;
if (!PyArg_ParseTuple(args,"O", &obj)) {
return NULL;
}
/* Get the read method of the passed object */
if ((read_meth = PyObject_GetAttrString(obj, "read")) == NULL) {
return NULL;
}
/* Build the argument list to read() */
read_args = Py_BuildValue("(i)", CHUNK_SIZE);
while (1) {
PyObject *data;
PyObject *enc_data;
char *buf;
Py_ssize_t len;
/* Call read() */
if ((data = PyObject_Call(read_meth, read_args, NULL)) == NULL) {
goto final;
}
/* Check for EOF */
if (PySequence_Length(data) == 0) {
Py_DECREF(data);
break;
}
/* Encode Unicode as Bytes for C */
if ((enc_data = PyUnicode_AsEncodedString(data, "utf-8", "strict")) == NULL) {
Py_DECREF(data);
goto final;
}
/* Extract underlying buffer data */
PyBytes_AsStringAndSize(enc_data, &buf, &len);
/* Write to stdout (replace with something more useful) */
write(1, buf, len);
/* Cleanup */
Py_DECREF(enc_data);
Py_DECREF(data);
}
开发者ID:OpenDeployment,项目名称:chef-repo,代码行数:51,代码来源:sample.c
示例7: PyObject_Call
static PyObject *_prepareValue(t_set *self, PyObject *value)
{
PyObject *item = PyObject_Call(self->itemvalue.owner, Empty_TUPLE, NULL);
if (!item)
return NULL;
value = PyObject_CallMethodObjArgs((PyObject *) self, prepareValue_NAME,
item, self->itemvalue.attribute, value,
Py_False, NULL);
Py_DECREF(item);
return value;
}
开发者ID:HackLinux,项目名称:chandler,代码行数:14,代码来源:set.c
示例8: PyDict_New
PyObject* pyInfoTree::make_pyobject_from_c_ptr(InfoTree* tree, bool do_copy) {
PyObject* keyworded_args = PyDict_New();
On_scope_exit { Py_XDECREF(keyworded_args); };
PyObject* empty_tuple = PyTuple_New(0);
On_scope_exit { Py_XDECREF(empty_tuple); };
auto tree_capsule = PyCapsule_New(static_cast<void*>(tree), nullptr, nullptr);
On_scope_exit { Py_XDECREF(tree_capsule); };
PyDict_SetItemString(keyworded_args, "infotree_c_ptr", tree_capsule);
PyObject* copy = PyLong_FromLong(do_copy);
On_scope_exit { Py_XDECREF(copy); };
PyDict_SetItemString(keyworded_args, "copy", copy);
PyObject* obj = PyObject_Call((PyObject*)&pyInfoTree::pyType, empty_tuple, keyworded_args);
return obj;
}
开发者ID:nicobou,项目名称:switcher,代码行数:14,代码来源:pyinfotree.cpp
示例9: _def_f_getsize
static PyObject*
_def_f_getsize(PyObject *self, PyObject *args, PyObject *kwds)
{
PyObject *retval, *method;
method = PyObject_GetAttrString(self, "getsize");
if (!method)
return NULL;
retval = PyObject_Call(method, args, kwds);
Py_DECREF (method);
return retval;
}
开发者ID:gdos,项目名称:pgreloaded.sdl12,代码行数:14,代码来源:font.c
示例10: modena_model_read_substituteModels
void modena_model_read_substituteModels(modena_model_t *m)
{
PyObject *pSubstituteModels = PyObject_GetAttrString
(
m->pModel, "substituteModels"
);
if(!pSubstituteModels){ Modena_PyErr_Print(); }
PyObject *pSeq = PySequence_Fast
(
pSubstituteModels, "expected a sequence"
);
m->substituteModels_size = PySequence_Size(pSubstituteModels);
m->substituteModels =
malloc(m->substituteModels_size*sizeof(modena_substitute_model_t));
size_t i;
for(i = 0; i < m->substituteModels_size; i++)
{
PyObject *args = PyTuple_New(0);
PyObject *kw = Py_BuildValue
(
"{s:O}", "model", PyList_GET_ITEM(pSeq, i)
);
m->substituteModels[i].model = (modena_model_t *) PyObject_Call
(
(PyObject *) &modena_model_tType, args, kw
);
Py_DECREF(args);
Py_DECREF(kw);
if(!m->substituteModels[i].model){ Modena_PyErr_Print(); }
m->substituteModels[i].inputs = modena_inputs_new
(
m->substituteModels[i].model
);
m->substituteModels[i].outputs = modena_outputs_new
(
m->substituteModels[i].model
);
modena_substitute_model_calculate_maps(&m->substituteModels[i], m);
}
Py_DECREF(pSeq);
Py_DECREF(pSubstituteModels);
if(PyErr_Occurred()){ Modena_PyErr_Print(); }
}
开发者ID:mandarthombre,项目名称:MoDeNa,代码行数:49,代码来源:modena.c
示例11: Py_BuildValue
void KX_LibLoadStatus::RunFinishCallback()
{
#ifdef WITH_PYTHON
if (m_finish_cb) {
PyObject* args = Py_BuildValue("(O)", GetProxy());
if (!PyObject_Call(m_finish_cb, args, NULL)) {
PyErr_Print();
PyErr_Clear();
}
Py_DECREF(args);
}
#endif
}
开发者ID:DarkDefender,项目名称:blender-npr-tess2,代码行数:15,代码来源:KX_LibLoadStatus.cpp
示例12: selTournament
static PyObject* selTournament(PyObject *self, PyObject *args, PyObject *kwargs){
/* Args[0] / kwArgs['individuals'] : Individual list
* Args[1] / kwArgs['k'] : Number of individuals wanted in output
* Args[2] / kwArgs['tournsize'] : Tournament size
* Return : k selected individuals from input individual list
*/
PyObject *lListIndv;
unsigned int k, lTournSize;
static char *lKwlist[] = {"individuals", "k", "tournsize", NULL};
PyArg_ParseTupleAndKeywords(args, kwargs, "Oii", lKwlist, &lListIndv, &k, &lTournSize);
// Import the Python random module
PyObject *lRandomModule = PyImport_ImportModule("random");
PyObject *lRandomChoiceFunc = PyObject_GetAttrString(lRandomModule, "choice");
PyObject *lListSelect = PyList_New(0);
PyObject *lCandidate, *lChallenger, *lCandidateFit, *lChallengerFit, *lTupleArgs;
lTupleArgs = Py_BuildValue("(O)", lListIndv);
for(unsigned int i=0; i < k; i++){
// We call random.choice with the population as argument
lCandidate = PyObject_Call(lRandomChoiceFunc, lTupleArgs, NULL);
lCandidateFit = PyObject_GetAttrString(lCandidate, "fitness");
for(unsigned int j=0; j < lTournSize-1; j++){
lChallenger = PyObject_Call(lRandomChoiceFunc, lTupleArgs, NULL);
lChallengerFit = PyObject_GetAttrString(lChallenger, "fitness");
// Is the fitness of the aspirant greater?
if(PyObject_RichCompareBool(lChallengerFit, lCandidateFit, Py_GT)){
lCandidate = lChallenger;
lCandidateFit = lChallengerFit;
}
}
PyList_Append(lListSelect, lCandidate);
}
return lListSelect;
}
开发者ID:chulakar,项目名称:KeyPlayers_Sample,代码行数:36,代码来源:cTools.cpp
示例13: keyobject_richcompare
static PyObject *
keyobject_richcompare(PyObject *ko, PyObject *other, int op)
{
PyObject *res;
PyObject *args;
PyObject *x;
PyObject *y;
PyObject *compare;
PyObject *answer;
static PyObject *zero;
if (zero == NULL) {
zero = PyLong_FromLong(0);
if (!zero)
return NULL;
}
if (Py_TYPE(other) != &keyobject_type){
PyErr_Format(PyExc_TypeError, "other argument must be K instance");
return NULL;
}
compare = ((keyobject *) ko)->cmp;
assert(compare != NULL);
x = ((keyobject *) ko)->object;
y = ((keyobject *) other)->object;
if (!x || !y){
PyErr_Format(PyExc_AttributeError, "object");
return NULL;
}
/* Call the user's comparison function and translate the 3-way
* result into true or false (or error).
*/
args = PyTuple_New(2);
if (args == NULL)
return NULL;
Py_INCREF(x);
Py_INCREF(y);
PyTuple_SET_ITEM(args, 0, x);
PyTuple_SET_ITEM(args, 1, y);
res = PyObject_Call(compare, args, NULL);
Py_DECREF(args);
if (res == NULL)
return NULL;
answer = PyObject_RichCompare(res, zero, op);
Py_DECREF(res);
return answer;
}
开发者ID:AaronVerrells,项目名称:cpython,代码行数:48,代码来源:_functoolsmodule.c
示例14: obj_create
static PyObject *
obj_create(PyObject *self)
{
int added;
PyObject * args = PyTuple_New(3);
if (args == NULL) {
return NULL;
}
PyObject * name = PyUnicode_FromString("Bill");
if (name == NULL) {
Py_DECREF(args);
return NULL;
}
added = PyTuple_SetItem(args, 0, name);
// PyTuple_SetItem is an exception and it steals the reference, even if it fails.
// We will not have to DECREF name anymore.
if (added != 0) {
Py_DECREF(args);
return NULL;
}
PyObject * number = PyLong_FromLong(7);
if (number == NULL) {
Py_DECREF(args);
return NULL;
}
added = PyTuple_SetItem(args, 1, number);
// We will not have to DECREF number anymore.
if (added != 0) {
Py_DECREF(args);
return NULL;
}
PyObject * yes = Py_True;
Py_INCREF(yes);
added = PyTuple_SetItem(args, 2, yes);
// We will not have to DECREF yes anymore.
if (added != 0) {
Py_DECREF(args);
return NULL;
}
PyObject * kwargs = NULL;
PyObject * result = PyObject_Call((PyObject *) &NativeType, args, kwargs);
Py_DECREF(args);
if (result == NULL) {
return NULL;
}
return result;
}
开发者ID:kurazu,项目名称:pyext,代码行数:48,代码来源:obj.c
示例15: call_func
double call_func(PyObject *func, double x, double y) {
PyObject *args;
PyObject *kwargs;
PyObject *result = 0;
double retval;
/* Make sure we own the GIL */
PyGILState_STATE state = PyGILState_Ensure();
/* Verify that func is a proper callable */
if (!PyCallable_Check(func)) {
fprintf(stderr,"call_func: expected a callable\n");
goto fail;
}
/* Build arguments */
args = Py_BuildValue("(dd)", x, y);
kwargs = NULL;
/* Call the function */
result = PyObject_Call(func, args, kwargs);
Py_DECREF(args);
Py_XDECREF(kwargs);
/* Check for Python exceptions (if any) */
if (PyErr_Occurred()) {
PyErr_Print();
goto fail;
}
/* Verify the result is a float object */
if (!PyFloat_Check(result)) {
fprintf(stderr,"call_func: callable didn't return a float\n");
goto fail;
}
/* Create the return value */
retval = PyFloat_AsDouble(result);
Py_DECREF(result);
/* Restore previous GIL state and return */
PyGILState_Release(state);
return retval;
fail:
Py_XDECREF(result);
PyGILState_Release(state);
abort();
}
开发者ID:1060460048,项目名称:python-cookbook,代码行数:48,代码来源:embed.c
示例16: atexit_callfuncs
static void
atexit_callfuncs(void)
{
PyObject *exc_type = NULL, *exc_value, *exc_tb, *r;
atexit_callback *cb;
PyObject *module;
atexitmodule_state *modstate;
int i;
module = PyState_FindModule(&atexitmodule);
if (module == NULL)
return;
modstate = GET_ATEXIT_STATE(module);
if (modstate->ncallbacks == 0)
return;
for (i = modstate->ncallbacks - 1; i >= 0; i--)
{
cb = modstate->atexit_callbacks[i];
if (cb == NULL)
continue;
r = PyObject_Call(cb->func, cb->args, cb->kwargs);
Py_XDECREF(r);
if (r == NULL) {
/* Maintain the last exception, but don't leak if there are
multiple exceptions. */
if (exc_type) {
Py_DECREF(exc_type);
Py_XDECREF(exc_value);
Py_XDECREF(exc_tb);
}
PyErr_Fetch(&exc_type, &exc_value, &exc_tb);
if (!PyErr_ExceptionMatches(PyExc_SystemExit)) {
PySys_WriteStderr("Error in atexit._run_exitfuncs:\n");
PyErr_NormalizeException(&exc_type, &exc_value, &exc_tb);
PyErr_Display(exc_type, exc_value, exc_tb);
}
}
}
atexit_cleanup(modstate);
if (exc_type)
PyErr_Restore(exc_type, exc_value, exc_tb);
}
开发者ID:dougmassay,项目名称:cpython3.4.4,代码行数:48,代码来源:atexitmodule.c
示例17: Session_browse_artist
static PyObject *
Session_browse_artist(Session * self, PyObject *args, PyObject *kwds)
{
PyObject *artist, *callback, *userdata = NULL;
static char *kwlist[] = { "artist", "callback", "userdata", NULL };
if (!PyArg_ParseTupleAndKeywords
(args, kwds, "O!O|O", kwlist, &ArtistType, &artist, &callback,
&userdata))
return NULL;
args = PyTuple_NewByPreappending((PyObject *)self, args);
PyObject *result =
PyObject_Call((PyObject *)&ArtistBrowserType, args, kwds);
Py_XDECREF(args);
return result;
}
开发者ID:JoeConyers,项目名称:SpotifyRemote,代码行数:16,代码来源:session.c
示例18: DCPointFromObject
PyObject* DCPointFromObject(DKPoint* point)
{
if (point)
{
PyObject* args = Py_BuildValue("ff", point->x, point->y);
PyObject* kwds = PyDict_New();
PyObject* tp = (PyObject*)DCObjectDefaultClass(&objectType);
PyObject* self = PyObject_Call(tp, args, kwds);
Py_XDECREF(tp);
Py_XDECREF(args);
Py_XDECREF(kwds);
return self;
}
Py_RETURN_NONE;
}
开发者ID:hhg128,项目名称:DKGL,代码行数:16,代码来源:DCPoint.cpp
示例19: partial_call_impl
static PyObject *
partial_call_impl(partialobject *pto, PyObject *args, PyObject *kwargs)
{
PyObject *ret, *args2;
/* Note: tupleconcat() is optimized for empty tuples */
args2 = PySequence_Concat(pto->args, args);
if (args2 == NULL) {
return NULL;
}
assert(PyTuple_Check(args2));
ret = PyObject_Call(pto->fn, args2, kwargs);
Py_DECREF(args2);
return ret;
}
开发者ID:1st1,项目名称:cpython,代码行数:16,代码来源:_functoolsmodule.c
示例20: sleeper_agent_state
/* Return result of sleeper_agent._get_state_info() as a C string */
char * sleeper_agent_state(void)
{
char *rv = NULL;
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
rv = PyString_AsString(
PyObject_Call(
PyObject_GetAttrString(
PyImport_ImportModule("sleeper_agent"),
"_get_state_info"),
Py_BuildValue("()"), NULL));
PyGILState_Release(gstate);
return rv;
}
开发者ID:mpasternacki,项目名称:sleeper_agent,代码行数:17,代码来源:_sleeper_agent_activation.c
注:本文中的PyObject_Call函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论