#NEWLINE# def test_verify_struct( ) : #NEWLINE# #INDENT# ffi = FFI ( ) #NEWLINE# ffi . cdef ( 'struct foo_s { int b; short a; ...; };\n                struct bar_s { struct foo_s *f; };' ) #NEWLINE# lib = verify ( ffi , 'test_verify_struct' , 'struct foo_s { short a; int b; };\n                    struct bar_s { struct foo_s *f; };' ) #NEWLINE# ffi . typeof ( 'struct bar_s *' ) #NEWLINE# p = ffi . new ( 'struct foo_s *' , { #NEWLINE# #INDENT# 'a' : ( - 32768 ) , #NEWLINE# 'b' : ( - 2147483648 ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert ( p . a == ( - 32768 ) ) #NEWLINE# assert ( p . b == ( - 2147483648 ) ) #NEWLINE# py . test . raises ( OverflowError , 'p.a -= 1' ) #NEWLINE# py . test . raises ( OverflowError , 'p.b -= 1' ) #NEWLINE# q = ffi . new ( 'struct bar_s *' , { #NEWLINE# #INDENT# 'f' : p , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert ( q . f == p ) #NEWLINE# assert ( ffi . offsetof ( 'struct foo_s' , 'a' ) == 0 ) #NEWLINE# assert ( ffi . offsetof ( 'struct foo_s' , 'b' ) == 4 ) #NEWLINE# assert ( ffi . offsetof ( ( u + 'struct foo_s' ) , ( u + 'b' ) ) == 4 ) #NEWLINE# py . test . raises ( TypeError , ffi . addressof , p ) #NEWLINE# assert ( ffi . addressof ( p [ 0 ] ) == p ) #NEWLINE# assert ( ffi . typeof ( ffi . addressof ( p [ 0 ] ) ) is ffi . typeof ( 'struct foo_s *' ) ) #NEWLINE# assert ( ffi . typeof ( ffi . addressof ( p , 'b' ) ) is ffi . typeof ( 'int *' ) ) #NEWLINE# assert ( ffi . addressof ( p , 'b' ) [ 0 ] == p . b )