o 6a@sddlZddlZddlZddlZddlZddlZddlZddlZddlZ ddl m Z m Z m Z ddlmZGdddejZGdddeZGd d d ejZGd d d ejZdS) N)assert_ assert_equalIS_PYPY)utilc@seZdZdZejdddddZejj e ddd d Z d d Z ejj ejd kddddZejj ejd kddddZddZddZdS)TestF77Callbacka subroutine t(fun,a) integer a cf2py intent(out) a external fun call fun(a) end subroutine func(a) cf2py intent(in,out) a integer a a = a + 11 end subroutine func0(a) cf2py intent(out) a integer a a = 11 end subroutine t2(a) cf2py intent(callback) fun integer a cf2py intent(out) a external fun call fun(a) end subroutine string_callback(callback, a) external callback double precision callback double precision a character*1 r cf2py intent(out) a r = 'r' a = callback(r) end subroutine string_callback_array(callback, cu, lencu, a) external callback integer callback integer lencu character*8 cu(lencu) integer a cf2py intent(out) a a = callback(cu, lencu) end subroutine hidden_callback(a, r) external global_f cf2py intent(callback, hide) global_f integer a, r, global_f cf2py intent(out) r r = global_f(a) end subroutine hidden_callback2(a, r) external global_f integer a, r, global_f cf2py intent(out) r r = global_f(a) end namezt,t2,cCs||dSN)check_function)selfrr @/usr/lib/python3/dist-packages/numpy/f2py/tests/test_callback.pytest_allQszTestF77Callback.test_allz,PyPy cannot modify tp_doc after PyType_Ready)reasoncCstd}t|jjj|dS)Na a = t(fun,[fun_extra_args]) Wrapper for ``t``. Parameters ---------- fun : call-back function Other Parameters ---------------- fun_extra_args : input tuple, optional Default: () Returns ------- a : int Notes ----- Call-back functions:: def fun(): return a Return objects: a : int )textwrapdedentrmodulet__doc__)r expectedr r rtest_docstringUs zTestF77Callback.test_docstringcCst|j|}|dd}t|dkt||dddd}t|dkt||dddd}t|d kt||d dd d}t|d kt||d dtjfd}t|dkt||tjtjfd}t|dkt|||jjdd}t|dkt|||jj}t|dkt|||jjj }t|dkt|Gddd}|}||}t|dkt|||j }t|dkt|dS)NcSdS)Nr r r r rvz0TestF77Callback.check_function..rcSrNr ar r rrxr))fun_extra_argsrcSs|Sr r rr r rrzrr cSsd|Srr rr r rr|) cSs t|Sr )mathdegreesrr r rr~s  c@seZdZddZddZdS)z)TestF77Callback.check_function..AcSr)Nr#r r r r r__call__z2TestF77Callback.check_function..A.__call__cSr)N r r*r r rmthr,z-TestF77Callback.check_function..A.mthN)__name__ __module__ __qualname__r+r.r r r rAs r2r#r-) getattrrrreprr%pir&funcfunc0 _cpointerr.)r rrrr2rr r rr ts2    zTestF77Callback.check_functionwin32z)Fails with MinGW64 Gfortran (Issue #9673)cCs2dd}t|jd}||}t|dkt|dS)NcSs|dkrdSdS)Nr9rrr )coder r rcallbacksz6TestF77Callback.test_string_callback..callbackstring_callbackr)r3rrr4)r r<fr9r r rtest_string_callbacks z$TestF77Callback.test_string_callbackcCsFtdd}dd}t|jd}|||t|}t|dkt|dS)N)rS1cSs6|j|dfkr dS|jdkrdSt|dksdSdS)Nr@rrAr)shapedtypenpall)culencur r rr<s z.callbackstring_callback_arrayr)rGzerosr3rlenrr4)r rIr<r>resr r rtest_string_callback_arrays  z*TestF77Callback.test_string_callback_arraycspgfddfddfdddD}|D]}|q|D]}|q$dr6tdS) Ncs*tdjdd}t|dkdS)NgMbP?cSrN{r r r r rrrz?TestF77Callback.test_threadsafety..cb..rQ*)timesleeprrr)r9r*r rcbs  z-TestF77Callback.test_threadsafety..cbcsZztdD]}j}t|dk|qWdSty,tYdSw)N2rR) rangerrrr Exceptionappend traceback format_exc)rjr9)rUerrorsr r rrunners     z1TestF77Callback.test_threadsafety..runnercs*g|]}tdD] }tj|fdqqS))targetargs)rW threadingThread).0argn)r^r r s z5TestF77Callback.test_threadsafety..)rt2z )startjoinAssertionError)r threadsrr )rUr]r^r rtest_threadsafetys     z!TestF77Callback.test_threadsafetyc Cshz|jdWnty#}ztt|dWYd}~nd}~wwz|jdWntyG}ztt|dWYd}~nd}~wwdd|j_|jd}t|dkdd|j_|jd}t|dk|j`z|jdWnty}ztt|dWYd}~nd}~wwd d d|j_|jd}t|d k|jd}t|dkdS) NrBzCallback global_f not definedz!cb: Callback global_f not definedcS|dS)Nrr xr r rrr"z6TestF77Callback.test_hidden_callback..rDcSrn)NrBr ror r rrr"rrcSrn)NrDr ror r rrr"r)r)rhidden_callbackrXrstr startswithhidden_callback2global_f)r msgr9r r rtest_hidden_callbacks<         z$TestF77Callback.test_hidden_callbackN)r/r0r1r;pytestmark parametrizesplitrxfailrrr skipifsysplatformr?rOrmrwr r r rrs&A  #    &rc@seZdZdZdgZdS)TestF77CallbackPythonTLSz[ Callback tests using Python thread-local storage instead of compiler-provided z-DF2PY_USE_PYTHON_TLSN)r/r0r1roptionsr r r rrs rc@s"eZdZdZedZddZdS)TestF90Callback.f90z function gh17797(f, y) result(r) external f integer(8) :: r, f integer(8), dimension(:) :: y r = f(0) r = r + sum(y) end function gh17797 cCs:dd}tjgdtjd}|j||}|dksJdS)NcSrnrPr ror r rincrsz*TestF90Callback.test_gh17797..incrrrBrDrF)rGarrayint64rgh17797)r ryr9r r r test_gh17797szTestF90Callback.test_gh17797N)r/r0r1suffixrrr;rr r r rrs  rc@s&eZdZdZdZedZddZdS) TestGH18335zThe reproduction of the reported issue requires specific input that extensions may break the issue conditions, so the reproducer is implemented as a separate test class. Do not extend this test with other tests! ra ! When gh18335_workaround is defined as an extension, ! the issue cannot be reproduced. !subroutine gh18335_workaround(f, y) ! implicit none ! external f ! integer(kind=1) :: y(1) ! call f(y) !end subroutine gh18335_workaround function gh18335(f) result (r) implicit none external f integer(kind=1) :: y(1), r y(1) = 123 call f(y) r = y(1) end function gh18335 cCs8dd}tjgdtjd}|j|}|dksJdS)NcSs|dd7<dS)Nrrr ror r rfooAsz%TestGH18335.test_gh18335..foorr|)rGrint8rgh18335)r rrr9r r r test_gh18335?s zTestGH18335.test_gh18335N) r/r0r1rrrrr;rr r r rr!s r)r%rr~rxrbrZrSrandomnumpyrG numpy.testingrrrrF2PyTestrrrrr r r rs  r