2[c@`sdZddlmZmZmZddlmZddlmZm Z m Z m Z m Z m Z mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%ddlm&Z&ej'Z(idd6d d 6d d gd 6dd6dd6dd6dd6dd6Z)iidd6dd6dd6dd6dd6dd 6dd!6dd"6dd#6dd$6dd%6d&d'6dd(6dd)6dd*6dd+6dd,6d-6d.d6d/d6d0d$6gd6dd6dd16dd26d3d6gd 6dd!6dd46gd"6dd#6dd56dd66d7d%6dd'6dd(6d8d96d:d;6d<d=6d>d?6dd@6ddA6ddB6dCd)6dDd*6dEd+6dFd,6idGe 6de e 6dH6idId6idJe 6dKidLe 6gd$6dMid e 6dNgd 6dOd16eee ee edP6iidQe 6d6dRd6dSd"6dTd 6idUe 6dVidWe 6gd$6dMid e 6dXdYgd 6dZd16edP6id[d6d\d#6d]d!6d^d6idJe 6d_id`e 6gd$6dad16dMid e 6dXdNdbgd 6edP6idcd=6ddidGe 6gd+6ded@6edP6iedP6dZd16gZ*i idfeee6d;6idfeee6d96idce6d=6idgidGe 6geee6d*6idgidGe 6geee6d)6iddidGee e6dhee e6ge6d+6idieee6dA6idieee6dB6ddj6iidkeee6dleee e6dme6dke6d6idneee6doeee e6dne6dne6d"6idbeee6dpeee e6dpe6dbe6d 6idqe6d26idre6d46idse6d56iidte e6d6ideeee%du6dv6idwe 6idxe6idyee ee ee6idzee ee ee e6id{ee eee6id|ee eee e6gd$6idMdNge6id e 6gd 6edP6iid}e6id~e6gd6ide6ide6idbe6gd 6eeedP6dd6iide 6dide 6gd$6dbdYid e 6dXgd 6eeedP6iide 6ide6ide6gd6ide6ide6gd 6eeedP6dd6idd6dd%6edP6dd6iide 6ide6de e6dgd6eeee!eedP6dd6iidwe 6dide6dide 6gd$6didbe6gd 6eeedP6idid@6edP6g Z+ia,dZ-dZ.dS(sK Build call-back mechanism for f2py2e. Copyright 2000 Pearu Peterson all rights reserved, Pearu Peterson Permission to use, modify, and distribute this software is given under the terms of the NumPy License. NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. $Date: 2005/07/20 11:27:58 $ Pearu Peterson i(tdivisiontabsolute_importtprint_functioni(t __version__(t applyrulest debugcapit dictappendterrmesstgetargsthasnotetisarrayt iscomplextiscomplexarraytiscomplexfunctiont isfunctiont isintent_ct isintent_hidet isintent_intisintent_inouttisintent_nothidet isintent_outt isoptionalt isrequiredtisscalartisstringtisstringfunctiont issubroutinetl_andtl_nottl_ortoutmesstreplacet stripcommat throw_error(tcfuncssPtypedef #rctype#(*#name#_typedef)(#optargs_td##args_td##strarglens_td##noargs#);t cbtypedefss #begintitle# PyObject *#name#_capi = NULL;/*was Py_None*/ PyTupleObject *#name#_args_capi = NULL; int #name#_nofargs = 0; jmp_buf #name#_jmpbuf; /*typedef #rctype#(*#name#_typedef)(#optargs_td##args_td##strarglens_td##noargs#);*/ #static# #rctype# #callbackname# (#optargs##args##strarglens##noargs#) { PyTupleObject *capi_arglist = #name#_args_capi; PyObject *capi_return = NULL; PyObject *capi_tmp = NULL; PyObject *capi_arglist_list = NULL; int capi_j,capi_i = 0; int capi_longjmp_ok = 1; #decl# #ifdef F2PY_REPORT_ATEXIT f2py_cb_start_clock(); #endif CFUNCSMESS("cb:Call-back function #name# (maxnofargs=#maxnofargs#(-#nofoptargs#))\n"); CFUNCSMESSPY("cb:#name#_capi=",#name#_capi); if (#name#_capi==NULL) { capi_longjmp_ok = 0; #name#_capi = PyObject_GetAttrString(#modulename#_module,"#argname#"); } if (#name#_capi==NULL) { PyErr_SetString(#modulename#_error,"cb: Callback #argname# not defined (as an argument or module #modulename# attribute).\n"); goto capi_fail; } if (F2PyCapsule_Check(#name#_capi)) { #name#_typedef #name#_cptr; #name#_cptr = F2PyCapsule_AsVoidPtr(#name#_capi); #returncptr#(*#name#_cptr)(#optargs_nm##args_nm##strarglens_nm#); #return# } if (capi_arglist==NULL) { capi_longjmp_ok = 0; capi_tmp = PyObject_GetAttrString(#modulename#_module,"#argname#_extra_args"); if (capi_tmp) { capi_arglist = (PyTupleObject *)PySequence_Tuple(capi_tmp); if (capi_arglist==NULL) { PyErr_SetString(#modulename#_error,"Failed to convert #modulename#.#argname#_extra_args to tuple.\n"); goto capi_fail; } } else { PyErr_Clear(); capi_arglist = (PyTupleObject *)Py_BuildValue("()"); } } if (capi_arglist == NULL) { PyErr_SetString(#modulename#_error,"Callback #argname# argument list is not set.\n"); goto capi_fail; } #setdims# #ifdef PYPY_VERSION #define CAPI_ARGLIST_SETITEM(idx, value) PyList_SetItem((PyObject *)capi_arglist_list, idx, value) capi_arglist_list = PySequence_List(capi_arglist); if (capi_arglist_list == NULL) goto capi_fail; #else #define CAPI_ARGLIST_SETITEM(idx, value) PyTuple_SetItem((PyObject *)capi_arglist, idx, value) #endif #pyobjfrom# #undef CAPI_ARGLIST_SETITEM #ifdef PYPY_VERSION CFUNCSMESSPY("cb:capi_arglist=",capi_arglist_list); #else CFUNCSMESSPY("cb:capi_arglist=",capi_arglist); #endif CFUNCSMESS("cb:Call-back calling Python function #argname#.\n"); #ifdef F2PY_REPORT_ATEXIT f2py_cb_start_call_clock(); #endif #ifdef PYPY_VERSION capi_return = PyObject_CallObject(#name#_capi,(PyObject *)capi_arglist_list); Py_DECREF(capi_arglist_list); capi_arglist_list = NULL; #else capi_return = PyObject_CallObject(#name#_capi,(PyObject *)capi_arglist); #endif #ifdef F2PY_REPORT_ATEXIT f2py_cb_stop_call_clock(); #endif CFUNCSMESSPY("cb:capi_return=",capi_return); if (capi_return == NULL) { fprintf(stderr,"capi_return is NULL\n"); goto capi_fail; } if (capi_return == Py_None) { Py_DECREF(capi_return); capi_return = Py_BuildValue("()"); } else if (!PyTuple_Check(capi_return)) { capi_return = Py_BuildValue("(N)",capi_return); } capi_j = PyTuple_Size(capi_return); capi_i = 0; #frompyobj# CFUNCSMESS("cb:#name#:successful\n"); Py_DECREF(capi_return); #ifdef F2PY_REPORT_ATEXIT f2py_cb_stop_clock(); #endif goto capi_return_pt; capi_fail: fprintf(stderr,"Call-back #name# failed.\n"); Py_XDECREF(capi_return); Py_XDECREF(capi_arglist_list); if (capi_longjmp_ok) longjmp(#name#_jmpbuf,-1); capi_return_pt: ; #return# } #endtitle# tbodyssetjmp.ht CFUNCSMESStneeds #maxnofargs#t maxnofargss #nofoptargs#t nofoptargssC def #argname#(#docsignature#): return #docreturn#\n\ #docstrsigns#tdocstrsc {{}\verb@def #argname#(#latexdocsignature#): return #docreturn#@{}} #routnote# #latexdocstrsigns#t latexdocstrs1def #argname#(#docsignature#): return #docreturn#t docstrshorts tdeclt,targsttoptargst pyobjfromtfreememtargs_tdt optargs_tdtargs_nmt optargs_nmt frompyobjtsetdimss\n" "t docstrsignstlatexdocstrsignstlatexdocstrreqtlatexdocstropttlatexdocstrouttlatexdocstrcbst separatorsfors/*decl*/s /*pyobjfrom*/s /*frompyobj*/treturnt strarglenss /*freemem*/t strarglens_tdt strarglens_nmtnoargss /*setdims*/s Required arguments:t docstrreqs Optional arguments:t docstropts Return objects:t docstrouts Call-back functions:t docstrcbst docreturntdocsignt docsignopts\noindent Required arguments:s\noindent Optional arguments:s\noindent Return objects:s\noindent Call-back functions:s --- #note#troutnotes #ctype# return_value;s) CFUNCSMESS("cb:Getting return_value->");s if (capi_j>capi_i) GETSCALARFROMPYTUPLE(capi_return,capi_i++,&return_value,#ctype#,"#ctype#_from_pyobj failed in converting return_value of call-back function #name# to C #ctype#\n");s5 fprintf(stderr,"#showvalueformat#.\n",return_value);s#ctype#_from_pyobjtGETSCALARFROMPYTUPLEs return return_value;t_checks? fprintf(stderr,"debug-capi:cb:#name#:%d:\n",return_value_len);s)#ctype# return_value,int return_value_lensreturn_value,&return_value_lens #ctype# ,ints+ CFUNCSMESS("cb:Getting return_value->\"");s\ if (capi_j>capi_i) GETSTRFROMPYTUPLE(capi_return,capi_i++,return_value,return_value_len);s7 fprintf(stderr,"#showvalueformat#\".\n",return_value);sstring.htGETSTRFROMPYTUPLEsreturn;s< #ifndef F2PY_CB_RETURNCOMPLEX #ctype# *return_value #endif s3 #ifndef F2PY_CB_RETURNCOMPLEX return_value #endif s0 #ifndef F2PY_CB_RETURNCOMPLEX #ctype# * #endif s< #ifdef F2PY_CB_RETURNCOMPLEX #ctype# return_value; #endif s if (capi_j>capi_i) #ifdef F2PY_CB_RETURNCOMPLEX GETSCALARFROMPYTUPLE(capi_return,capi_i++,&return_value,#ctype#,"#ctype#_from_pyobj failed in converting return_value of call-back function #name# to C #ctype#\n"); #else GETSCALARFROMPYTUPLE(capi_return,capi_i++,return_value,#ctype#,"#ctype#_from_pyobj failed in converting return_value of call-back function #name# to C #ctype#\n"); #endif s #ifdef F2PY_CB_RETURNCOMPLEX fprintf(stderr,"#showvalueformat#.\n",(return_value).r,(return_value).i); #else fprintf(stderr,"#showvalueformat#.\n",(*return_value).r,(*return_value).i); #endif sJ #ifdef F2PY_CB_RETURNCOMPLEX return return_value; #else return; #endif s#ctype#s #pydocsignout#s"\item[]{{}\verb@#pydocsignout#@{}}s#rname#,s #pydocsign#s\item[]{{}\verb@#pydocsign#@{}}s--- See above.s #varname#,tdepends#ctype# #varname_i#s#ctype# *#varname_i#_cb_capis#ctype# *#varname_i#s #varname_i#s#varname_i#_cb_capis #ctype# *s,int #varname_i#_cb_lens,ints,#varname_i#_cb_lens, #ctype# #varname_i#=(*#varname_i#_cb_capi);s8intent(c,out) is forbidden for callback scalar argumentsterrors& CFUNCSMESS("cb:Getting #varname#->");s if (capi_j>capi_i) GETSCALARFROMPYTUPLE(capi_return,capi_i++,#varname_i#_cb_capi,#ctype#,"#ctype#_from_pyobj failed in converting argument #varname# of call-back function #name# to C #ctype#\n");s4 fprintf(stderr,"#showvalueformat#.\n",#varname_i#);s= fprintf(stderr,"#showvalueformat#.\n",*#varname_i#_cb_capi);sH fprintf(stderr,"#showvalueformat#.\n",(#varname_i#).r,(#varname_i#).i);sZ fprintf(stderr,"#showvalueformat#.\n",(*#varname_i#_cb_capi).r,(*#varname_i#_cb_capi).i);su if (#name#_nofargs>capi_i) if (CAPI_ARGLIST_SETITEM(capi_i++,pyobj_from_#ctype#1(#varname_i#))) goto capi_fail;s if (#name#_nofargs>capi_i) if (CAPI_ARGLIST_SETITEM(capi_i++,pyarr_from_p_#ctype#1(#varname_i#_cb_capi))) goto capi_fail;spyobj_from_#ctype#1spyarr_from_p_#ctype#1t _optionals( CFUNCSMESS("cb:Getting #varname#->\"");s] if (capi_j>capi_i) GETSTRFROMPYTUPLE(capi_return,capi_i++,#varname_i#,#varname_i#_cb_len);sM fprintf(stderr,"#showvalueformat#\":%d:.\n",#varname_i#,#varname_i#_cb_len);sf fprintf(stderr,"debug-capi:cb:#varname#=\"#showvalueformat#\":%d:\n",#varname_i#,#varname_i#_cb_len);s if (#name#_nofargs>capi_i) if (CAPI_ARGLIST_SETITEM(capi_i++,pyobj_from_#ctype#1size(#varname_i#,#varname_i#_cb_len))) goto capi_fail;s if (#name#_nofargs>capi_i) { int #varname_i#_cb_dims[] = {#varname_i#_cb_len}; if (CAPI_ARGLIST_SETITEM(capi_i++,pyarr_from_p_#ctype#1(#varname_i#,#varname_i#_cb_dims))) goto capi_fail; }spyobj_from_#ctype#1sizes3 npy_intp #varname_i#_Dims[#rank#] = {#rank*[-1]#};s #cbsetdims#;t_depends- fprintf(stderr,"debug-capi:cb:#varname#\n");s  if (#name#_nofargs>capi_i) { int itemsize_ = #atype# == NPY_STRING ? 1 : 0; /*XXX: Hmm, what will destroy this array??? */ PyArrayObject *tmp_arr = (PyArrayObject *)PyArray_New(&PyArray_Type,#rank#,#varname_i#_Dims,#atype#,NULL,(char*)#varname_i#,itemsize_,NPY_ARRAY_CARRAY,NULL); s  if (#name#_nofargs>capi_i) { int itemsize_ = #atype# == NPY_STRING ? 1 : 0; /*XXX: Hmm, what will destroy this array??? */ PyArrayObject *tmp_arr = (PyArrayObject *)PyArray_New(&PyArray_Type,#rank#,#varname_i#_Dims,#atype#,NULL,(char*)#varname_i#,itemsize_,NPY_ARRAY_FARRAY,NULL); sw if (tmp_arr==NULL) goto capi_fail; if (CAPI_ARGLIST_SETITEM(capi_i++,(PyObject *)tmp_arr)) goto capi_fail; }s if (capi_j>capi_i) { PyArrayObject *rv_cb_arr = NULL; if ((capi_tmp = PyTuple_GetItem(capi_return,capi_i++))==NULL) goto capi_fail; rv_cb_arr = array_from_pyobj(#atype#,#varname_i#_Dims,#rank#,F2PY_INTENT_INs|F2PY_INTENT_Cs,capi_tmp); if (rv_cb_arr == NULL) { fprintf(stderr,"rv_cb_arr is NULL\n"); goto capi_fail; } MEMCOPY(#varname_i#,PyArray_DATA(rv_cb_arr),PyArray_NBYTES(rv_cb_arr)); if (capi_tmp != (PyObject *)rv_cb_arr) { Py_DECREF(rv_cb_arr); } }s fprintf(stderr,"<-.\n");tMEMCOPYcC`s{gt|dtjjD]*}||d.krP| d.j|qPqPWn| d/tj|dd0<| d.j|dd0| d.tj|dsx r   #           %&