Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(116280)

Side by Side Diff: Lib/ctypes/test/test_prototypes.py

Issue 23670: Modifications to support iOS as a development platform
Patch Set: Created 3 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/ctypes/test/test_pointers.py ('k') | Lib/ctypes/test/test_refcounts.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import os
1 from ctypes import * 2 from ctypes import *
2 from ctypes.test import need_symbol 3 from ctypes.test import need_symbol
3 import unittest 4 import unittest
4 5
5 # IMPORTANT INFO: 6 # IMPORTANT INFO:
6 # 7 #
7 # Consider this call: 8 # Consider this call:
8 # func.restype = c_char_p 9 # func.restype = c_char_p
9 # func(c_char_p("123")) 10 # func(c_char_p("123"))
10 # It returns 11 # It returns
11 # "123" 12 # "123"
12 # 13 #
13 # WHY IS THIS SO? 14 # WHY IS THIS SO?
14 # 15 #
15 # argument tuple (c_char_p("123"), ) is destroyed after the function 16 # argument tuple (c_char_p("123"), ) is destroyed after the function
16 # func is called, but NOT before the result is actually built. 17 # func is called, but NOT before the result is actually built.
17 # 18 #
18 # If the arglist would be destroyed BEFORE the result has been built, 19 # If the arglist would be destroyed BEFORE the result has been built,
19 # the c_char_p("123") object would already have a zero refcount, 20 # the c_char_p("123") object would already have a zero refcount,
20 # and the pointer passed to (and returned by) the function would 21 # and the pointer passed to (and returned by) the function would
21 # probably point to deallocated space. 22 # probably point to deallocated space.
22 # 23 #
23 # In this case, there would have to be an additional reference to the argument.. . 24 # In this case, there would have to be an additional reference to the argument.. .
24 25
25 import _ctypes_test 26 import _ctypes_test
26 testdll = CDLL(_ctypes_test.__file__) 27 testdll = CDLL(getattr(_ctypes_test, '__file__', os.environ['TEST_EXECUTABLE']))
27 28
28 # Return machine address `a` as a (possibly long) non-negative integer. 29 # Return machine address `a` as a (possibly long) non-negative integer.
29 # Starting with Python 2.5, id(anything) is always non-negative, and 30 # Starting with Python 2.5, id(anything) is always non-negative, and
30 # the ctypes addressof() inherits that via PyLong_FromVoidPtr(). 31 # the ctypes addressof() inherits that via PyLong_FromVoidPtr().
31 def positive_address(a): 32 def positive_address(a):
32 if a >= 0: 33 if a >= 0:
33 return a 34 return a
34 # View the bits in `a` as unsigned instead. 35 # View the bits in `a` as unsigned instead.
35 import struct 36 import struct
36 num_bits = struct.calcsize("P") * 8 # num bits in native machine address 37 num_bits = struct.calcsize("P") * 8 # num bits in native machine address
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 214
214 # This did crash before: 215 # This did crash before:
215 216
216 def func(): pass 217 def func(): pass
217 CFUNCTYPE(None, c_int * 3)(func) 218 CFUNCTYPE(None, c_int * 3)(func)
218 219
219 ################################################################ 220 ################################################################
220 221
221 if __name__ == '__main__': 222 if __name__ == '__main__':
222 unittest.main() 223 unittest.main()
OLDNEW
« no previous file with comments | « Lib/ctypes/test/test_pointers.py ('k') | Lib/ctypes/test/test_refcounts.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+