
    3j	                         S r SSKJr  SSKrSSKJr  SrS r\" 5       r\	S:X  a)  Sr
\" \" \
5      \" \
5      \" \
5      \" \
5      -
  45        gg)	a  Run-time calculation of offset into Python string structure

Does a scan to find the digits of pi in a string structure
in order to produce an offset that can be used to produce 
data-pointers from Python strings.

Porting note:
    
    Currently this uses id( str a ) to get the base address
    of the Python string.  Python implementations where id( a )
    is *not* the memory address of the string will not work!
    )print_functionN)bytes31415926535897931c                  \  ^	 Sm	[         n [        U 5      n[        R                  " [        R                  5      n[        S5       HI  n[        R                  " X-   U5      nSn[        U 5       H  u  pgXF   U:w  d  M  Sn  O   U(       d  MG  Um	  O   T	b  U	4S jnT	Ul        U$ [        S5      e)a  Calculates the data-pointer offset for strings

This does a sequential scan for 100 bytes from the id
of a string to find special data-value stored in the
string (the digits of PI).  It produces a dataPointer
function which adds that offset to the id of the 
passed strings.
Nd   TFc                 z   > [        U [        5      (       d  [        S[        U 5      < 35      e[	        U 5      T-   $ )zReturn the data-pointer from the array using calculated offset

data -- a Python string

Returns the raw data-pointer to the internal buffer of the passed string
z3This function can only handle Python strings!  Got )
isinstancer   	TypeErrortypeid)datafinalOffsets    P/home/wildlama/miniconda3/lib/python3.13/site-packages/OpenGL/arrays/_strings.pydataPointer$calculateOffset.<locals>.dataPointer+   s<     tU,,T
 
 d8k))    z3Unable to determine dataPointer offset for strings!)
	PI_DIGITSr   ctypesPOINTERc_charrangecast	enumerateoffsetRuntimeError)
ainitial
targetTyper   vector
allMatchedindexdigitr   r   s
            @r   calculateOffsetr#      s     KAeG0J,gnZ9
$a>KE}%"
 * : K  	* )
A r   __main__this)__doc__
__future__r   r   OpenGL._bytesr   r   r#   r   __name__r   printr    r   r   <module>r,      sa    &  	,\ z	A	2a5+q"KNRU$:
;< r   