Debian Codegraph @

pypy/module/_cppyy/capi/loadable_capi.py

raw symbols SCIP
1 import os, sys
2
3 from rpython.rtyper.lltypesystem import rffi, lltype
4 from rpython.rlib.rarithmetic import intmask
5 from rpython.rlib import jit, jit_libffi, libffi, rdynload, objectmodel
6 from rpython.rlib.rarithmetic import r_singlefloat
7 from rpython.tool import leakfinder
8
9 from pypy.interpreter.error import OperationError, oefmt
10 from pypy.interpreter.argument import Arguments
11 from pypy.interpreter.gateway import interp2app, interpindirect2app
12 from pypy.interpreter.typedef import TypeDef
13 from pypy.objspace.std.iterobject import W_AbstractSeqIterObject
14
15 from pypy.module._rawffi.interp_array import W_ArrayInstance
16 from pypy.module._cffi_backend import ctypefunc, cdataobj, misc
17 from pypy.module._cffi_backend import newtype
18 from pypy.module._cppyy import ffitypes
19 from pypy.module.sys.version import PYPY_VERSION
20
21 from pypy.module._cppyy.capi.capi_types import C_SCOPE, C_TYPE, C_OBJECT,\
22 C_METHOD, C_INDEX, C_INDEX_ARRAY, C_FUNC_PTR
23
24 backend_ext = '.so'
25 if sys.platform == 'darwin':
26 backend_ext = '.dylib'
27 if sys.platform == 'win32':
28 backend_ext = '.dll'
29 dldflags = 0
30 else:
31 dldflags = rdynload.RTLD_LOCAL | rdynload.RTLD_LAZY
32
33 backend_library = 'libcppyy_backend'
34
35 # this is not technically correct, but will do for now
36 std_string_name = 'std::string'
37
38 class _Arg: # poor man's union
39 _immutable_ = True
40 def __init__(self, tc, h = rffi.cast(C_SCOPE, 0),
41 m = rffi.cast(C_METHOD, 0),
42 o = rffi.cast(C_OBJECT, 0),
43 u = rffi.cast(C_INDEX, -1),
44 i = rffi.cast(rffi.INT, -1),
45 d = rffi.cast(rffi.DOUBLE, -1.),
46 s = '',
47 p = rffi.cast(rffi.VOIDP, 0)):
48 self.tc = tc
49 self._scope = h
50 self._method = m
51 self._object = o
52 self._index = u
53 self._int = i
54 self._double = d
55 self._string = s
56 self._voidp = p
57
58 # use separate classes for the benefit of the rtyper
59 class _ArgH(_Arg):
60 _immutable_ = True
61 def __init__(self, val):
62 _Arg.__init__(self, 'h', h = val)
63
64 def _ArgC(val):
65 return _ArgH(val.handle)
66
67 class _ArgM(_Arg):
68 _immutable_ = True
69 def __init__(self, val):
70 _Arg.__init__(self, 'm', m = val)
71
72 class _ArgO(_Arg):
73 _immutable_ = True
74 def __init__(self, val):
75 _Arg.__init__(self, 'o', o = val)
76
77 class _ArgU(_Arg):
78 _immutable_ = True
79 def __init__(self, val):
80 _Arg.__init__(self, 'u', u = val)
81
82 class _ArgI(_Arg):
83 _immutable_ = True
84 def __init__(self, val):
85 _Arg.__init__(self, 'i', i = val)
86
87 class _ArgD(_Arg):
88 _immutable_ = True
89 def __init__(self, val):
90 _Arg.__init__(self, 'd', d = val)
91
92 class _ArgS(_Arg):
93 _immutable_ = True
94 def __init__(self, val):
95 _Arg.__init__(self, 's', s = val)
96
97 class _ArgP(_Arg):
98 _immutable_ = True
99 def __init__(self, val):
100 _Arg.__init__(self, 'p', p = val)
101
102 # For the loadable CAPI, the calls start and end in RPython. Therefore, the standard
103 # _call of W_CTypeFunc, which expects wrapped objects, does not quite work: some
104 # vars (e.g. void* equivalent) can not be wrapped, and others (such as rfloat) risk
105 # rounding problems. This W_RCTypeFun then, takes args, instead of args_w. Note that
106 # rcall() is a new method, so as to not interfere with the base class call and _call
107 # when rtyping. It is also called directly (see call_capi below).
108 class W_RCTypeFunc(ctypefunc.W_CTypeFunc):
109 @jit.unroll_safe
110 def rcall(self, funcaddr, args):
111 assert self.cif_descr
112 self = jit.promote(self)
113 # no checking of len(args) needed, as calls in this context are not dynamic
114
115 # The following code is functionally similar to W_CTypeFunc._call, but its
116 # implementation is tailored to the restricted use (include memory handling)
117 # of the CAPI calls.
118 space = self.space
119 cif_descr = self.cif_descr
120 size = cif_descr.exchange_size
121 raw_string1 = rffi.cast(rffi.CCHARP, 0)
122 raw_string2 = rffi.cast(rffi.CCHARP, 0) # have max two in any CAPI
123 buffer = lltype.malloc(rffi.CCHARP.TO, size, flavor='raw')
124 try:
125 for i in range(len(args)):
126 data = rffi.ptradd(buffer, cif_descr.exchange_args[i])
127 obj = args[i]
128 argtype = self.fargs[i]
129 # the following is clumsy, but the data types used as arguments are
130 # very limited, so it'll do for now
131 if obj.tc == 'h':
132 misc.write_raw_unsigned_data(data, rffi.cast(rffi.SIZE_T, obj._scope), argtype.size)
133 elif obj.tc == 'm':
134 misc.write_raw_signed_data(data, rffi.cast(rffi.INTPTR_T, obj._method), argtype.size)
135 elif obj.tc == 'o':
136 # additional cast of void* to intptr_t required for 32b (or intmask fails)
137 misc.write_raw_signed_data(data, rffi.cast(rffi.INTPTR_T, rffi.cast(rffi.VOIDP, obj._object)), argtype.size)
138 elif obj.tc == 'u':
139 misc.write_raw_unsigned_data(data, rffi.cast(rffi.SIZE_T, obj._index), argtype.size)
140 elif obj.tc == 'i':
141 misc.write_raw_signed_data(data, rffi.cast(rffi.INT, obj._int), argtype.size)
142 elif obj.tc == 'd':
143 misc.write_raw_float_data(data, rffi.cast(rffi.DOUBLE, obj._double), argtype.size)
144 elif obj.tc == 'p':
145 assert obj._voidp != rffi.cast(rffi.VOIDP, 0)
146 data = rffi.cast(rffi.VOIDPP, data)
147 data[0] = obj._voidp
148 elif obj.tc == 's':
149 n = len(obj._string)
150 data = rffi.cast(rffi.CCHARPP, data)
151 if raw_string1 == rffi.cast(rffi.CCHARP, 0):
152 # XXX could use rffi.get_nonmovingbuffer_final_null()
153 raw_string1 = rffi.str2charp(obj._string)
154 data[0] = raw_string1
155 else:
156 assert raw_string2 == rffi.cast(rffi.CCHARP, 0)
157 raw_string2 = rffi.str2charp(obj._string)
158 data[0] = raw_string2
159 else: # only other use is voidp
160 assert obj.tc == 'p'
161 assert obj._voidp != rffi.cast(rffi.VOIDP, 0)
162 data = rffi.cast(rffi.VOIDPP, data)
163 data[0] = obj._voidp
164
165 jit_libffi.jit_ffi_call(cif_descr,
166 rffi.cast(rffi.VOIDP, funcaddr),
167 buffer)
168
169 resultdata = rffi.ptradd(buffer, cif_descr.exchange_result)
170 # this wrapping is unnecessary, but the assumption is that given the
171 # immediate unwrapping, the round-trip is removed
172 w_res = self.ctitem.copy_and_convert_to_object(resultdata)
173 finally:
174 if raw_string1 != rffi.cast(rffi.CCHARP, 0):
175 rffi.free_charp(raw_string1)
176 if raw_string2 != rffi.cast(rffi.CCHARP, 0):
177 rffi.free_charp(raw_string2)
178 lltype.free(buffer, flavor='raw')
179 return w_res
180
181 class State(object):
182 def __init__(self, space):
183 self.backend = None
184 self.capi_calls = {}
185
186 nt = newtype # module from _cffi_backend
187 state = space.fromcache(ffitypes.State) # factored out common types
188
189 # TODO: the following need to match up with the globally defined C_XYZ low-level
190 # types (see capi/__init__.py), but by using strings here, that isn't guaranteed
191 c_voidp = state.c_voidp
192 c_size_t = state.c_size_t
193 c_ptrdiff_t = state.c_ptrdiff_t
194 c_intptr_t = state.c_intptr_t
195
196 c_scope = c_size_t
197 c_type = c_scope
198 c_enum = c_voidp
199 c_object = c_voidp
200 c_method = c_intptr_t
201 c_index = c_size_t
202 c_index_array = c_voidp
203
204 c_void = state.c_void
205 c_char = state.c_char
206 c_uchar = state.c_uchar
207 c_short = state.c_short
208 c_int = state.c_int
209 c_long = state.c_long
210 c_llong = state.c_llong
211 c_ullong = state.c_ullong
212 c_float = state.c_float
213 c_double = state.c_double
214 c_ldouble = state.c_ldouble
215
216 c_ccharp = state.c_ccharp
217
218 self.capi_call_ifaces = {
219 # direct interpreter access
220 'compile' : ([c_ccharp], c_int),
221 'cppyy_to_string' : ([c_type, c_object], c_ccharp),
222
223 # name to opaque C++ scope representation
224 'resolve_name' : ([c_ccharp], c_ccharp),
225 'resolve_enum' : ([c_ccharp], c_ccharp),
226 'get_scope' : ([c_ccharp], c_scope),
227 'actual_class' : ([c_type, c_object], c_type),
228 'size_of_klass' : ([c_type], c_size_t),
229 'size_of_type' : ([c_ccharp], c_size_t),
230
231 'is_builtin' : ([c_ccharp], c_int),
232 'is_complete' : ([c_ccharp], c_int),
233
234 # memory management
235 'allocate' : ([c_type], c_object),
236 'deallocate' : ([c_type, c_object], c_void),
237 'construct' : ([c_type], c_object),
238 'destruct' : ([c_type, c_object], c_void),
239
240 # method/function dispatching
241 'call_v' : ([c_method, c_object, c_int, c_voidp], c_void),
242 'call_b' : ([c_method, c_object, c_int, c_voidp], c_uchar),
243 'call_c' : ([c_method, c_object, c_int, c_voidp], c_char),
244
245 'call_h' : ([c_method, c_object, c_int, c_voidp], c_short),
246 'call_i' : ([c_method, c_object, c_int, c_voidp], c_int),
247 'call_l' : ([c_method, c_object, c_int, c_voidp], c_long),
248 'call_ll' : ([c_method, c_object, c_int, c_voidp], c_llong),
249 'call_f' : ([c_method, c_object, c_int, c_voidp], c_float),
250 'call_d' : ([c_method, c_object, c_int, c_voidp], c_double),
251 'call_ld' : ([c_method, c_object, c_int, c_voidp], c_ldouble),
252 'call_nld' : ([c_method, c_object, c_int, c_voidp], c_double),
253
254 'call_r' : ([c_method, c_object, c_int, c_voidp], c_voidp),
255 # call_s actually takes an size_t* as last parameter, but this will do
256 'call_s' : ([c_method, c_object, c_int, c_voidp, c_voidp], c_ccharp),
257 'constructor' : ([c_method, c_object, c_int, c_voidp], c_object),
258 'destructor' : ([c_type, c_object], c_void),
259 'call_o' : ([c_method, c_object, c_int, c_voidp, c_type], c_object),
260
261 'function_address' : ([c_method], c_voidp), # TODO: verify
262
263 # handling of function argument buffer
264 'allocate_function_args' : ([c_int], c_voidp),
265 'deallocate_function_args' : ([c_voidp], c_void),
266 'function_arg_sizeof' : ([], c_size_t),
267 'function_arg_typeoffset' : ([], c_size_t),
268
269 # scope reflection information
270 'is_namespace' : ([c_scope], c_int),
271 'is_template' : ([c_ccharp], c_int),
272 'is_abstract' : ([c_type], c_int),
273 'is_enum' : ([c_ccharp], c_int),
274 'is_aggregate' : ([c_ccharp], c_int),
275 'is_default_constructable' : ([c_ccharp], c_int),
276
277 'get_all_cpp_names' : ([c_scope, c_voidp], c_voidp), # const char**
278
279 # namespace reflection information
280 'get_using_namespaces' : ([c_scope], c_index),
281
282 # type/class reflection information
283 'final_name' : ([c_type], c_ccharp),
284 'scoped_final_name' : ([c_type], c_ccharp),
285 'has_virtual_destructor' : ([c_type], c_int),
286 'has_complex_hierarchy' : ([c_type], c_int),
287 'num_bases' : ([c_type], c_int),
288 'base_name' : ([c_type, c_int], c_ccharp),
289 'is_subtype' : ([c_type, c_type], c_int),
290 'is_smartptr' : ([c_type], c_int),
291 'smartptr_info' : ([c_ccharp, c_voidp, c_voidp], c_int),
292 'add_smartptr_type' : ([c_ccharp], c_void),
293
294 'add_type_reducer' : ([c_ccharp, c_ccharp], c_void),
295
296 'base_offset' : ([c_type, c_type, c_object, c_int], c_ptrdiff_t),
297
298 # method/function reflection information
299 'num_methods' : ([c_scope], c_int),
300 'method_indices_from_name' : ([c_scope, c_ccharp], c_index_array),
301
302 'get_method' : ([c_scope, c_index], c_method),
303
304 'method_name' : ([c_method], c_ccharp),
305 'method_full_name' : ([c_method], c_ccharp),
306 'method_mangled_name' : ([c_method], c_ccharp),
307 'method_result_type' : ([c_method], c_ccharp),
308 'method_num_args' : ([c_method], c_int),
309 'method_req_args' : ([c_method], c_int),
310 'method_arg_name' : ([c_method, c_int], c_ccharp),
311 'method_arg_type' : ([c_method, c_int], c_ccharp),
312 'method_arg_default' : ([c_method, c_int], c_ccharp),
313 'method_signature' : ([c_method, c_int], c_ccharp),
314 'method_signature_max' : ([c_method, c_int, c_int], c_ccharp),
315 'method_prototype' : ([c_scope, c_method, c_int], c_ccharp),
316 'is_const_method' : ([c_method], c_int),
317
318 'get_num_templated_methods': ([c_scope], c_int),
319 'get_templated_method_name': ([c_scope, c_index], c_ccharp),
320 'is_templated_constructor' : ([c_scope, c_index], c_int),
321 'exists_method_template' : ([c_scope, c_ccharp], c_int),
322 'method_is_template' : ([c_scope, c_index], c_int),
323 'get_method_template' : ([c_scope, c_ccharp, c_ccharp], c_method),
324
325 'get_global_operator' : ([c_scope, c_scope, c_scope, c_ccharp], c_index),
326
327 # method properties
328 'is_public_method' : ([c_method], c_int),
329 'is_protected_method' : ([c_method], c_int),
330 'is_constructor' : ([c_method], c_int),
331 'is_destructor' : ([c_method], c_int),
332 'is_staticmethod' : ([c_method], c_int),
333
334 # data member reflection information
335 'num_datamembers' : ([c_scope], c_int),
336 'datamember_name' : ([c_scope, c_int], c_ccharp),
337 'datamember_type' : ([c_scope, c_int], c_ccharp),
338 'datamember_offset' : ([c_scope, c_int], c_intptr_t),
339 'datamember_index' : ([c_scope, c_ccharp], c_int),
340
341 # data member properties
342 'is_publicdata' : ([c_scope, c_int], c_int),
343 'is_protecteddata' : ([c_scope, c_int], c_int),
344 'is_staticdata' : ([c_scope, c_int], c_int),
345 'is_const_data' : ([c_scope, c_int], c_int),
346 'is_enum_data' : ([c_scope, c_int], c_int),
347 'get_dimension_size' : ([c_scope, c_int, c_int], c_int),
348
349 # enum properties
350 'get_enum' : ([c_scope, c_ccharp], c_enum),
351 'get_num_enum_data' : ([c_enum], c_index),
352 'get_enum_data_name' : ([c_enum, c_index], c_ccharp),
353 'get_enum_data_value' : ([c_enum, c_index], c_llong),
354
355 # misc helpers
356 'strtoll' : ([c_ccharp], c_llong),
357 'strtoull' : ([c_ccharp], c_ullong),
358 'free' : ([c_voidp], c_void),
359
360 'charp2stdstring' : ([c_ccharp, c_size_t], c_object),
361 #stdstring2charp actually takes an size_t* as last parameter, but this will do
362 'stdstring2charp' : ([c_object, c_voidp], c_ccharp),
363 'stdstring2stdstring' : ([c_object], c_object),
364
365 'longdouble2double' : ([c_voidp], c_double),
366 'double2longdouble' : ([c_double, c_voidp], c_void),
367
368 'vectorbool_getitem' : ([c_object, c_int], c_int),
369 'vectorbool_setitem' : ([c_object, c_int, c_int], c_void),
370 }
371
372 # size/offset are backend-specific but fixed after load
373 self.c_sizeof_farg = 0
374 self.c_offset_farg = 0
375
376
377 def load_backend(space):
378 state = space.fromcache(State)
379 if state.backend is None:
380 from pypy.module._cffi_backend.libraryobj import W_Library
381 if os.environ.get('CPPYY_BACKEND_LIBRARY'):
382 libname = os.environ['CPPYY_BACKEND_LIBRARY']
383 state.backend = W_Library(space, space.newtext(libname), dldflags)
384 else:
385 # try usual lookups
386 try:
387 if backend_library[-len(backend_ext):] == backend_ext:
388 fullname = backend_library
389 else:
390 fullname = backend_library+backend_ext
391 state.backend = W_Library(space, space.newtext(fullname), dldflags)
392 except Exception as e:
393 soabi = space.config.objspace.soabi
394 if soabi is None:
395 soabi = '.pypy-%d%d' % PYPY_VERSION[:2]
396 state.backend = W_Library(space, space.newtext(backend_library+soabi+backend_ext), dldflags)
397
398 if state.backend:
399 # fix constants
400 state.c_sizeof_farg = _cdata_to_size_t(
401 space, call_capi(space, 'function_arg_sizeof', []))
402 state.c_offset_farg = _cdata_to_size_t(
403 space, call_capi(space, 'function_arg_typeoffset', []))
404
405 def verify_backend(space):
406 try:
407 load_backend(space)
408 except Exception:
409 if objectmodel.we_are_translated():
410 raise oefmt(space.w_ImportError,
411 "missing backend library %s", backend_library)
412 return False
413 return True
414
415 def call_capi(space, name, args):
416 state = space.fromcache(State)
417 try:
418 c_call = state.capi_calls[name]
419 except KeyError:
420 if state.backend is None:
421 verify_backend(space)
422 iface = state.capi_call_ifaces[name]
423 cfunc = W_RCTypeFunc(space, iface[0], iface[1], False)
424 c_call = state.backend.load_function(cfunc, 'cppyy_'+name)
425 # TODO: there must be a better way to trick the leakfinder ...
426 if not objectmodel.we_are_translated():
427 leakfinder.remember_free(c_call.ctype.cif_descr._obj0)
428 state.capi_calls[name] = c_call
429 with c_call as ptr:
430 return c_call.ctype.rcall(ptr, args)
431
432 def _cdata_to_ptr(space, w_cdata):
433 w_cdata = space.interp_w(cdataobj.W_CData, w_cdata, can_be_None=False)
434 with w_cdata as ptr:
435 return rffi.cast(rffi.VOIDP, ptr) # escapes (is okay)
436 return rffi.cast(rffi.VOIDP, 0)
437
438 def _cdata_to_cobject(space, w_cdata):
439 ptr = _cdata_to_ptr(space, w_cdata)
440 return rffi.cast(C_OBJECT, ptr)
441
442 _cdata_to_cenum = _cdata_to_cobject
443
444 def _cdata_to_size_t(space, w_cdata):
445 return rffi.cast(rffi.SIZE_T, space.uint_w(w_cdata))
446
447 def _cdata_to_ptrdiff_t(space, w_cdata):
448 return rffi.cast(rffi.PTRDIFF_T, space.int_w(w_cdata))
449
450 def _cdata_to_intptr_t(space, w_cdata):
451 return rffi.cast(rffi.INTPTR_T, space.int_w(w_cdata))
452
453 def _cdata_to_ccharp(space, w_cdata):
454 ptr = _cdata_to_ptr(space, w_cdata)
455 return rffi.cast(rffi.CCHARP, ptr)
456
457 # direct interpreter access
458 def c_compile(space, code):
459 return space.int_w(call_capi(space, 'compile', [_ArgS(code)]))
460 def c_cppyy_to_string(space, cppclass, cppobj):
461 args = [_ArgC(cppclass), _ArgO(cppobj)]
462 return charp2str_free(space, call_capi(space, 'cppyy_to_string', args))
463
464 # name to opaque C++ scope representation ------------------------------------
465 def c_resolve_name(space, name):
466 return charp2str_free(space, call_capi(space, 'resolve_name', [_ArgS(name)]))
467 def c_resolve_enum(space, name):
468 return charp2str_free(space, call_capi(space, 'resolve_enum', [_ArgS(name)]))
469 def c_get_scope_opaque(space, name):
470 return rffi.cast(C_SCOPE, space.uint_w(call_capi(space, 'get_scope', [_ArgS(name)])))
471 def c_actual_class(space, cppclass, cppobj):
472 args = [_ArgC(cppclass), _ArgO(cppobj)]
473 return rffi.cast(C_TYPE, space.uint_w(call_capi(space, 'actual_class', args)))
474 def c_size_of_klass(space, cppclass):
475 return _cdata_to_size_t(space, call_capi(space, 'size_of_klass', [_ArgC(cppclass)]))
476 def c_size_of_type(space, name):
477 return _cdata_to_size_t(space, call_capi(space, 'size_of_type', [_ArgS(name)]))
478
479 def c_is_builtin(space, name):
480 return space.bool_w(call_capi(space, 'is_builtin', [_ArgS(name)]))
481 def c_is_complete(space, name):
482 return space.bool_w(call_capi(space, 'is_complete', [_ArgS(name)]))
483
484 # memory management ----------------------------------------------------------
485 def c_allocate(space, cppclass):
486 return _cdata_to_cobject(space, call_capi(space, 'allocate', [_ArgC(cppclass)]))
487 def c_deallocate(space, cppclass, cppobj):
488 call_capi(space, 'deallocate', [_ArgC(cppclass), _ArgO(cppobj)])
489 def c_construct(space, cppclass):
490 return _cdata_to_cobject(space, call_capi(space, 'construct', [_ArgC(cppclass)]))
491 def c_destruct(space, cppclass, cppobj):
492 call_capi(space, 'destruct', [_ArgC(cppclass), _ArgO(cppobj)])
493
494 # method/function dispatching ------------------------------------------------
495 def c_call_v(space, cppmeth, cppobj, nargs, cargs):
496 args = [_ArgM(cppmeth), _ArgO(cppobj), _ArgI(nargs), _ArgP(cargs)]
497 call_capi(space, 'call_v', args)
498 def c_call_b(space, cppmeth, cppobj, nargs, cargs):
499 args = [_ArgM(cppmeth), _ArgO(cppobj), _ArgI(nargs), _ArgP(cargs)]
500 return rffi.cast(rffi.UCHAR, space.c_uint_w(call_capi(space, 'call_b', args)))
501 def c_call_c(space, cppmeth, cppobj, nargs, cargs):
502 args = [_ArgM(cppmeth), _ArgO(cppobj), _ArgI(nargs), _ArgP(cargs)]
503 return rffi.cast(rffi.CHAR, space.bytes_w(call_capi(space, 'call_c', args))[0])
504 def c_call_h(space, cppmeth, cppobj, nargs, cargs):
505 args = [_ArgM(cppmeth), _ArgO(cppobj), _ArgI(nargs), _ArgP(cargs)]
506 return rffi.cast(rffi.SHORT, space.int_w(call_capi(space, 'call_h', args)))
507 def c_call_i(space, cppmeth, cppobj, nargs, cargs):
508 args = [_ArgM(cppmeth), _ArgO(cppobj), _ArgI(nargs), _ArgP(cargs)]
509 return rffi.cast(rffi.INT, space.c_int_w(call_capi(space, 'call_i', args)))
510 def c_call_l(space, cppmeth, cppobj, nargs, cargs):
511 args = [_ArgM(cppmeth), _ArgO(cppobj), _ArgI(nargs), _ArgP(cargs)]
512 return rffi.cast(rffi.LONG, space.int_w(call_capi(space, 'call_l', args)))
513 def c_call_ll(space, cppmeth, cppobj, nargs, cargs):
514 args = [_ArgM(cppmeth), _ArgO(cppobj), _ArgI(nargs), _ArgP(cargs)]
515 return rffi.cast(rffi.LONGLONG, space.r_longlong_w(call_capi(space, 'call_ll', args)))
516 def c_call_f(space, cppmeth, cppobj, nargs, cargs):
517 args = [_ArgM(cppmeth), _ArgO(cppobj), _ArgI(nargs), _ArgP(cargs)]
518 return rffi.cast(rffi.FLOAT, r_singlefloat(space.float_w(call_capi(space, 'call_f', args))))
519 def c_call_d(space, cppmeth, cppobj, nargs, cargs):
520 args = [_ArgM(cppmeth), _ArgO(cppobj), _ArgI(nargs), _ArgP(cargs)]
521 return rffi.cast(rffi.DOUBLE, space.float_w(call_capi(space, 'call_d', args)))
522 def c_call_ld(space, cppmeth, cppobj, nargs, cargs):
523 args = [_ArgM(cppmeth), _ArgO(cppobj), _ArgI(nargs), _ArgP(cargs)]
524 #return rffi.cast(rffi.LONGDOUBLE, space.float_w(call_capi(space, 'call_ld', args)))
525 # call_nld narrows long double to double
526 return rffi.cast(rffi.DOUBLE, space.float_w(call_capi(space, 'call_nld', args)))
527
528 def c_call_r(space, cppmeth, cppobj, nargs, cargs):
529 args = [_ArgM(cppmeth), _ArgO(cppobj), _ArgI(nargs), _ArgP(cargs)]
530 return _cdata_to_ptr(space, call_capi(space, 'call_r', args))
531 def c_call_s(space, cppmeth, cppobj, nargs, cargs):
532 length = lltype.malloc(rffi.SIZE_TP.TO, 1, flavor='raw')
533 try:
534 w_cstr = call_capi(space, 'call_s',
535 [_ArgM(cppmeth), _ArgO(cppobj), _ArgI(nargs), _ArgP(cargs),
536 _ArgP(rffi.cast(rffi.VOIDP, length))])
537 cstr_len = int(intmask(length[0]))
538 finally:
539 lltype.free(length, flavor='raw')
540 return _cdata_to_ccharp(space, w_cstr), cstr_len
541 def c_constructor(space, cppmeth, cppobj, nargs, cargs):
542 args = [_ArgM(cppmeth), _ArgO(cppobj), _ArgI(nargs), _ArgP(cargs)]
543 return _cdata_to_cobject(space, call_capi(space, 'constructor', args))
544 def c_destructor(space, cppclass, cppobj):
545 call_capi(space, 'constructor', [_ArgC(cppclass), _ArgO(cppobj)])
546 def c_call_o(space, cppmeth, cppobj, nargs, cargs, cppclass):
547 args = [_ArgM(cppmeth), _ArgO(cppobj), _ArgI(nargs), _ArgP(cargs), _ArgC(cppclass)]
548 return _cdata_to_cobject(space, call_capi(space, 'call_o', args))
549
550 def c_function_address(space, cppmeth):
551 return rffi.cast(C_FUNC_PTR,
552 _cdata_to_ptr(space, call_capi(space, 'function_address', [_ArgM(cppmeth)])))
553
554 # handling of function argument buffer ---------------------------------------
555 def c_allocate_function_args(space, size):
556 return _cdata_to_ptr(space, call_capi(space, 'allocate_function_args', [_ArgI(size)]))
557 def c_deallocate_function_args(space, cargs):
558 call_capi(space, 'deallocate_function_args', [_ArgP(cargs)])
559 def c_function_arg_sizeof(space):
560 state = space.fromcache(State)
561 return state.c_sizeof_farg
562 def c_function_arg_typeoffset(space):
563 state = space.fromcache(State)
564 return state.c_offset_farg
565
566 # scope reflection information -----------------------------------------------
567 def c_is_namespace(space, scope):
568 return space.bool_w(call_capi(space, 'is_namespace', [_ArgH(scope)]))
569 def c_is_template(space, name):
570 return space.bool_w(call_capi(space, 'is_template', [_ArgS(name)]))
571 def c_is_abstract(space, cpptype):
572 return space.bool_w(call_capi(space, 'is_abstract', [_ArgC(cpptype)]))
573 def c_is_enum(space, name):
574 return space.bool_w(call_capi(space, 'is_enum', [_ArgS(name)]))
575 def c_is_aggregate(space, name):
576 return space.bool_w(call_capi(space, 'is_aggregate', [_ArgS(name)]))
577 def c_is_default_constructable(space, name):
578 return space.bool_w(call_capi(space, 'is_default_constructable', [_ArgS(name)]))
579
580 def c_get_all_cpp_names(space, cppscope):
581 sz = lltype.malloc(rffi.SIZE_TP.TO, 1, flavor='raw', zero=True)
582 try:
583 args = [_ArgC(cppscope), _ArgP(rffi.cast(rffi.VOIDP, sz))]
584 rawnames = rffi.cast(rffi.CCHARPP,
585 _cdata_to_ptr(space, call_capi(space, 'get_all_cpp_names', args)))
586 count = int(intmask(sz[0]))
587 finally:
588 lltype.free(sz, flavor='raw')
589 allnames = []
590 for i in range(count):
591 pystr = rffi.charp2str(rawnames[i])
592 c_free(space, rffi.cast(rffi.VOIDP, rawnames[i])) # c_free defined below
593 allnames.append(pystr)
594 c_free(space, rffi.cast(rffi.VOIDP, rawnames)) # id.
595 return allnames
596
597 # namespace reflection information
598 def c_get_using_namespaces(space, cppscope):
599 return space.uint_w(call_capi(space, 'get_using_namespaces', [_ArgC(cppscope)]))
600
601 # type/class reflection information ------------------------------------------
602 def c_final_name(space, handle):
603 return charp2str_free(space, call_capi(space, 'final_name', [_ArgH(handle)]))
604 def c_scoped_final_name(space, handle):
605 return charp2str_free(space, call_capi(space, 'scoped_final_name', [_ArgH(handle)]))
606 def c_has_virtual_destructor(space, handle):
607 return space.bool_w(call_capi(space, 'has_virtual_destructor', [_ArgH(handle)]))
608 def c_has_complex_hierarchy(space, handle):
609 return space.bool_w(call_capi(space, 'has_complex_hierarchy', [_ArgH(handle)]))
610 def c_num_bases(space, cppclass):
611 return space.int_w(call_capi(space, 'num_bases', [_ArgC(cppclass)]))
612 def c_base_name(space, cppclass, base_index):
613 args = [_ArgC(cppclass), _ArgI(base_index)]
614 return charp2str_free(space, call_capi(space, 'base_name', args))
615 def c_is_subtype(space, derived, base):
616 jit.promote(base)
617 if derived == base:
618 return bool(1)
619 return space.bool_w(call_capi(space, 'is_subtype', [_ArgC(derived), _ArgC(base)]))
620 def c_is_smartptr(space, handle):
621 return space.bool_w(call_capi(space, 'is_smartptr', [_ArgH(handle)]))
622 def c_smartptr_info(space, name):
623 out_raw = lltype.malloc(rffi.ULONGP.TO, 1, flavor='raw', zero=True)
624 out_deref = lltype.malloc(rffi.ULONGP.TO, 1, flavor='raw', zero=True)
625 try:
626 args = [_ArgS(name),
627 _ArgP(rffi.cast(rffi.VOIDP, out_raw)), _ArgP(rffi.cast(rffi.VOIDP, out_deref))]
628 result = space.bool_w(call_capi(space, 'smartptr_info', args))
629 raw = rffi.cast(C_TYPE, out_raw[0])
630 deref = rffi.cast(C_METHOD, out_deref[0])
631 finally:
632 lltype.free(out_deref, flavor='raw')
633 lltype.free(out_raw, flavor='raw')
634 return (result, raw, deref)
635 def c_add_smartptr_type(space, name):
636 return space.bool_w(call_capi(space, 'add_smartptr_type', [_ArgS(name)]))
637
638 def c_add_type_reducer(space, reducable, reduced):
639 return space.bool_w(call_capi(space, 'add_type_reducer', [_ArgS(reducable), _ArgS(reduced)]))
640
641 def _c_base_offset(space, derived_h, base_h, address, direction):
642 args = [_ArgH(derived_h), _ArgH(base_h), _ArgO(address), _ArgI(direction)]
643 return _cdata_to_ptrdiff_t(space, call_capi(space, 'base_offset', args))
644 def c_base_offset(space, derived, base, address, direction):
645 if derived == base:
646 return rffi.cast(rffi.LONG, 0)
647 return _c_base_offset(space, derived.handle, base.handle, address, direction)
648 def c_base_offset1(space, derived_h, base, address, direction):
649 return _c_base_offset(space, derived_h, base.handle, address, direction)
650
651 # method/function reflection information -------------------------------------
652 def c_num_methods(space, cppscope):
653 return space.int_w(call_capi(space, 'num_methods', [_ArgC(cppscope)]))
654 def c_method_indices_from_name(space, cppscope, name):
655 args = [_ArgC(cppscope), _ArgS(name)]
656 indices = rffi.cast(C_INDEX_ARRAY,
657 _cdata_to_ptr(space, call_capi(space, 'method_indices_from_name', args)))
658 if not indices:
659 return []
660 py_indices = []
661 i = 0
662 index = indices[i]
663 while index != rffi.cast(C_INDEX, -1):
664 i += 1
665 py_indices.append(index)
666 index = indices[i]
667 c_free(space, rffi.cast(rffi.VOIDP, indices)) # c_free defined below
668 return py_indices
669
670 def c_get_method(space, cppscope, index):
671 args = [_ArgC(cppscope), _ArgU(index)]
672 return _cdata_to_intptr_t(space, call_capi(space, 'get_method', args))
673
674 def c_method_name(space, cppmeth):
675 return charp2str_free(space, call_capi(space, 'method_name', [_ArgM(cppmeth)]))
676 def c_method_full_name(space, cppmeth):
677 return charp2str_free(space, call_capi(space, 'method_full_name', [_ArgM(cppmeth)]))
678 def c_method_mangled_name(space, cppmeth):
679 return charp2str_free(space, call_capi(space, 'method_mangled_name', [_ArgM(cppmeth)]))
680 def c_method_result_type(space, cppmeth):
681 return charp2str_free(space, call_capi(space, 'method_result_type', [_ArgM(cppmeth)]))
682 def c_method_num_args(space, cppmeth):
683 return space.int_w(call_capi(space, 'method_num_args', [_ArgM(cppmeth)]))
684 def c_method_req_args(space, cppmeth):
685 return space.int_w(call_capi(space, 'method_req_args', [_ArgM(cppmeth)]))
686 def c_method_arg_name(space, cppmeth, arg_index):
687 args = [_ArgM(cppmeth), _ArgI(arg_index)]
688 return charp2str_free(space, call_capi(space, 'method_arg_name', args))
689 def c_method_arg_type(space, cppmeth, arg_index):
690 args = [_ArgM(cppmeth), _ArgI(arg_index)]
691 return charp2str_free(space, call_capi(space, 'method_arg_type', args))
692 def c_method_arg_default(space, cppmeth, arg_index):
693 args = [_ArgM(cppmeth), _ArgI(arg_index)]
694 return charp2str_free(space, call_capi(space, 'method_arg_default', args))
695 def c_method_signature(space, cppmeth, show_formalargs=True):
696 args = [_ArgM(cppmeth), _ArgI(show_formalargs)]
697 return charp2str_free(space, call_capi(space, 'method_signature', args))
698 def c_method_signature_max(space, cppmeth, show_formalargs, maxargs):
699 args = [_ArgM(cppmeth), _ArgI(show_formalargs), _ArgI(maxargs)]
700 return charp2str_free(space, call_capi(space, 'method_signature_max', args))
701 def c_method_prototype(space, cppscope, cppmeth, show_formalargs=True):
702 args = [_ArgC(cppscope), _ArgM(cppmeth), _ArgI(show_formalargs)]
703 return charp2str_free(space, call_capi(space, 'method_prototype', args))
704 def c_is_const_method(space, cppmeth):
705 return space.bool_w(call_capi(space, 'is_const_method', [_ArgM(cppmeth)]))
706
707 def c_get_num_templated_methods(space, cppscope):
708 return space.int_w(call_capi(space, 'get_num_templated_methods', [_ArgC(cppscope)]))
709 def c_get_templated_method_name(space, cppscope, index):
710 args = [_ArgC(cppscope), _ArgU(index)]
711 return charp2str_free(space, call_capi(space, 'get_templated_method_name', args))
712 def c_is_templated_constructor(space, cppscope, index):
713 args = [_ArgC(cppscope), _ArgU(index)]
714 return space.bool_w(space, call_capi(space, 'is_templated_constructor', args))
715 def c_exists_method_template(space, cppscope, name):
716 args = [_ArgC(cppscope), _ArgS(name)]
717 return space.bool_w(call_capi(space, 'exists_method_template', args))
718 def c_method_is_template(space, cppscope, index):
719 args = [_ArgC(cppscope), _ArgU(index)]
720 return space.bool_w(call_capi(space, 'method_is_template', args))
721 def c_get_method_template(space, cppscope, name, proto):
722 args = [_ArgC(cppscope), _ArgS(name), _ArgS(proto)]
723 return rffi.cast(C_METHOD, space.int_w(call_capi(space, 'get_method_template', args)))
724
725 def c_get_global_operator(space, nss, lc, rc, op):
726 if nss is not None:
727 args = [_ArgC(nss), _ArgC(lc), _ArgC(rc), _ArgS(op)]
728 return rffi.cast(C_INDEX, space.uint_w(call_capi(space, 'get_global_operator', args)))
729 return rffi.cast(C_INDEX, -1)
730
731 # method properties ----------------------------------------------------------
732 def c_is_public_method(space, cppmeth):
733 return space.bool_w(call_capi(space, 'is_public_method', [_ArgM(cppmeth)]))
734 def c_is_protected_method(space, cppmeth):
735 return space.bool_w(call_capi(space, 'is_protected_method', [_ArgM(cppmeth)]))
736 def c_is_constructor(space, cppmeth):
737 return space.bool_w(call_capi(space, 'is_constructor', [_ArgM(cppmeth)]))
738 def c_is_destructor(space, cppmeth):
739 return space.bool_w(call_capi(space, 'is_destructor', [_ArgM(cppmeth)]))
740 def c_is_staticmethod(space, cppmeth):
741 return space.bool_w(call_capi(space, 'is_staticmethod', [_ArgM(cppmeth)]))
742
743 # data member reflection information -----------------------------------------
744 def c_num_datamembers(space, cppscope):
745 return space.int_w(call_capi(space, 'num_datamembers', [_ArgC(cppscope)]))
746 def c_datamember_name(space, cppscope, datamember_index):
747 args = [_ArgC(cppscope), _ArgI(datamember_index)]
748 return charp2str_free(space, call_capi(space, 'datamember_name', args))
749 def c_datamember_type(space, cppscope, datamember_index):
750 args = [_ArgC(cppscope), _ArgI(datamember_index)]
751 return charp2str_free(space, call_capi(space, 'datamember_type', args))
752 def c_datamember_offset(space, cppscope, datamember_index):
753 args = [_ArgC(cppscope), _ArgI(datamember_index)]
754 return _cdata_to_intptr_t(space, call_capi(space, 'datamember_offset', args))
755
756 def c_datamember_index(space, cppscope, name):
757 args = [_ArgC(cppscope), _ArgS(name)]
758 return space.int_w(call_capi(space, 'datamember_index', args))
759
760 # data member properties -----------------------------------------------------
761 def c_is_publicdata(space, cppscope, datamember_index):
762 args = [_ArgC(cppscope), _ArgU(datamember_index)]
763 return space.bool_w(call_capi(space, 'is_publicdata', args))
764 def c_is_protecteddata(space, cppscope, datamember_index):
765 args = [_ArgC(cppscope), _ArgU(datamember_index)]
766 return space.bool_w(call_capi(space, 'is_protecteddata', args))
767 def c_is_staticdata(space, cppscope, datamember_index):
768 args = [_ArgC(cppscope), _ArgU(datamember_index)]
769 return space.bool_w(call_capi(space, 'is_staticdata', args))
770 def c_is_const_data(space, cppscope, datamember_index):
771 args = [_ArgC(cppscope), _ArgU(datamember_index)]
772 return space.bool_w(call_capi(space, 'is_const_data', args))
773 def c_is_enum_data(space, cppscope, datamember_index):
774 args = [_ArgC(cppscope), _ArgU(datamember_index)]
775 return space.bool_w(call_capi(space, 'is_enum_data', args))
776 def c_get_dimension_size(space, cppscope, datamember_index, dim_idx):
777 args = [_ArgC(cppscope), _ArgU(datamember_index), _ArgI(dim_idx)]
778 return space.int_w(call_capi(space, 'get_dimension_size', args))
779
780 # enum properties ------------------------------------------------------------
781 def c_get_enum(space, cppscope, name):
782 args = [_ArgC(cppscope), _ArgS(name)]
783 return _cdata_to_cenum(call_capi(space, 'get_enum', args))
784 def c_num_enum_data(space, cppenum):
785 return space.int_w(call_capi(space, 'num_enum_data', [_ArgE(cppenum)]))
786 def c_get_enum_data_name(space, cppenum, idata):
787 args = [_ArgE(cppenum), _ArgU(idata)]
788 return charp2str_free(space, call_capi(space, 'get_enum_data_name', args))
789 def c_get_enum_data_value(space, cppenum, idata):
790 args = [_ArgE(cppenum), _ArgU(idata)]
791 return rffi.cast(C_ENUM, call_capi(space, 'get_enum_data_value', args))
792
793 # misc helpers ---------------------------------------------------------------
794 def c_strtoll(space, svalue):
795 return space.r_longlong_w(call_capi(space, 'strtoll', [_ArgS(svalue)]))
796 def c_strtoull(space, svalue):
797 return space.r_ulonglong_w(call_capi(space, 'strtoull', [_ArgS(svalue)]))
798 def c_free(space, voidp):
799 call_capi(space, 'free', [_ArgP(voidp)])
800
801 def charp2str_free(space, cdata):
802 charp = rffi.cast(rffi.CCHARP, _cdata_to_ptr(space, cdata))
803 pystr = rffi.charp2str(charp)
804 c_free(space, rffi.cast(rffi.VOIDP, charp))
805 return pystr
806
807 def c_charp2stdstring(space, svalue, sz):
808 return _cdata_to_cobject(space, call_capi(space, 'charp2stdstring',
809 [_ArgS(svalue), _ArgU(rffi.cast(C_INDEX, sz))]))
810 def c_stdstring2charp(space, cppstr):
811 szp = lltype.malloc(rffi.SIZE_TP.TO, 1, flavor='raw')
812 try:
813 w_cstr = call_capi(space, 'stdstring2charp',
814 [_ArgO(cppstr), _ArgP(rffi.cast(rffi.VOIDP, szp))])
815 cstr_len = int(intmask(szp[0]))
816 finally:
817 lltype.free(szp, flavor='raw')
818 return rffi.charpsize2str(_cdata_to_ccharp(space, w_cstr), cstr_len)
819 def c_stdstring2stdstring(space, cppobj):
820 return _cdata_to_cobject(space, call_capi(space, 'stdstring2stdstring', [_ArgO(cppobj)]))
821
822 def c_longdouble2double(space, addr):
823 return space.float_w(call_capi(space, 'longdouble2double', [_ArgP(addr)]))
824 def c_double2longdouble(space, dval, addr):
825 call_capi(space, 'double2longdouble', [_ArgD(dval), _ArgP(addr)])
826
827 def c_vectorbool_getitem(space, vbool, idx):
828 return call_capi(space, 'vectorbool_getitem', [_ArgO(vbool), _ArgI(idx)])
829 def c_vectorbool_setitem(space, vbool, idx, value):
830 call_capi(space, 'vectorbool_setitem', [_ArgO(vbool), _ArgI(idx), _ArgI(value)])
831
832
833 # TODO: factor these out ...
834 # pythonizations
835 def stdstring_c_str(space, w_self):
836 """Return a python string taking into account \0"""
837 from pypy.module._cppyy import interp_cppyy
838 cppstr = space.interp_w(interp_cppyy.W_CPPInstance, w_self, can_be_None=False)
839 return space.newtext(c_stdstring2charp(space, cppstr._rawobject))
840
841 def vbool_getindex(space, w_vbool, w_idx):
842 idx = space.getindex_w(w_idx, space.w_IndexError, "std::vector<bool> index")
843 sz = space.len_w(w_vbool)
844 if idx < 0: idx += sz
845 if idx < 0 or idx >= sz:
846 raise IndexError
847 return idx
848
849 def vectorbool_getitem(space, w_self, w_idx):
850 """Index a std::vector<bool>, return the value"""
851 from pypy.module._cppyy import interp_cppyy
852 vbool = space.interp_w(interp_cppyy.W_CPPInstance, w_self, can_be_None=False)
853 idx = vbool_getindex(space, w_self, w_idx)
854 item = c_vectorbool_getitem(space, vbool._rawobject, idx)
855 return space.newbool(space.is_true(item))
856
857 def vectorbool_setitem(space, w_self, w_idx, w_value):
858 """Index a std::vector<bool>, set the value"""
859 from pypy.module._cppyy import interp_cppyy
860 vbool = space.interp_w(interp_cppyy.W_CPPInstance, w_self, can_be_None=False)
861 idx = vbool_getindex(space, w_self, w_idx)
862 c_vectorbool_setitem(space, vbool._rawobject, idx, int(space.is_true(w_value)))
863
864 class W_STLVectorIter(W_AbstractSeqIterObject):
865 # w_seq and index are in base class
866 _immutable_fields_ = ['converter', 'data', 'len', 'stride']
867
868 def __init__(self, space, w_vector):
869 W_AbstractSeqIterObject.__init__(self, w_vector)
870 # TODO: this should live in rpythonize.py or something so that the
871 # imports can move to the top w/o getting circles
872 from pypy.module._cppyy import interp_cppyy
873 assert isinstance(w_vector, interp_cppyy.W_CPPInstance)
874 vector = space.interp_w(interp_cppyy.W_CPPInstance, w_vector)
875
876 v_type = c_resolve_name(space, vector.clsdecl.name+'::value_type')
877 v_size = c_size_of_type(space, v_type)
878
879 if not v_type or not v_size:
880 raise NotImplementedError # fallback on getitem
881
882 from pypy.module._cppyy import converter
883 self.converter = converter.get_converter(space, v_type, '')
884
885 # this 'data' is from the decl, so not the pythonized data from pythonify.py
886 w_arr = space.call_obj_args(vector.clsdecl.get_overload('data'), w_vector, Arguments(space, []))
887 arr = space.interp_w(W_ArrayInstance, w_arr, can_be_None=True)
888 if not arr:
889 raise OperationError(space.w_StopIteration, space.w_None)
890
891 self.data = rffi.cast(rffi.CCHARP, space.uint_w(arr.getbuffer(space)))
892 self.len = space.uint_w(space.call_obj_args(vector.clsdecl.get_overload('size'), w_vector, Arguments(space, [])))
893 self.stride = v_size
894
895 def descr_next(self, space):
896 if self.w_seq is None:
897 raise OperationError(space.w_StopIteration, space.w_None)
898 if self.len <= self.index:
899 self.w_seq = None
900 raise OperationError(space.w_StopIteration, space.w_None)
901 offset = lltype.direct_ptradd(self.data, rffi.cast(rffi.SIZE_T, self.index*self.stride))
902 w_item = self.converter.from_memory(space, space.w_None, rffi.cast(rffi.LONG, offset))
903 self.index += 1
904 return w_item
905
906 def stdvector_iter(space, w_self):
907 return W_STLVectorIter(space, w_self)
908
909
910 # setup pythonizations for later use at run-time
911 _pythonizations = {}
912 def register_pythonizations(space):
913 "NOT_RPYTHON"
914
915 allfuncs = [
916
917 ### std::string
918 stdstring_c_str,
919
920 ### std::vector
921 stdvector_iter,
922
923 ### std::vector<bool>
924 vectorbool_getitem,
925 vectorbool_setitem,
926 ]
927
928 for f in allfuncs:
929 _pythonizations[f.__name__] = interp2app(f).spacebind(space)
930
931 def _method_alias(space, w_pycppclass, m1, m2):
932 space.setattr(w_pycppclass, space.newtext(m1),
933 space.getattr(w_pycppclass, space.newtext(m2)))
934
935 def pythonize(space, w_pycppclass, name):
936 if name == "string":
937 space.setattr(w_pycppclass, space.newtext("c_str"), _pythonizations["stdstring_c_str"])
938 _method_alias(space, w_pycppclass, "_cppyy_as_builtin", "c_str")
939 _method_alias(space, w_pycppclass, "__str__", "c_str")
940
941 if name.find("std::vector<bool", 0, 16) == 0:
942 space.setattr(w_pycppclass, space.newtext("__getitem__"), _pythonizations["vectorbool_getitem"])
943 space.setattr(w_pycppclass, space.newtext("__setitem__"), _pythonizations["vectorbool_setitem"])
944
945 elif name.find("std::vector", 0, 11) == 0:
946 space.setattr(w_pycppclass, space.newtext("__iter__"), _pythonizations["stdvector_iter"])