• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PyCObject_Check函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中PyCObject_Check函数的典型用法代码示例。如果您正苦于以下问题:C++ PyCObject_Check函数的具体用法?C++ PyCObject_Check怎么用?C++ PyCObject_Check使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了PyCObject_Check函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: PyBool_FromLong

static PyObject *authGSSServerHasDelegated(PyObject *self, PyObject *args)
{
    gss_server_state *state;
    PyObject *pystate;

    if (!PyArg_ParseTuple(args, "O", &pystate))
        return NULL;

    if (!PyCObject_Check(pystate)) {
        PyErr_SetString(PyExc_TypeError, "Expected a context object");
        return NULL;
    }

    state = (gss_server_state *)PyCObject_AsVoidPtr(pystate);
    if (state == NULL)
        return NULL;

    return PyBool_FromLong(authenticate_gss_server_has_delegated(state));
}
开发者ID:prashanthpai,项目名称:PyKerberos,代码行数:19,代码来源:kerberos.c


示例2: Py_BuildValue

static PyObject *authGSSClientResponseConf(PyObject *self, PyObject *args)
{
    gss_client_state *state;
    PyObject *pystate;

    if (!PyArg_ParseTuple(args, "O", &pystate))
        return NULL;

    if (!PyCObject_Check(pystate)) {
        PyErr_SetString(PyExc_TypeError, "Expected a context object");
        return NULL;
    }

    state = (gss_client_state *)PyCObject_AsVoidPtr(pystate);
    if (state == NULL)
        return NULL;

    return Py_BuildValue("i", state->responseConf);
}
开发者ID:prashanthpai,项目名称:PyKerberos,代码行数:19,代码来源:kerberos.c


示例3: pythonTrace

  int pythonTrace(PyObject* mobj, PyFrameObject *mframe, int mwhat, PyObject *marg) {
    // DBG("Python trace\n");
    IvrPython* pIvrPython = 0; //getIvrPythonPointer();
    if (mobj != NULL){
      if (PyCObject_Check(mobj)) {
	  pIvrPython = (IvrPython*)PyCObject_AsVoidPtr(mobj);
	  //	  Py_DECREF(mobj);
      }
    }

    if (pIvrPython) {
      AmEventQueue* evq = pIvrPython->getScriptEventQueue();
      if (evq)
	evq->processEvents();
    } else {
      ERROR("IvrPython pointer not found in Trace!\n");
      return 1;
    }
    return 0; 
  }
开发者ID:BackupTheBerlios,项目名称:semsivr,代码行数:20,代码来源:IvrPython.cpp


示例4: pf_init

