
    cwi                        S r SSKrSSKrSSKJr  SSKJr   Sr\" \S5      (       a:  \R                  " 5       r\R                  " \R                  \R                  -  5         SSKJr  SSKJr  \b  \R                  " \5        SS	.S
 jrSS	.S jrSS	.S jrS\4S jrSS\4S jjrS\4S jrS rS r " S S5      r " S S5      rS rg! \ a    SSKJr  SSKJr   Nsf = f! \b  \R                  " \5        f f = f)z6
Internal functions and classes of the clingo module.
    N)_exitprint_exceptionsetdlopenflags)ffi)lib   )handlerc                   [         R                  " S5      n[        U " / UQUP76 U5        [         R                  " SUS   5      n[        U" / UQUPUS   P76 U5        [         R                  " U5      R	                  5       $ )Nzsize_t*zchar[]r   )_ffinew_handle_errorstringdecode)f_sizef_strr
   argsp_sizep_strs         J/home/james-whalen/.local/lib/python3.13/site-packages/clingo/_internal.py_strr   !   ss    XXi F&'$''1HHXvay)E%00u0fQi0':;;u$$&&    c                    [        U [        5      (       a  [        R                  " U  S35      nOU n[	        U" / UQUP76 U5        US   $ )ze
Helper to simplify calling C functions where the last parameter is a
reference to the return value.
*r   )
isinstancestrr   r   r   )c_typec_funr
   r   p_rets        r   _c_callr    )   sJ    
 &#F81&%%%u%w/8Or   c                    [         R                  " U  S35      n[         R                  " U S35      n[        U" / UQUPUP76 U5        US   US   4$ )zk
Helper to simplify calling C functions where the last two parameters are a
reference to the return value.
r   r   )r   r   r   )c_type1c_type2r   r
   r   p_ret1p_ret2s          r   _c_call2r&   6   s[    
 XX	m$FXX	m$F%..v.v.8!9fQir   returnc                 J    [         R                  " U 5      R                  5       $ N)r   r   r   )c_strs    r   _to_strr+   A   s    ;;u$$&&r   retc                    U (       d  [         R                  " 5       nU[         R                  :X  aN  UbK  UR                  b>  UR                  S   " UR                  S   5      R	                  UR                  S   5      e[
        R                  " [         R                  " 5       5      R                  5       nU[         R                  :X  a  [        U5      e[        U5      eg )Nr   r	      )_libclingo_error_codeclingo_error_unknownerrorwith_tracebackr   r   clingo_error_messager   clingo_error_bad_allocMemoryErrorRuntimeError)r,   r
   codemsgs       r   r   r   E   s    %%'D---#)--"7==#34CCGMMRSDTUUkk$3356==?4...c""3 r   paramc                 $   ^  S[         4U 4S jjnU$ )Nr'   c                 X  > Ubs  [         R                  " UR                  R                  T   5      nXU4Ul        [
        R                  " [
        R                  [        U5      R                  5       5        g[
        R                  " [
        R                  SR                  5       5        g)Nzerror in callbackF)r   from_handletb_framef_localsr2   r/   clingo_set_errorr1   r   encodeclingo_error_runtime)	exception	exc_value	tracebackr
   r:   s       r   r
   "_cb_error_handler.<locals>.handlerU   s     &&y'9'9'B'B5'IJG&9=GM!!$";";S^=R=R=TU
  !!))+>+E+E+G r   )bool)r:   r
   s   ` r   _cb_error_handlerrH   T   s    	D 	 Nr   c                 p    [        XU5        [        R                  R                  S5        [	        S5        g )Nz!PANIC: exception in nothrow scoper	   )r   sysstderrwriter   rC   rD   rE   s      r   _cb_error_panicrN   c   s&    I)4JJ89	!Hr   c                     [        XU5        g)NFr   rM   s      r   _cb_error_printrP   i   s    I)4r   c                   X    \ rS rSrSrS rS r\S 5       r\R                  S 5       rSr
g)	_Errorn   z/
Class to store an error in a unique location.
c                     S U l         g r)   _errorselfs    r   __init___Error.__init__s   s	    r   c                     SU l         g)z
Clears the last error set.
NrU   rW   s    r   clear_Error.clearv   s     r   c                     U R                   $ )z
Return the last error set.
rU   rW   s    r   r2   _Error.error|   s     {{r   c                     Xl         g)zN
Set an error if no error has been set before.

This function is thread-safe.
NrU   rX   values     r   r2   r_      s	     r   rU   N)__name__
__module____qualname____firstlineno____doc__rY   r\   propertyr2   setter__static_attributes__ r   r   rR   rR   n   s=       \\ r   rR   c                   R    \ rS rSrSrS r\S 5       r\R                  S 5       rSr	g)_CBData   z
The class stores the data object that should be passed to a callback as
well as provides the means to set an error while a callback is running.
c                     Xl         X l        g r)   )datarV   )rX   rp   r2   s      r   rY   _CBData.__init__   s    	r   c                 .    U R                   R                  $ )z4
Get the last error in the underlying error object.
rV   r2   rW   s    r   r2   _CBData.error   s    
 {{   r   c                 $    XR                   l        g)z+
Set error in the underlying error object.
Nrs   ra   s     r   r2   rt      s    
 "r   )rV   rp   N)
rc   rd   re   rf   rg   rY   rh   r2   ri   rj   rk   r   r   rm   rm      s8    
 ! ! \\" "r   rm   c                     [        X5      =(       a9    [        X5      (       + =(       d"    [        X5      [        UR                  US 5      L$ r)   )hasattrgetattr	__class__)baseobjfunctions      r   _overwrittenr}      s?    3! D## 	Q4"'#--4*PPr   r)   )rg   osrJ   r   rE   r   _FLAGSrw   getdlopenflagsr   	RTLD_LAZYRTLD_GLOBAL_clingor   r   r   r/   ImportErrorr   r    r&   r   r+   rG   r   rH   rN   rP   rR   rm   r}   rk   r   r   <module>r      s   
 
  %#F s$%%##%2<<"..89
)	
 	( 6" (, ' +/ 
 6:  'c ' t  S 
 B" "2c  )	
 	)	) 6" s*   A
C& #C C# C& "C##C& &C>