+
    nDj%                     4   ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
t
]
P                  P                  t. ROtR.tR tR t] P$                  R 4       tR tR tR	 tR
 tR tR tR tRR/R ltR tR tR tR t]
P                  PA                  R]! 4       4      R 4       t!]
P                  PA                  R]! 4       4      R 4       t"]
P                  PA                  R]! 4       4      R 4       t#R t$]
P                  PA                  R]! 4       4      R 4       t%]
P                  PA                  R]! 4       4      R 4       t&]
P                  PA                  R]! 4       4      R 4       t']
P                  PA                  R]! 4       4      R 4       t(R# )    N)utilsystemc                 (    \        \        V  R 24      # )_memory_pool)getattrpabackend_names   &S/data/cameron/venvs/s3viz/lib/python3.14/site-packages/pyarrow/tests/test_memory.pybackend_factoryr   $   s    2,|455    c               #      "   \         P                  x  \         P                  ! 4        F  p \        V 4      x  K  	  R # 5iN)r   default_memory_poolsupported_memory_backendsr   r	   s    r   supported_factoriesr   (   s/     

 
  446l++ 7s   >A c              #     "   \         P                  ! RV,          .\         P                  ! 4       V R7      pVP                  4       ^,          pRp\	        V4      V8X  g   Q h Rx  RpR#   Rpi ; i5i)z6
Temporarily allocate *nbytes* from the given *pool*.
   x)typememory_poolN)r   arraybinarybufferslen)poolnbytesarrbufs   &&  r   allocate_bytesr   .   s`     
 ((D6M?$
GC ++-
C
Cs8vds   A A2#A+ 'A2+A//A2c                *   V P                  4       pV P                  4       pV P                  4       p\        V R4      ;_uu_ 4        V P                  4       VR,           8X  g   Q hV P                  4       pV P                  4       V8  g   Q hV P                  4       pWS8  g   Q hWS^,           8  g   Q h RRR4       V P                  4       V8X  g   Q hV P                  4       X8X  g   Q hV P                  4       X8X  g   Q hR#   + '       g   i     LW; i)z#
Check allocation stats on *pool*.
   N)bytes_allocated
max_memorynum_allocationsr   )r   allocated_beforemax_mem_beforenum_allocations_beforenew_max_memorynum_allocations_afters   &     r   check_allocated_bytesr*   ?   s     ++-__&N!113	c	"	"##%)9C)????* N222 $ 4 4 6$===$'AAAA 
# !%5555??...!%:::: 
#	"s   A-DD	c                      \         P                  ! 4       p \        V R 4      ;_uu_ 4        \        V 4       V P	                  4       \         P
                  ! 4       8X  g   Q h RRR4       R#   + '       g   i     R# ; i)i   N)r   r   r   r*   r"   total_allocated_bytesr   s    r   test_default_allocated_bytesr.   R   sT    !!#D	d	#	#d###%)A)A)CCCC 
$	#	#	#s   6A++A<	c                      \         P                  ! \         P                  ! 4       4      p \        V 4       \        P
                  ! V 4      pV! 4       f   Q h? V! 4       e   Q hR # r   )r   proxy_memory_poolr   r*   weakrefref)r   wrs     r   test_proxy_memory_poolr4   Y   sN     6 6 89D$	T	B44<<r   c                 "   \         P                  ! \         P                  ! 4       4      p\        V4       V P	                  4       w  r#VR 8X  g   Q hVP                  R4      ^ 8  g   Q hVP                  R4      VP                  R4      8X  g   Q hR# ) z	Allocate:zFree:N)r   logging_memory_poolr   r*   
readouterrcount)capfdr   outerrs   &   r   test_logging_memory_poolr=   b   sv    !!""8"8":;D$!HC"9999[!A%%%99[!SYYw%7777r   c                     \         P                  ! 4       p \         P                  ! V 4      p\         P                  ! V4        VP	                  4       p\        R R4      ;_uu_ 4        VP	                  4       VR,           8X  g   Q h R R R 4       VP	                  4       V8X  g   Q h \         P                  ! V 4       R #   + '       g   i     L@; i  \         P                  ! T 4       i ; i)Nr!   )r   r   r0   set_memory_poolr"   r   )old_poolr   r%   s      r   test_set_memory_poolrA   k   s    %%'H)Dt%//1D#&&'')-=-CCCC '##%)9999
8$	 '& 	8$s$   $C 'B?C ?C	
C C*c                  ^    \         P                  ! 4       p V P                  \        9   g   Q hR # r   )r   r   r
   possible_backendsr-   s    r   test_default_backend_namerD   x   s%    !!#D 1111r   c                  P    \         P                  ! 4       p V P                  4        R # r   )r   r   release_unusedr-   s    r   test_release_unusedrG   }   s    !!#Dr   expect_warningFc                p   R V: R2p\        \        P                  4      pWR&   \        P                  ! \
        P                  RV.VR\        P                  R7      pVP                  ^ 8w  d6   \        VP                  \
        P                  R7       VP                  4        VP                  P                  4       pV'       d_   \        V4      R9   g   Q h\        V4      ^8X  d   RV  R2V^ ,          9   g   Q hR
# R	V^ ,          9   g   Q hRV  R2V^,          9   g   Q hR
# \        V4      ^ 8X  g   Q hR
# )zpif 1:
        import pyarrow as pa

        pool = pa.default_memory_pool()
        assert pool.backend_name in z, pool.backend_name
        ARROW_DEFAULT_MEMORY_POOL-cTenvuniversal_newlinesstderrfilezUnsupported backend ''zInitGoogleLogging()N)      )dictosenviron
subprocessrunsys
executablePIPE
returncodeprintrO   check_returncode
splitlinesr   )nameexpectedrH   coderM   reserrliness   &&$    r   check_env_varrf      s   % &.L 1		D rzz
C'+#$
..#..$53,0JC
~~cjjszz*zz$$&H8}&&&x=A*4&2hqkAAA )HQK777*4&2hqkAAA8}!!!r   c                  \    \          F  p \        W .4       K  	  \        R \        RR7       R# )nonexistentT)rH   N)mandatory_backendsrf   rC   r	   s    r   test_env_varrj      s#    *lN3 +-!24Hr   c                  d    R R/R lp \          F  pV ! \        V4      VV\        9  R7       K   	  R# )can_failFc                    V'       d
    V ! 4       pMV ! 4       pVP                  V8X  g   Q hR #   \          d     R # i ; ir   )NotImplementedErrorr
   )factoryra   rl   r   s   &&$ r   check)test_memory_pool_factories.<locals>.check   sB    y 9D  D(((	 ' s   . ==)rl   N)rC   r   ri   )rp   r
   s     r   test_memory_pool_factoriesrr      s4    ) ) *ol+\#+==	? *r   c                      \         P                  ! 4       p \        V 4      \        \        4      8  g   Q h\        V 4      \        \        4      8:  g   Q hR # r   )r   r   setri   rC   )backendss    r   test_supported_memory_backendsrv      s@    ++-Hx=C 23333x=C 12222r   c                   RV  R2p\        \        P                  4      pWR&   \        P                  ! \
        P                  RV.VR\        P                  R7      p\        VP                  \
        P                  R7       V# )z
Run a piece of code making an invalid memory write with the
ARROW_DEBUG_MEMORY_POOL environment variable set to a specific value.
a  if 1:
        import ctypes
        import pyarrow as pa
        # ARROW-16873: some Python installs enable faulthandler by default,
        # which could dump a spurious stack trace if the following crashes
        import faulthandler
        faulthandler.disable()

        pool = pa.z()
        buf = pa.allocate_buffer(64, memory_pool=pool)

        # Write memory out of bounds
        ptr = ctypes.cast(buf.address, ctypes.POINTER(ctypes.c_ubyte))
        ptr[64] = 0

        del buf
        ARROW_DEBUG_MEMORY_POOLrK   TrL   rP   )
rU   rV   rW   rX   rY   rZ   r[   r\   r^   rO   )pool_factory	env_valuerc   rM   rd   s   &&   r   run_debug_memory_poolr{      sq    
  . !	D" rzz
C%.!"
..#..$53,0JC	#**3::&Jr   ry   c                     \        V P                  R 4      p\        P                  R8X  d$   VP                  \
        P                  ) 8X  g   Q hMVP                  ^ 8w  g   Q hRVP                  9   g   Q hR# )abortposixWrong size on deallocationN)r{   __name__rV   ra   r]   signalSIGABRTrO   ry   rd   s   & r   test_debug_memory_pool_abortr      s\    
 5 5w
?C	ww'~~&..000~~"""'3::555r   c                     \        V P                  R 4      p\        P                  R8X  d$   VP                  \
        P                  ) 8X  g   Q hMVP                  ^ 8w  g   Q hRVP                  9   g   Q hR# )trapr~   r   N)r{   r   rV   ra   r]   r   SIGTRAPrO   r   s   & r   test_debug_memory_pool_trapr      s\    
 5 5v
>C	ww'~~&..000~~"""'3::555r   c                 x    \        V P                  R 4      pVP                  4        RVP                  9   g   Q hR# )warnr   N)r{   r   r_   rO   r   s   & r   test_debug_memory_pool_warnr      s2    
 5 5v
>C'3::555r   c                 V   \         P                  R8  d   \        P                  ! R4       \	        V P
                  V4      p\        P                  R8X  d   VP                  ^ 8:  g   Q hMVP                  4        VR8X  d   VP                  R8X  g   Q hR# W#P                  9   g   Q hR# )rT   z!Test may fail on 32-bit platformsr~   r6   Nl        )rZ   maxsizepytestskipr{   r   rV   ra   r]   r_   rO   )ry   rz   msgrd   s   &&& r    check_debug_memory_pool_disabledr      s    
{{U78
 5 5y
AC 
ww'~~"""
byzzRjj   r   c                      \        V R R4       R# )noner6   Nr   ry   s   &r   test_debug_memory_pool_noner     s    $\62>r   c                      \        V R R 4       R# )r6   Nr   r   s   &r   test_debug_memory_pool_emptyr   	  s    $\2r:r   c                 .    R pRV R2p\        WV4       R# )some_arbitrary_valuez,Invalid value for ARROW_DEBUG_MEMORY_POOL: 'z4'. Valid values are 'abort', 'trap', 'warn', 'none'.Nr   )ry   rz   r   s   &  r   test_debug_memory_pool_unknownr     s*    &I
6yk B< 	<  %\cBr   c                 `   R V P                    R2p\        P                  ! \        P                  RV.RR\        P
                  \        P
                  R7      p\        P                  R8X  dA   \        P                  ! 4       '       g$   VP                  P                  4       R8w  g   Q hR# R# R# )z6if 1:
        import pyarrow as pa

        pool = pa.z]()
        buf = pa.allocate_buffer(64, memory_pool=pool)
        pool.print_stats()
        rK   T)rp   rN   stdoutrO   linuxr6   N)r   rX   rY   rZ   r[   r\   platformr   running_on_musllinuxrO   strip)ry   rc   rd   s   &  r   test_print_statsr     s      (() *	D ..#..$5T,0 *1C ||wt'@'@'B'Bzz!R''' (Cr   )r   jemallocmimalloc))
contextlibrV   r   rX   rZ   r1   pyarrowr   pyarrow.testsr   r   mark	processes
pytestmarkrC   ri   r   r   contextmanagerr   r*   r.   r4   r=   rA   rD   rG   rf   rj   rr   rv   r{   parametrizer   r   r   r   r   r   r   r    r   r   <module>r      s  $  	   
    [[""
6 Z 6,   ;&D8
%2

"E "8I? 3< )<)>?6 @6 )<)>?6 @6 )<)>?6 @6!" )<)>?? @? )<)>?; @; )<)>?C @C )<)>?( @(r   