static PyObject *
pf_init(PyObject *self, PyObject *args)
{
    PyObject *pyobj, *pyarray, *py_posparams;
    double period_tolerance;
    struct s_param *params;
    struct pfHandle *pfh;
    double pos_params[N_PARAMS];

    if(!PyArg_ParseTuple(
	   args,"OdOO",&pyobj,&period_tolerance,&py_posparams, &pyarray))
    {
	return NULL;
    }
    if(!PyCObject_Check(pyobj))
    {
	PyErr_SetString(PyExc_ValueError,"Not a valid handle");
	return NULL;
    }

    pfh = (struct pfHandle *)PyCObject_AsVoidPtr(pyobj);

    if(!parse_posparams(py_posparams, pos_params))
    {
	return NULL;
    }

    int len=0;
    params = parse_params(pyarray,&len);
    if(!params)
    {
	return NULL;
    }

    /*finally all args are assembled */
    pfh->pfo->vtbl->init(pfh->pfo,period_tolerance,pos_params,params,len);
    free(params);

    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:Bookaa,项目名称:gnofract4d.simplify,代码行数:41,代码来源:fract4dmodule_gmp.cpp


示例5: mlabraw_oldeval

PyObject * mlabraw_oldeval(PyObject *, PyObject *args)
{
  //XXX how large should this be?
  const int  BUFSIZE=10000;
  char buffer[BUFSIZE];
  char *lStr;
  char *retStr = buffer;
  PyObject *ret;
  PyObject *lHandle;

  if (! PyArg_ParseTuple(args, "Os:eval", &lHandle, &lStr)) return NULL;
  if (! PyCObject_Check(lHandle)) {
    PyErr_SetString(PyExc_TypeError, "Invalid object passed as mlabraw session handle");
    return NULL;
  }
  engOutputBuffer((Engine *)PyCObject_AsVoidPtr(lHandle), retStr, BUFSIZE-1);
  if (engEvalString((Engine *)PyCObject_AsVoidPtr(lHandle), lStr) != 0) {
    PyErr_SetString(mlabraw_error,
                   "Unable to evaluate string in MATLAB(TM) workspace");
    return NULL;
  }
  // skip the prompt if there is one
  if (strncmp(">> ", retStr, 3) == 0) {
    retStr += 3;
  }
  else {
    //XXX I think there is no prompt under windoze
//     printf("###DEBUG: matlab output doesn't start with \">> \"!\n"
//            "It starts with: '%s'\n"
//            "The command was: '%s'\n", retStr, lStr);
  }
  // "??? " is how an error message begins in matlab
  // obviously there is no proper way to test whether a command was
  // succesful... AAARGH
  if (strncmp("??? ", retStr, 4) == 0) {
    PyErr_SetString(mlabraw_error, retStr + 4); // skip "??? "
    return NULL;
  }
  ret = (PyObject *)PyString_FromString(retStr);
  return ret;
}
开发者ID:ericjsolis,项目名称:danapeerlab,代码行数:41,代码来源:mlabraw.cpp


示例6: pyglib_init

void
pyglib_init(void)
{
    PyObject *glib, *cobject;
    
    glib = PyImport_ImportModule("glib");
    if (!glib) {
	if (PyErr_Occurred()) {
	    PyObject *type, *value, *traceback;
	    PyObject *py_orig_exc;
	    PyErr_Fetch(&type, &value, &traceback);
	    py_orig_exc = PyObject_Repr(value);
	    Py_XDECREF(type);
	    Py_XDECREF(value);
	    Py_XDECREF(traceback);
	    PyErr_Format(PyExc_ImportError,
			 "could not import glib (error was: %s)",
			 _PyUnicode_AsString(py_orig_exc));
	    Py_DECREF(py_orig_exc);
        } else {
	    PyErr_SetString(PyExc_ImportError,
			    "could not import glib (no error given)");
	}
	return;
    }
    
    cobject = PyObject_GetAttrString(glib, "_PyGLib_API");
    if (cobject && PyCObject_Check(cobject))
	_PyGLib_API = (struct _PyGLib_Functions *) PyCObject_AsVoidPtr(cobject);
    else {
	PyErr_SetString(PyExc_ImportError,
			"could not import glib (could not find _PyGLib_API object)");
	Py_DECREF(glib);
	return;
    }

    _PyGMainContext_Type = (PyTypeObject*)PyObject_GetAttrString(glib, "MainContext");
    _PyGOptionGroup_Type = (PyTypeObject*)PyObject_GetAttrString(glib, "OptionGroup");
    _PyGOptionContext_Type = (PyTypeObject*)PyObject_GetAttrString(glib, "OptionContext");
}
开发者ID:tizenorg,项目名称:platform.upstream.pygobject2,代码行数:40,代码来源:pyglib.c


示例7: do_get_time_by_index

static PyObject *
do_get_time_by_index (PyObject *self, PyObject *args, PyObject *kwds)
{
    NsLibrary      *lib;
    PyObject       *cobj;
    PyObject       *iobj, *id_obj, *idx_obj;
    uint32          file_id;
    uint32          entity_id;
    uint32          index;
    double          timepoint;
    ns_RESULT       res;

    if (!PyArg_ParseTuple (args, "OOOO", &cobj, &iobj, &id_obj, &idx_obj))
    {
        PyErr_SetString (PyExc_StandardError, "Could not parse arguments");
        return NULL;
    }

    if (!PyCObject_Check (cobj) || !PyInt_Check (iobj) ||
            !PyInt_Check (id_obj) || !PyInt_Check (idx_obj))
    {
        PyErr_SetString (PyExc_TypeError, "Wrong argument type(s)");
        return NULL;
    }

    lib = PyCObject_AsVoidPtr (cobj);
    file_id = (uint32) PyInt_AsUnsignedLongMask (iobj);
    entity_id = (uint32) PyInt_AsUnsignedLongMask (id_obj);
    index = (uint32) PyInt_AsUnsignedLongMask (idx_obj);

    res = lib->GetTimeByIndex (file_id,
                               entity_id,
                               index,
                               &timepoint);

    if (check_result_is_error (res, lib))
        return NULL;

    return Py_BuildValue ("d", timepoint);
}
开发者ID:jthorniley,项目名称:python-neuroshare,代码行数:40,代码来源:nspy_glue.c


示例8: PyArg_ParseTuple

static PyObject *pattern_get_class(PyObject *self,      PyObject *args)
{
  int ok=true;
  int int1;
  PyObject *result = NULL;
  PyObject *O,*l1,*l2;
  CChamp *I;
  ListPat *pat;
  ListAtom *at;
  ListBond *bd;
  int a,b;
  int n_atom,n_bond;
  ok = PyArg_ParseTuple(args,"Oi",&O,&int1);
  ok = PyCObject_Check(O);
  if(ok) {
    I = PyCObject_AsVoidPtr(O);
    pat = I->Pat+int1;
    
    n_atom = ListLen(I->Atom,pat->atom);
    at = I->Atom + pat->atom;
    l1 = PyList_New(n_atom);
    for(a=0;a<n_atom;a++) {
      PyList_SetItem(l1,a,PyInt_FromLong(at->class));
      at = I->Atom + at->link;
    }

    n_bond = ListLen(I->Bond,pat->bond);
    l2 = PyList_New(n_bond);
    bd = I->Bond + pat->bond;
    for(b=0;b<n_bond;b++) {
      PyList_SetItem(l2,b,PyInt_FromLong(bd->class));
      bd = I->Bond + bd->link;
    }

    result = PyList_New(2);
    PyList_SetItem(result,0,l1);
    PyList_SetItem(result,1,l2);
  }
  return(RetObj(ok,result));
}
开发者ID:dprada,项目名称:pymol-open-source,代码行数:40,代码来源:champ_module.c


示例9: Py_BuildValue

static PyObject *authGSSServerTargetName(PyObject *self, PyObject *args)
{
    gss_server_state *state;
    PyObject *pystate;
    
    if (! PyArg_ParseTuple(args, "O", &pystate)) {
        return NULL;
    }
    
    if (! PyCObject_Check(pystate)) {
        PyErr_SetString(PyExc_TypeError, "Expected a context object");
        return NULL;
    }
    
    state = (gss_server_state *)PyCObject_AsVoidPtr(pystate);

    if (state == NULL) {
        return NULL;
    }
    
    return Py_BuildValue("s", state->targetname);
}
开发者ID:veerakumar123,项目名称:tomcat,代码行数:22,代码来源:kerberos.c


示例10: pf_calc

static PyObject *
pf_calc(PyObject *self, PyObject *args)
{
    PyObject *pyobj, *pyret;
    double params[4];
    struct pfHandle *pfh; 
    int nIters, x=0,y=0,aa=0;
    int outIters=0, outFate=-777;
    double outDist=0.0;
    int outSolid=0;
    int fDirectColorFlag=0;
    double colors[4] = {0.0, 0.0, 0.0, 0.0};

    if(!PyArg_ParseTuple(args,"O(dddd)i|iii",
			 &pyobj,
			 &params[0],&params[1],&params[2],&params[3],
			 &nIters,&x,&y,&aa))
    {
	return NULL;
    }
    if(!PyCObject_Check(pyobj))
    {
	PyErr_SetString(PyExc_ValueError,"Not a valid handle");
	return NULL;
    }

    pfh = (struct pfHandle *)PyCObject_AsVoidPtr(pyobj);
#ifdef DEBUG_THREADS
    printf("%p : PF : CALC\n",pfh);
#endif
    pfh->pfo->vtbl->calc(pfh->pfo,params,
			 nIters, -1,
			 x,y,aa,
			 &outIters,&outFate,&outDist,&outSolid,
			 &fDirectColorFlag, &colors[0]);
    assert(outFate != -777);
    pyret = Py_BuildValue("iidi",outIters,outFate,outDist,outSolid);
    return pyret; // Python can handle errors if this is NULL
}
开发者ID:Bookaa,项目名称:gnofract4d.simplify,代码行数:39,代码来源:fract4dmodule_gmp.cpp


示例11: authGSSClientInit

static PyObject* authGSSClientInit(PyObject* self, PyObject* args, PyObject* keywds)
{
    const char *service = NULL;
    const char *principal = NULL;
    gss_client_state *state;
    PyObject *pystate;
    gss_server_state *delegatestate = NULL;
    PyObject *pydelegatestate;
    static char *kwlist[] = {
        "service", "principal", "gssflags", "delegated", NULL
    };
    long int gss_flags = GSS_C_MUTUAL_FLAG | GSS_C_SEQUENCE_FLAG;
    int result = 0;

    if (! PyArg_ParseTupleAndKeywords(
        args, keywds, "s|slO", kwlist,
        &service, &principal, &gss_flags, &pydelegatestate
    )) {
        return NULL;
    }

    state = (gss_client_state *) malloc(sizeof(gss_client_state));
    pystate = PyCObject_FromVoidPtr(state, NULL);

    if (PyCObject_Check(pydelegatestate)) {
        delegatestate = PyCObject_AsVoidPtr(pydelegatestate);
    }

    result = authenticate_gss_client_init(
        service, principal, gss_flags, delegatestate, state
    );

    if (result == AUTH_GSS_ERROR) {
        return NULL;
    }

    return Py_BuildValue("(iO)", result, pystate);
}
开发者ID:veerakumar123,项目名称:tomcat,代码行数:38,代码来源:kerberos.c


示例12: Py_BuildValue

static PyObject *authGSSImpersonationCleanCtx(PyObject *self, PyObject *args)
{
    gss_impers_state *state;
    PyObject *pystate;
    int result = 0;

    if (!PyArg_ParseTuple(args, "O", &pystate))
        return NULL;

    if (!PyCObject_Check(pystate)) {
        PyErr_SetString(PyExc_TypeError, "Expected a context object");
        return NULL;
    }

    state = (gss_impers_state *)PyCObject_AsVoidPtr(pystate);
    if (state != NULL)
    {
        result = authenticate_gss_impers_cleanctx(state);

    }

    return Py_BuildValue("i", result);
}
开发者ID:may-day,项目名称:s4u2p,代码行数:23,代码来源:s4u2p.c


示例13: _get_array_interface

static int
_get_array_interface(PyObject *obj,
		     PyObject **cobj_p,
		     PyArrayInterface **inter_p)
{
    if (!(*cobj_p = PyObject_GetAttrString(obj, "__array_struct__"))) {
	if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
		PyErr_Clear();
		PyErr_SetString(PyExc_ValueError,
				"no C-struct array interface");
	    }
	return 0;
    }

    if (!PyCObject_Check(*cobj_p) ||  /* conditional 'or's */
	!(*inter_p = PyCObject_AsVoidPtr(*cobj_p)) ||
	(*inter_p)->two != 2) {
	Py_DECREF(*cobj_p);
	PyErr_SetString(PyExc_ValueError, "invalid array interface");
	return 0;
    }
    return 1;
}
开发者ID:Abstak,项目名称:Mastermind_Python,代码行数:23,代码来源:_arraysurfarray.c


