MCPcopy Index your code
hub / github.com/python/mypy / vec_create

Function vec_create

mypyc/irbuild/vec.py:76–143  ·  view source on GitHub ↗
(
    builder: LowLevelIRBuilder,
    vtype: RVec,
    length: int | Value,
    line: int,
    *,
    capacity: Value | None = None,
)

Source from the content-addressed store, hash-verified

74
75
76def vec_create(
77 builder: LowLevelIRBuilder,
78 vtype: RVec,
79 length: int | Value,
80 line: int,
81 *,
82 capacity: Value | None = None,
83) -> Value:
84 if isinstance(length, int):
85 length = Integer(length, c_pyssize_t_rprimitive)
86 length = as_platform_int(builder, length, line)
87 if capacity is not None:
88 capacity = as_platform_int(builder, capacity, line)
89 else:
90 capacity = length
91
92 item_type = vtype.item_type
93 api_name = vec_api_by_item_type.get(item_type)
94 if api_name is not None:
95 call = CallC(
96 f"{api_name}.alloc",
97 [length, capacity],
98 vtype,
99 False,
100 False,
101 error_kind=ERR_MAGIC,
102 line=line,
103 )
104 return builder.add(call)
105
106 typeobj, optional, depth = vec_item_type_info(builder, item_type, line)
107 if typeobj is not None:
108 typeval: Value
109 if isinstance(typeobj, Integer):
110 typeval = typeobj
111 else:
112 # Create an integer which will hold the type object * as an integral value.
113 # Assign implicitly coerces between pointer/integer types.
114 typeval = Register(pointer_rprimitive)
115 builder.add(Assign(typeval, typeobj))
116 if optional:
117 typeval = builder.add(
118 IntOp(pointer_rprimitive, typeval, Integer(1, pointer_rprimitive), IntOp.OR)
119 )
120 if depth == 0:
121 call = CallC(
122 "VecTApi.alloc",
123 [length, capacity, typeval],
124 vtype,
125 False,
126 False,
127 error_kind=ERR_MAGIC,
128 line=line,
129 )
130 return builder.add(call)
131 else:
132 call = CallC(
133 "VecNestedApi.alloc",

Callers 5

transform_call_exprFunction · 0.90
vec_from_iterableFunction · 0.90
vec_create_initializedFunction · 0.85
vec_create_from_valuesFunction · 0.85

Calls 10

IntegerClass · 0.90
CallCClass · 0.90
RegisterClass · 0.90
AssignClass · 0.90
IntOpClass · 0.90
isinstanceFunction · 0.85
as_platform_intFunction · 0.85
vec_item_type_infoFunction · 0.85
getMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…