示例14: IvrDialogBase_new

// Constructor
static PyObject* IvrDialogBase_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
  static char *kwlist[] = {"ivr_dlg", NULL};
  IvrDialogBase *self;

  self = (IvrDialogBase *)type->tp_alloc(type, 0);
  if (self != NULL) {
	
    PyObject* o_dlg = NULL;
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, &o_dlg)){
	    
      Py_DECREF(self);
      return NULL;
    }
    
    if (!PyCObject_Check(o_dlg)){
	    
      Py_DECREF(self);
      return NULL;
    }
	
    self->p_dlg = (IvrDialog*)PyCObject_AsVoidPtr(o_dlg);
	
    // initialize self.dialog
    self->dialog = IvrSipDialog_FromPtr(&self->p_dlg->dlg);

    if(!self->dialog){
      PyErr_Print();
      ERROR("IvrDialogBase: while creating IvrSipDialog instance\n");
      Py_DECREF(self);
      return NULL;
    }
  }

  DBG("IvrDialogBase_new\n");
  return (PyObject *)self;
}
开发者ID:BackupTheBerlios,项目名称:sems-svn,代码行数:38,代码来源:IvrDialogBase.cpp


示例15: headerNew

/* TODO: permit keyring check + retrofits on copy/load */
static PyObject *hdr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
{
    PyObject *obj = NULL;
    rpmfdObject *fdo = NULL;
    Header h = NULL;
    char *kwlist[] = { "obj", NULL };

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, &obj)) {
	return NULL;
    }

    if (obj == NULL) {
	h = headerNew();
    } else if (PyCObject_Check(obj)) {
	h = PyCObject_AsVoidPtr(obj);
    } else if (hdrObject_Check(obj)) {
	h = headerCopy(((hdrObject*) obj)->h);
    } else if (PyBytes_Check(obj)) {
	h = headerCopyLoad(PyBytes_AsString(obj));
    } else if (rpmfdFromPyObject(obj, &fdo)) {
	Py_BEGIN_ALLOW_THREADS;
	h = headerRead(rpmfdGetFd(fdo), HEADER_MAGIC_YES);
	Py_END_ALLOW_THREADS;
	Py_XDECREF(fdo);
    } else {
    	PyErr_SetString(PyExc_TypeError, "header, blob or file expected");
	return NULL;
    }

    if (h == NULL) {
	PyErr_SetString(pyrpmError, "bad header");
	return NULL;
    }
    
    return hdr_Wrap(subtype, h);
}
开发者ID:kaltsi,项目名称:rpm,代码行数:37,代码来源:header-py.c


示例16: CmissFEelement_wrap

static PyObject*
CmissFEelement_wrap(PyObject* self, PyObject* args)
{
	char *name;
	CmissFEelementObject *cmiss_fe_element;
	PyObject *cmiss_fe_element_cpointer;

	if (!(PyArg_ParseTuple(args,"O:wrap", &cmiss_fe_element_cpointer)
		&& PyCObject_Check(cmiss_fe_element_cpointer)))
	{
		PyErr_SetString(PyExc_AttributeError, "Incorrect argument for wrap function.");
		return NULL;			 
	}

	cmiss_fe_element = PyObject_New(CmissFEelementObject, &CmissFEelementType);
	if (!(cmiss_fe_element->fe_element = ACCESS(FE_element)(
		(struct FE_element *)PyCObject_AsVoidPtr(cmiss_fe_element_cpointer))))
	{
		PyErr_SetString(PyExc_AttributeError, "Unable to extract FE_element pointer.");
		return NULL;			 
	}

	return (PyObject*)cmiss_fe_element;
}
开发者ID:A1kmm,项目名称:libzinc,代码行数:24,代码来源:FE_element.c


示例17: SWIG_Python_ConvertPtr

SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) {
  swig_type_info *tc;
  char  *c = 0;
  static PyObject *SWIG_this = 0;
  int    newref = 0;
  PyObject  *pyobj = 0;

  if (!obj) return 0;
  if (obj == Py_None) {
    *ptr = 0;
    return 0;
  }
#ifdef SWIG_COBJECT_TYPES
  if (!(PyCObject_Check(obj))) {
    if (!SWIG_this)
      SWIG_this = PyString_FromString("this");
    pyobj = obj;
    obj = PyObject_GetAttr(obj,SWIG_this);
    newref = 1;
    if (!obj) goto type_error;
    if (!PyCObject_Check(obj)) {
      Py_DECREF(obj);
      goto type_error;
    }
  }  
  *ptr = PyCObject_AsVoidPtr(obj);
  c = (char *) PyCObject_GetDesc(obj);
  if (newref) Py_DECREF(obj);
  goto cobject;
#else
  if (!(PyString_Check(obj))) {
    if (!SWIG_this)
      SWIG_this = PyString_FromString("this");
    pyobj = obj;
    obj = PyObject_GetAttr(obj,SWIG_this);
    newref = 1;
    if (!obj) goto type_error;
    if (!PyString_Check(obj)) {
      Py_DECREF(obj);
      goto type_error;
    }
  } 
  c = PyString_AsString(obj);
  /* Pointer values must start with leading underscore */
  if (*c != '_') {
    *ptr = (void *) 0;
    if (strcmp(c,"NULL") == 0) {
      if (newref) { Py_DECREF(obj); }
      return 0;
    } else {
      if (newref) { Py_DECREF(obj); }
      goto type_error;
    }
  }
  c++;
  c = SWIG_UnpackData(c,ptr,sizeof(void *));
  if (newref) { Py_DECREF(obj); }
#endif

#ifdef SWIG_COBJECT_TYPES
cobject:
#endif

  if (ty) {
    tc = SWIG_TypeCheck(c,ty);
    if (!tc) goto type_error;
    *ptr = SWIG_TypeCast(tc,(void*) *ptr);
  }

  if ((pyobj) && (flags & SWIG_POINTER_DISOWN)) {
    PyObject *zero = PyInt_FromLong(0);
    PyObject_SetAttrString(pyobj,(char*)"thisown",zero);
    Py_DECREF(zero);
  }
  return 0;

type_error:
  if (flags & SWIG_POINTER_EXCEPTION) {
    if (ty && c) {
      char *temp = (char *) malloc(64+strlen(ty->name)+strlen(c));
      sprintf(temp,"Type error. Got %s, expected %s", c, ty->name);
      PyErr_SetString(PyExc_TypeError, temp);
      free((char *) temp);
    } else {
      PyErr_SetString(PyExc_TypeError,"Expected a pointer");
    }
  }
  return -1;
}
开发者ID:BackupTheBerlios,项目名称:sumi-svn,代码行数:89,代码来源:cfastxor_wrap.c


示例18: initMMTK_pose

PyMODINIT_FUNC
initMMTK_pose(void)
{
  PyObject *m, *d, *module;
#ifdef WITH_MPI
  PyObject *mpi_module;
#endif
  static void *PyFF_API[PyFF_API_pointers];

  /* Create the module and add the functions */
  m = Py_InitModule("MMTK_pose", pose_methods);
  
  /* Import the array and MPI modules */
#ifdef import_array
  import_array();
#endif
#ifdef WITH_MPI
  import_mpi();
  mpi_module = PyImport_ImportModule("Scientific.MPI");
  if (mpi_module != NULL) {
    PyObject *module_dict = PyModule_GetDict(mpi_module);
    PyExc_MPIError = PyDict_GetItemString(module_dict, "MPIError");
  }
#endif

  /* Add C API pointer array */ 
  PyFF_API[PyFFEnergyTerm_Type_NUM] = (void *)&PyFFEnergyTerm_Type;
  PyFF_API[PyFFEvaluator_Type_NUM] = (void *)&PyFFEvaluator_Type;
  PyFF_API[PyNonbondedList_Type_NUM] = (void *)&PyNonbondedList_Type;
  PyFF_API[PySparseFC_New_NUM] = (void *)&PySparseFC_New;
  PyFF_API[PySparseFC_Type_NUM] = (void *)&PySparseFC_Type;
  PyFF_API[PySparseFC_Zero_NUM] = (void *)&PySparseFC_Zero;
  PyFF_API[PySparseFC_Find_NUM] = (void *)&PySparseFC_Find;
  PyFF_API[PySparseFC_AddTerm_NUM] = (void *)&PySparseFC_AddTerm;
  PyFF_API[PySparseFC_CopyToArray_NUM] = (void *)&PySparseFC_CopyToArray;
  PyFF_API[PySparseFC_AsArray_NUM] = (void *)&PySparseFC_AsArray;
  PyFF_API[PySparseFC_VectorMultiply_NUM] = (void *)&PySparseFC_VectorMultiply;
  PyFF_API[PySparseFC_Scale_NUM] = (void *)&PySparseFC_Scale;
  PyFF_API[PyFFEnergyTerm_New_NUM] = (void *)&PyFFEnergyTerm_New;
  PyFF_API[PyFFEvaluator_New_NUM] = (void *)&PyFFEvaluator_New;
  PyFF_API[PyNonbondedListUpdate_NUM] = (void *)&PyNonbondedListUpdate;
  PyFF_API[PyNonbondedListIterate_NUM] = (void *)&PyNonbondedListIterate;

#ifdef EXTENDED_TYPES
  if (PyType_Ready(&PyFFEnergyTerm_Type) < 0)
    return;
  if (PyType_Ready(&PyFFEvaluator_Type) < 0)
    return;
  if (PyType_Ready(&PyNonbondedList_Type) < 0)
    return;
  if (PyType_Ready(&PySparseFC_Type) < 0)
    return;
#else
  PyFFEnergyTerm_Type.ob_type = &PyType_Type;
  PyFFEvaluator_Type.ob_type = &PyType_Type;
  PyNonbondedList_Type.ob_type = &PyType_Type;
  PySparseFC_Type.ob_type = &PyType_Type;
#endif

  d = PyModule_GetDict(m);
  PyDict_SetItemString(d, "_C_API",
		       PyCObject_FromVoidPtr((void *)PyFF_API, NULL));
  PyDict_SetItemString(d, "EnergyTerm", (PyObject *)&PyFFEnergyTerm_Type);
  PyDict_SetItemString(d, "EnergyEvaluator",
		       (PyObject *)&PyFFEvaluator_Type);

  /* Get the energy conversion factor from Units */
  module = PyImport_ImportModule("MMTK.Units");
  if (module != NULL) {
    PyObject *module_dict = PyModule_GetDict(module);
    PyObject *factor = PyDict_GetItemString(module_dict,
					    "electrostatic_energy");
    electrostatic_energy_factor = PyFloat_AsDouble(factor);
  }

  /* Get function pointers from _universe */
  module = PyImport_ImportModule("MMTK_universe");
  if (module != NULL) {
    PyObject *module_dict = PyModule_GetDict(module);
    PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API");
    PyObject *fn;
    if (PyCObject_Check(c_api_object))
      PyUniverse_API = (void **)PyCObject_AsVoidPtr(c_api_object);
    fn = PyDict_GetItemString(module_dict,
			      "infinite_universe_distance_function");
    distance_vector_pointer = (distance_fn *)PyCObject_AsVoidPtr(fn);
    fn = PyDict_GetItemString(module_dict,
			      "orthorhombic_universe_distance_function");
    orthorhombic_distance_vector_pointer =
                        (distance_fn *)PyCObject_AsVoidPtr(fn);
    fn = PyDict_GetItemString(module_dict,
			      "parallelepipedic_universe_distance_function");
    parallelepipedic_distance_vector_pointer =
                        (distance_fn *)PyCObject_AsVoidPtr(fn);
  }

  /* Check for errors */
  if (PyErr_Occurred())
    Py_FatalError("can't initialize module MMTK_forcefield");
}
开发者ID:CCBatIIT,项目名称:AlGDock,代码行数:100,代码来源:MMTK_pose.c


示例19: SIP_MODULE_ENTRY

PyMODINIT_FUNC SIP_MODULE_ENTRY()
#endif
{
    static PyMethodDef sip_methods[] = {
        {0, 0, 0, 0}
    };

#if PY_MAJOR_VERSION >= 3
    static PyModuleDef sip_module_def = {
        PyModuleDef_HEAD_INIT,
        "MyMath",
        NULL,
        -1,
        sip_methods,
        NULL,
        NULL,
        NULL,
        NULL
    };
#endif

    PyObject *sipModule, *sipModuleDict;
    PyObject *sip_sipmod, *sip_capiobj;

    /* Initialise the module and get it's dictionary. */
#if PY_MAJOR_VERSION >= 3
    sipModule = PyModule_Create(&sip_module_def);
#elif PY_VERSION_HEX >= 0x02050000
    sipModule = Py_InitModule(sipName_MyMath, sip_methods);
#else
    sipModule = Py_InitModule(const_cast<char *>(sipName_MyMath), sip_methods);
#endif

    if (sipModule == NULL)
        SIP_MODULE_RETURN(NULL);

    sipModuleDict = PyModule_GetDict(sipModule);

    /* Get the SIP module's API. */
#if PY_VERSION_HEX >= 0x02050000
    sip_sipmod = PyImport_ImportModule(SIP_MODULE_NAME);
#else
    sip_sipmod = PyImport_ImportModule(const_cast<char *>(SIP_MODULE_NAME));
#endif

    if (sip_sipmod == NULL)
    {
        SIP_MODULE_DISCARD(sipModule);
        SIP_MODULE_RETURN(NULL);
    }

    sip_capiobj = PyDict_GetItemString(PyModule_GetDict(sip_sipmod), "_C_API");
    Py_DECREF(sip_sipmod);

#if defined(SIP_USE_PYCAPSULE)
    if (sip_capiobj == NULL || !PyCapsule_CheckExact(sip_capiobj))
#else
    if (sip_capiobj == NULL || !PyCObject_Check(sip_capiobj))
#endif
    {
        SIP_MODULE_DISCARD(sipModule);
        SIP_MODULE_RETURN(NULL);
    }

#if defined(SIP_USE_PYCAPSULE)
    sipAPI_MyMath = reinterpret_cast<const sipAPIDef *>(PyCapsule_GetPointer(sip_capiobj, SIP_MODULE_NAME "._C_API"));
#else
    sipAPI_MyMath = reinterpret_cast<const sipAPIDef *>(PyCObject_AsVoidPtr(sip_capiobj));
#endif

#if defined(SIP_USE_PYCAPSULE)
    if (sipAPI_MyMath == NULL)
    {
        SIP_MODULE_DISCARD(sipModule);
        SIP_MODULE_RETURN(NULL);
    }
#endif

    /* Export the module and publish it's API. */
    if (sipExportModule(&sipModuleAPI_MyMath,SIP_API_MAJOR_NR,SIP_API_MINOR_NR,0) < 0)
    {
        SIP_MODULE_DISCARD(sipModule);
        SIP_MODULE_RETURN(0);
    }
    /* Initialise the module now all its dependencies have been set up. */
    if (sipInitModule(&sipModuleAPI_MyMath,sipModuleDict) < 0)
    {
        SIP_MODULE_DISCARD(sipModule);
        SIP_MODULE_RETURN(0);
    }

    SIP_MODULE_RETURN(sipModule);
}
开发者ID:ax003d,项目名称:PythonSamples,代码行数:93,代码来源:sipMyMathcmodule.cpp


示例20: mlabraw_put

PyObject * mlabraw_put(PyObject *, PyObject *args)
{
  char *lName;
  PyObject *lHandle;
  PyObject *lSource;
  mxArray *lArray = NULL;
  //FIXME should make these objects const
  if (! PyArg_ParseTuple(args, "OsO:put", &lHandle, &lName, &lSource)) return NULL;
  if (! PyCObject_Check(lHandle)) {
    PyErr_SetString(PyExc_TypeError, "Invalid object passed as mlabraw session handle");
    return NULL;
  }
  Py_INCREF(lSource);

  if (PyString_Check(lSource)) {
    lArray = char2mx(lSource);
  } else {
    lArray = numeric2mx(lSource);
  }
  Py_DECREF(lSource);

  if (lArray == NULL) {
    return NULL;   // Above converter already set error message
  }


// for matlab version >= 6.5 (FIXME UNTESTED)
#ifdef _V6_5_OR_LATER
  if (engPutVariable((Engine *)PyCObject_AsVoidPtr(lHandle), lName, lArray) != 0) {
#else
  mxSetName(lArray, lName);
  if (engPutArray((Engine *)PyCObject_AsVoidPtr(lHandle), lArray) != 0) {
#endif
    PyErr_SetString(mlabraw_error,
                   "Unable to put matrix into MATLAB(TM) workspace");
    mxDestroyArray(lArray);
    return NULL;
  }
  mxDestroyArray(lArray);
  Py_INCREF(Py_None);
  return Py_None;
}

static PyMethodDef MlabrawMethods[] = {
  { "open",       mlabraw_open,       METH_VARARGS, open_doc },
  { "close",      mlabraw_close,      METH_VARARGS, close_doc },
  { "oldeval",    mlabraw_oldeval,    METH_VARARGS, ""       },
  { "eval",       mlabraw_eval,       METH_VARARGS, eval_doc },  //FIXME doc
  { "get",        mlabraw_get,        METH_VARARGS, get_doc },
  { "put",        mlabraw_put,        METH_VARARGS, put_doc },
  { NULL,         NULL,               0           , NULL}, // sentinel
};

PyMODINIT_FUNC initmlabraw(void)
{
  PyObject *module =
    Py_InitModule4("mlabraw",
      MlabrawMethods,
"Mlabraw -- Low-level MATLAB(tm) Engine Interface\n"
"\n"
"  open  - Open a MATLAB(tm) engine session\n"
"  close - Close a MATLAB(tm) engine session\n"
"  eval  - Evaluates a string in the MATLAB(tm) session\n"
"  get   - Gets a matrix from the MATLAB(tm) session\n"
"  put   - Places a matrix into the MATLAB(tm) session\n"
"\n"



"The Numeric package must be installed for this module to be used.\n"
"\n"
"Copyright & Disclaimer\n"
"======================\n"
"Copyright (c) 2002-2007 Alexander Schmolck <[email protected]>\n"
"\n"
"Copyright (c) 1998,1999 Andrew Sterian. All Rights Reserved. mailto: [email protected]\n"
"\n"
"Copyright (c) 1998,1999 THE REGENTS OF THE UNIVERSITY OF MICHIGAN. ALL RIGHTS RESERVED \n"
"\n"
"Permission to use, copy, modify, and distribute this software and its\n"
"documentation for any purpose and without fee is hereby granted, provided\n"
"that the above copyright notices appear in all copies and that both these\n"
"copyright notices and this permission notice appear in supporting\n"
"documentation, and that the name of The University of Michigan not be used\n"
"in advertising or publicity pertaining to distribution of the software\n"
"without specific, written prior permission.\n"
"\n"
"THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION AS TO ITS FITNESS\n"
"FOR ANY PURPOSE, AND WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR\n"
"IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF\n"
"MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE REGENTS OF THE\n"
"UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE FOR ANY DAMAGES, INCLUDING\n"
"SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY\n"
"CLAIM ARISING OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN IF\n"
"IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.\n"
"\n",
       0,
       PYTHON_API_VERSION);

  /* This macro, defined in arrayobject.h, loads the Numeric API interface */
//.........这里部分代码省略.........
开发者ID:ericjsolis,项目名称:danapeerlab,代码行数:101,代码来源:mlabraw.cpp



注:本文中的PyCObject_Check函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PyCObject_FromVoidPtr函数代码示例发布时间:2022-05-30
下一篇:
C++ PyCObject_AsVoidPtr函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap