| 1 |
"""Miscellaneous primitive ops.""" |
| 2 |
|
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
from mypyc.ir.deps import LIBRT_BASE64 |
| 6 |
from mypyc.ir.ops import ERR_FALSE, ERR_MAGIC, ERR_MAGIC_OVERLAPPING, ERR_NEVER |
| 7 |
from mypyc.ir.rtypes import ( |
| 8 |
KNOWN_NATIVE_TYPES, |
| 9 |
RUnion, |
| 10 |
bit_rprimitive, |
| 11 |
bool_rprimitive, |
| 12 |
bytes_rprimitive, |
| 13 |
c_int_rprimitive, |
| 14 |
c_pointer_rprimitive, |
| 15 |
c_pyssize_t_rprimitive, |
| 16 |
cstring_rprimitive, |
| 17 |
dict_rprimitive, |
| 18 |
float_rprimitive, |
| 19 |
int_rprimitive, |
| 20 |
none_rprimitive, |
| 21 |
object_pointer_rprimitive, |
| 22 |
object_rprimitive, |
| 23 |
pointer_rprimitive, |
| 24 |
str_rprimitive, |
| 25 |
uint8_rprimitive, |
| 26 |
void_rtype, |
| 27 |
) |
| 28 |
from mypyc.primitives.registry import ( |
| 29 |
ERR_NEG_INT, |
| 30 |
custom_op, |
| 31 |
custom_primitive_op, |
| 32 |
function_op, |
| 33 |
load_address_op, |
| 34 |
load_global_op, |
| 35 |
method_op, |
| 36 |
) |
| 37 |
|
| 38 |
# Get the 'bool' type object. |
| 39 |
load_address_op(name="builtins.bool", type=object_rprimitive, src="PyBool_Type") |
| 40 |
|
| 41 |
# Get the 'range' type object. |
| 42 |
load_address_op(name="builtins.range", type=object_rprimitive, src="PyRange_Type") |
| 43 |
|
| 44 |
# Get the boxed Python 'None' object |
| 45 |
none_object_op = load_address_op(name="Py_None", type=object_rprimitive, src="_Py_NoneStruct") |
| 46 |
|
| 47 |
# Get the boxed object '...' |
| 48 |
ellipsis_op = load_address_op(name="...", type=object_rprimitive, src="_Py_EllipsisObject") |
| 49 |
|
| 50 |
# Get the boxed NotImplemented object |
| 51 |
not_implemented_op = load_address_op( |
| 52 |
name="builtins.NotImplemented", type=object_rprimitive, src="_Py_NotImplementedStruct" |
| 53 |
) |
| 54 |
|
| 55 |
# Get the boxed StopAsyncIteration object |
| 56 |
stop_async_iteration_op = load_global_op( |
| 57 |
name="builtins.StopAsyncIteration", type=object_rprimitive, src="PyExc_StopAsyncIteration" |
| 58 |
) |
| 59 |
|
| 60 |
# id(obj) |
| 61 |
function_op( |
| 62 |
name="builtins.id", |
| 63 |
arg_types=[object_rprimitive], |
| 64 |
return_type=int_rprimitive, |
| 65 |
c_function_name="CPyTagged_Id", |
| 66 |
error_kind=ERR_NEVER, |
| 67 |
) |
| 68 |
|
| 69 |
# Return the result of obj.__await()__ or obj.__iter__() (if no __await__ exists) |
| 70 |
coro_op = custom_op( |
| 71 |
arg_types=[object_rprimitive], |
| 72 |
return_type=object_rprimitive, |
| 73 |
c_function_name="CPy_GetCoro", |
| 74 |
error_kind=ERR_MAGIC, |
| 75 |
) |
| 76 |
|
| 77 |
# Do obj.send(value), or a next(obj) if second arg is None. |
| 78 |
# (This behavior is to match the PEP 380 spec for yield from.) |
| 79 |
# Like next_raw_op, don't swallow StopIteration, |
| 80 |
# but also don't propagate an error. |
| 81 |
# Can return NULL: see next_op. |
| 82 |
send_op = custom_op( |
| 83 |
arg_types=[object_rprimitive, object_rprimitive], |
| 84 |
return_type=object_rprimitive, |
| 85 |
c_function_name="CPyIter_Send", |
| 86 |
error_kind=ERR_NEVER, |
| 87 |
) |
| 88 |
|
| 89 |
# This is sort of unfortunate but oh well: yield_from_except performs most of the |
| 90 |
# error handling logic in `yield from` operations. It returns a bool and passes |
| 91 |
# a value by address. |
| 92 |
# If the bool is true, then a StopIteration was received and we should return. |
| 93 |
# If the bool is false, then the value should be yielded. |
| 94 |
# The normal case is probably that it signals an exception, which gets |
| 95 |
# propagated. |
| 96 |
# Op used for "yield from" error handling. |
| 97 |
# See comment in CPy_YieldFromErrorHandle for more information. |
| 98 |
yield_from_except_op = custom_op( |
| 99 |
arg_types=[object_rprimitive, object_pointer_rprimitive], |
| 100 |
return_type=bool_rprimitive, |
| 101 |
c_function_name="CPy_YieldFromErrorHandle", |
| 102 |
error_kind=ERR_MAGIC, |
| 103 |
) |
| 104 |
|
| 105 |
# Create method object from a callable object and self. |
| 106 |
method_new_op = custom_op( |
| 107 |
arg_types=[object_rprimitive, object_rprimitive], |
| 108 |
return_type=object_rprimitive, |
| 109 |
c_function_name="PyMethod_New", |
| 110 |
error_kind=ERR_MAGIC, |
| 111 |
) |
| 112 |
|
| 113 |
# Check if the current exception is a StopIteration and return its value if so. |
| 114 |
# Treats "no exception" as StopIteration with a None value. |
| 115 |
# If it is a different exception, re-reraise it. |
| 116 |
check_stop_op = custom_op( |
| 117 |
arg_types=[], |
| 118 |
return_type=object_rprimitive, |
| 119 |
c_function_name="CPy_FetchStopIterationValue", |
| 120 |
error_kind=ERR_MAGIC, |
| 121 |
) |
| 122 |
|
| 123 |
# Determine the most derived metaclass and check for metaclass conflicts. |
| 124 |
# Arguments are (metaclass, bases). |
| 125 |
py_calc_meta_op = custom_op( |
| 126 |
arg_types=[object_rprimitive, object_rprimitive], |
| 127 |
return_type=object_rprimitive, |
| 128 |
c_function_name="CPy_CalculateMetaclass", |
| 129 |
error_kind=ERR_MAGIC, |
| 130 |
is_borrowed=True, |
| 131 |
) |
| 132 |
|
| 133 |
# Import a module using the Python import system. |
| 134 |
import_op = custom_op( |
| 135 |
arg_types=[str_rprimitive], |
| 136 |
return_type=object_rprimitive, |
| 137 |
c_function_name="PyImport_Import", |
| 138 |
error_kind=ERR_MAGIC, |
| 139 |
) |
| 140 |
|
| 141 |
# Import a native same-group module directly via C-level init/exec functions. |
| 142 |
native_import_op = custom_op( |
| 143 |
# (module name, init-only function, exec function, module static, |
| 144 |
# shared lib __file__, ext suffix, is_package) |
| 145 |
arg_types=[ |
| 146 |
str_rprimitive, |
| 147 |
c_pointer_rprimitive, |
| 148 |
c_pointer_rprimitive, |
| 149 |
object_pointer_rprimitive, |
| 150 |
object_rprimitive, |
| 151 |
str_rprimitive, |
| 152 |
c_pyssize_t_rprimitive, |
| 153 |
], |
| 154 |
return_type=object_rprimitive, |
| 155 |
c_function_name="CPyImport_ImportNative", |
| 156 |
error_kind=ERR_MAGIC, |
| 157 |
) |
| 158 |
|
| 159 |
# Table-driven import op. |
| 160 |
import_many_op = custom_op( |
| 161 |
arg_types=[ |
| 162 |
object_rprimitive, |
| 163 |
c_pointer_rprimitive, |
| 164 |
object_rprimitive, |
| 165 |
object_rprimitive, |
| 166 |
object_rprimitive, |
| 167 |
c_pointer_rprimitive, |
| 168 |
], |
| 169 |
return_type=bit_rprimitive, |
| 170 |
c_function_name="CPyImport_ImportMany", |
| 171 |
error_kind=ERR_FALSE, |
| 172 |
) |
| 173 |
|
| 174 |
# From import helper op |
| 175 |
import_from_many_op = custom_op( |
| 176 |
arg_types=[object_rprimitive, object_rprimitive, object_rprimitive, object_rprimitive], |
| 177 |
return_type=object_rprimitive, |
| 178 |
c_function_name="CPyImport_ImportFromMany", |
| 179 |
error_kind=ERR_MAGIC, |
| 180 |
) |
| 181 |
|
| 182 |
# Get attributes from an already-imported native module and store them in globals. |
| 183 |
get_native_attrs_op = custom_op( |
| 184 |
arg_types=[object_rprimitive, object_rprimitive, object_rprimitive, object_rprimitive], |
| 185 |
return_type=object_rprimitive, |
| 186 |
c_function_name="CPyImport_GetNativeAttrs", |
| 187 |
error_kind=ERR_MAGIC, |
| 188 |
) |
| 189 |
|
| 190 |
# Get the sys.modules dictionary |
| 191 |
get_module_dict_op = custom_op( |
| 192 |
arg_types=[], |
| 193 |
return_type=dict_rprimitive, |
| 194 |
c_function_name="PyImport_GetModuleDict", |
| 195 |
error_kind=ERR_NEVER, |
| 196 |
is_borrowed=True, |
| 197 |
) |
| 198 |
|
| 199 |
# isinstance(obj, cls) |
| 200 |
slow_isinstance_op = function_op( |
| 201 |
name="builtins.isinstance", |
| 202 |
arg_types=[object_rprimitive, object_rprimitive], |
| 203 |
return_type=c_int_rprimitive, |
| 204 |
c_function_name="PyObject_IsInstance", |
| 205 |
error_kind=ERR_NEG_INT, |
| 206 |
truncated_type=bool_rprimitive, |
| 207 |
) |
| 208 |
|
| 209 |
# Faster isinstance(obj, cls) that only works with native classes and doesn't perform |
| 210 |
# type checking of the type argument. |
| 211 |
fast_isinstance_op = function_op( |
| 212 |
"builtins.isinstance", |
| 213 |
arg_types=[object_rprimitive, object_rprimitive], |
| 214 |
return_type=bool_rprimitive, |
| 215 |
c_function_name="CPy_TypeCheck", |
| 216 |
error_kind=ERR_NEVER, |
| 217 |
priority=0, |
| 218 |
) |
| 219 |
|
| 220 |
# bool(obj) with unboxed result |
| 221 |
bool_op = function_op( |
| 222 |
name="builtins.bool", |
| 223 |
arg_types=[object_rprimitive], |
| 224 |
return_type=c_int_rprimitive, |
| 225 |
c_function_name="PyObject_IsTrue", |
| 226 |
error_kind=ERR_NEG_INT, |
| 227 |
truncated_type=bool_rprimitive, |
| 228 |
) |
| 229 |
|
| 230 |
# isinstance(obj, bool) |
| 231 |
isinstance_bool = function_op( |
| 232 |
name="builtins.isinstance", |
| 233 |
arg_types=[object_rprimitive], |
| 234 |
return_type=bit_rprimitive, |
| 235 |
c_function_name="PyBool_Check", |
| 236 |
error_kind=ERR_NEVER, |
| 237 |
) |
| 238 |
|
| 239 |
# slice(start, stop, step) |
| 240 |
new_slice_op = function_op( |
| 241 |
name="builtins.slice", |
| 242 |
arg_types=[object_rprimitive, object_rprimitive, object_rprimitive], |
| 243 |
c_function_name="PySlice_New", |
| 244 |
return_type=object_rprimitive, |
| 245 |
error_kind=ERR_MAGIC, |
| 246 |
) |
| 247 |
|
| 248 |
# type(obj) |
| 249 |
type_op = function_op( |
| 250 |
name="builtins.type", |
| 251 |
arg_types=[object_rprimitive], |
| 252 |
c_function_name="CPy_TYPE", |
| 253 |
return_type=object_rprimitive, |
| 254 |
error_kind=ERR_NEVER, |
| 255 |
) |
| 256 |
|
| 257 |
# Get 'builtins.type' (base class of all classes) |
| 258 |
type_object_op = load_address_op(name="builtins.type", type=object_rprimitive, src="PyType_Type") |
| 259 |
|
| 260 |
# Create a heap type based on a template non-heap type. |
| 261 |
# See CPyType_FromTemplate for more docs. |
| 262 |
pytype_from_template_op = custom_op( |
| 263 |
arg_types=[object_rprimitive, object_rprimitive, str_rprimitive], |
| 264 |
return_type=object_rprimitive, |
| 265 |
c_function_name="CPyType_FromTemplate", |
| 266 |
error_kind=ERR_MAGIC, |
| 267 |
) |
| 268 |
|
| 269 |
# Call __init_subclass__ on a type. Separated from CPyType_FromTemplate |
| 270 |
# so that class attributes can be set before __init_subclass__ is called. |
| 271 |
py_init_subclass_op = custom_op( |
| 272 |
arg_types=[object_rprimitive], |
| 273 |
return_type=bool_rprimitive, |
| 274 |
c_function_name="CPy_InitSubclass", |
| 275 |
error_kind=ERR_FALSE, |
| 276 |
) |
| 277 |
|
| 278 |
# Create a dataclass from an extension class. See |
| 279 |
# CPyDataclass_SleightOfHand for more docs. |
| 280 |
dataclass_sleight_of_hand = custom_op( |
| 281 |
arg_types=[ |
| 282 |
object_rprimitive, |
| 283 |
object_rprimitive, |
| 284 |
dict_rprimitive, |
| 285 |
dict_rprimitive, |
| 286 |
str_rprimitive, |
| 287 |
], |
| 288 |
return_type=bit_rprimitive, |
| 289 |
c_function_name="CPyDataclass_SleightOfHand", |
| 290 |
error_kind=ERR_FALSE, |
| 291 |
) |
| 292 |
|
| 293 |
# Raise ValueError if length of first argument is not equal to the second argument. |
| 294 |
# The first argument must be a list or a variable-length tuple. |
| 295 |
check_unpack_count_op = custom_op( |
| 296 |
arg_types=[object_rprimitive, c_pyssize_t_rprimitive], |
| 297 |
return_type=c_int_rprimitive, |
| 298 |
c_function_name="CPySequence_CheckUnpackCount", |
| 299 |
error_kind=ERR_NEG_INT, |
| 300 |
) |
| 301 |
|
| 302 |
|
| 303 |
# Register an implementation for a singledispatch function |
| 304 |
register_function = custom_op( |
| 305 |
arg_types=[object_rprimitive, object_rprimitive, object_rprimitive], |
| 306 |
return_type=object_rprimitive, |
| 307 |
c_function_name="CPySingledispatch_RegisterFunction", |
| 308 |
error_kind=ERR_MAGIC, |
| 309 |
) |
| 310 |
|
| 311 |
|
| 312 |
# Initialize a PyObject * item in a memory buffer (steal the value) |
| 313 |
buf_init_item = custom_primitive_op( |
| 314 |
name="buf_init_item", |
| 315 |
arg_types=[pointer_rprimitive, c_pyssize_t_rprimitive, object_rprimitive], |
| 316 |
return_type=void_rtype, |
| 317 |
error_kind=ERR_NEVER, |
| 318 |
steals=[False, False, True], |
| 319 |
) |
| 320 |
|
| 321 |
# Get length of PyVarObject instance (e.g. list or tuple) |
| 322 |
var_object_size = custom_primitive_op( |
| 323 |
name="var_object_size", |
| 324 |
arg_types=[object_rprimitive], |
| 325 |
return_type=c_pyssize_t_rprimitive, |
| 326 |
error_kind=ERR_NEVER, |
| 327 |
) |
| 328 |
|
| 329 |
# Set the lazy value compute function of an TypeAliasType instance (Python 3.12+). |
| 330 |
# This must only be used as part of initializing the object. Any existing value |
| 331 |
# will be cleared. |
| 332 |
set_type_alias_compute_function_op = custom_primitive_op( |
| 333 |
name="set_type_alias_compute_function", |
| 334 |
c_function_name="CPy_SetTypeAliasTypeComputeFunction", |
| 335 |
# (alias object, value compute function) |
| 336 |
arg_types=[object_rprimitive, object_rprimitive], |
| 337 |
return_type=void_rtype, |
| 338 |
error_kind=ERR_NEVER, |
| 339 |
) |
| 340 |
|
| 341 |
debug_print_op = custom_primitive_op( |
| 342 |
name="debug_print", |
| 343 |
c_function_name="CPyDebug_PrintObject", |
| 344 |
arg_types=[object_rprimitive], |
| 345 |
return_type=void_rtype, |
| 346 |
error_kind=ERR_NEVER, |
| 347 |
) |
| 348 |
|
| 349 |
# Log an event to a trace log, which is written to a file during execution. |
| 350 |
log_trace_event = custom_primitive_op( |
| 351 |
name="log_trace_event", |
| 352 |
c_function_name="CPyTrace_LogEvent", |
| 353 |
# (fullname of function/location, line number, operation name, operation details) |
| 354 |
arg_types=[cstring_rprimitive, cstring_rprimitive, cstring_rprimitive, cstring_rprimitive], |
| 355 |
return_type=void_rtype, |
| 356 |
error_kind=ERR_NEVER, |
| 357 |
) |
| 358 |
|
| 359 |
# Mark object as immortal -- it won't be freed via reference counting, as |
| 360 |
# the reference count won't be updated any longer. Immortal objects support |
| 361 |
# fast concurrent read-only access from multiple threads when using free |
| 362 |
# threading, since this eliminates contention from concurrent reference count |
| 363 |
# updates. |
| 364 |
# |
| 365 |
# Needs at least Python 3.14. |
| 366 |
set_immortal_op = custom_primitive_op( |
| 367 |
name="set_immmortal", |
| 368 |
c_function_name="CPy_SetImmortal", |
| 369 |
arg_types=[object_rprimitive], |
| 370 |
return_type=void_rtype, |
| 371 |
error_kind=ERR_NEVER, |
| 372 |
) |
| 373 |
|
| 374 |
write_buffer_rprimitive = KNOWN_NATIVE_TYPES["librt.internal.WriteBuffer"] |
| 375 |
read_buffer_rprimitive = KNOWN_NATIVE_TYPES["librt.internal.ReadBuffer"] |
| 376 |
|
| 377 |
# ReadBuffer(source) |
| 378 |
function_op( |
| 379 |
name="librt.internal.ReadBuffer", |
| 380 |
arg_types=[bytes_rprimitive], |
| 381 |
return_type=read_buffer_rprimitive, |
| 382 |
c_function_name="ReadBuffer_internal", |
| 383 |
error_kind=ERR_MAGIC, |
| 384 |
) |
| 385 |
|
| 386 |
# WriteBuffer() |
| 387 |
function_op( |
| 388 |
name="librt.internal.WriteBuffer", |
| 389 |
arg_types=[], |
| 390 |
return_type=write_buffer_rprimitive, |
| 391 |
c_function_name="WriteBuffer_internal", |
| 392 |
error_kind=ERR_MAGIC, |
| 393 |
) |
| 394 |
|
| 395 |
method_op( |
| 396 |
name="getvalue", |
| 397 |
arg_types=[write_buffer_rprimitive], |
| 398 |
return_type=bytes_rprimitive, |
| 399 |
c_function_name="WriteBuffer_getvalue_internal", |
| 400 |
error_kind=ERR_MAGIC, |
| 401 |
) |
| 402 |
|
| 403 |
function_op( |
| 404 |
name="librt.internal.write_bool", |
| 405 |
arg_types=[object_rprimitive, bool_rprimitive], |
| 406 |
return_type=none_rprimitive, |
| 407 |
c_function_name="write_bool_internal", |
| 408 |
error_kind=ERR_MAGIC, |
| 409 |
) |
| 410 |
|
| 411 |
function_op( |
| 412 |
name="librt.internal.read_bool", |
| 413 |
arg_types=[object_rprimitive], |
| 414 |
return_type=bool_rprimitive, |
| 415 |
c_function_name="read_bool_internal", |
| 416 |
error_kind=ERR_MAGIC, |
| 417 |
) |
| 418 |
|
| 419 |
function_op( |
| 420 |
name="librt.internal.write_str", |
| 421 |
arg_types=[object_rprimitive, str_rprimitive], |
| 422 |
return_type=none_rprimitive, |
| 423 |
c_function_name="write_str_internal", |
| 424 |
error_kind=ERR_MAGIC, |
| 425 |
) |
| 426 |
|
| 427 |
function_op( |
| 428 |
name="librt.internal.read_str", |
| 429 |
arg_types=[object_rprimitive], |
| 430 |
return_type=str_rprimitive, |
| 431 |
c_function_name="read_str_internal", |
| 432 |
error_kind=ERR_MAGIC, |
| 433 |
) |
| 434 |
|
| 435 |
function_op( |
| 436 |
name="librt.internal.write_bytes", |
| 437 |
arg_types=[object_rprimitive, bytes_rprimitive], |
| 438 |
return_type=none_rprimitive, |
| 439 |
c_function_name="write_bytes_internal", |
| 440 |
error_kind=ERR_MAGIC, |
| 441 |
) |
| 442 |
|
| 443 |
function_op( |
| 444 |
name="librt.internal.read_bytes", |
| 445 |
arg_types=[object_rprimitive], |
| 446 |
return_type=bytes_rprimitive, |
| 447 |
c_function_name="read_bytes_internal", |
| 448 |
error_kind=ERR_MAGIC, |
| 449 |
) |
| 450 |
|
| 451 |
function_op( |
| 452 |
name="librt.internal.write_float", |
| 453 |
arg_types=[object_rprimitive, float_rprimitive], |
| 454 |
return_type=none_rprimitive, |
| 455 |
c_function_name="write_float_internal", |
| 456 |
error_kind=ERR_MAGIC, |
| 457 |
) |
| 458 |
|
| 459 |
function_op( |
| 460 |
name="librt.internal.read_float", |
| 461 |
arg_types=[object_rprimitive], |
| 462 |
return_type=float_rprimitive, |
| 463 |
c_function_name="read_float_internal", |
| 464 |
error_kind=ERR_MAGIC_OVERLAPPING, |
| 465 |
) |
| 466 |
|
| 467 |
function_op( |
| 468 |
name="librt.internal.write_int", |
| 469 |
arg_types=[object_rprimitive, int_rprimitive], |
| 470 |
return_type=none_rprimitive, |
| 471 |
c_function_name="write_int_internal", |
| 472 |
error_kind=ERR_MAGIC, |
| 473 |
) |
| 474 |
|
| 475 |
function_op( |
| 476 |
name="librt.internal.read_int", |
| 477 |
arg_types=[object_rprimitive], |
| 478 |
return_type=int_rprimitive, |
| 479 |
c_function_name="read_int_internal", |
| 480 |
error_kind=ERR_MAGIC, |
| 481 |
) |
| 482 |
|
| 483 |
function_op( |
| 484 |
name="librt.internal.write_tag", |
| 485 |
arg_types=[object_rprimitive, uint8_rprimitive], |
| 486 |
return_type=none_rprimitive, |
| 487 |
c_function_name="write_tag_internal", |
| 488 |
error_kind=ERR_MAGIC, |
| 489 |
) |
| 490 |
|
| 491 |
function_op( |
| 492 |
name="librt.internal.read_tag", |
| 493 |
arg_types=[object_rprimitive], |
| 494 |
return_type=uint8_rprimitive, |
| 495 |
c_function_name="read_tag_internal", |
| 496 |
error_kind=ERR_MAGIC_OVERLAPPING, |
| 497 |
) |
| 498 |
|
| 499 |
function_op( |
| 500 |
name="librt.internal.cache_version", |
| 501 |
arg_types=[], |
| 502 |
return_type=uint8_rprimitive, |
| 503 |
c_function_name="cache_version_internal", |
| 504 |
error_kind=ERR_NEVER, |
| 505 |
) |
| 506 |
|
| 507 |
function_op( |
| 508 |
name="librt.internal.extract_symbol", |
| 509 |
arg_types=[object_rprimitive], |
| 510 |
return_type=bytes_rprimitive, |
| 511 |
c_function_name="extract_symbol_internal", |
| 512 |
error_kind=ERR_MAGIC, |
| 513 |
) |
| 514 |
|
| 515 |
function_op( |
| 516 |
name="librt.base64.b64encode", |
| 517 |
arg_types=[bytes_rprimitive], |
| 518 |
return_type=bytes_rprimitive, |
| 519 |
c_function_name="LibRTBase64_b64encode_internal", |
| 520 |
error_kind=ERR_MAGIC, |
| 521 |
extra_int_constants=[(0, bool_rprimitive)], |
| 522 |
experimental=True, |
| 523 |
dependencies=[LIBRT_BASE64], |
| 524 |
) |
| 525 |
|
| 526 |
function_op( |
| 527 |
name="librt.base64.urlsafe_b64encode", |
| 528 |
arg_types=[bytes_rprimitive], |
| 529 |
return_type=bytes_rprimitive, |
| 530 |
c_function_name="LibRTBase64_b64encode_internal", |
| 531 |
error_kind=ERR_MAGIC, |
| 532 |
extra_int_constants=[(1, bool_rprimitive)], |
| 533 |
experimental=True, |
| 534 |
dependencies=[LIBRT_BASE64], |
| 535 |
) |
| 536 |
|
| 537 |
function_op( |
| 538 |
name="librt.base64.b64decode", |
| 539 |
arg_types=[RUnion([bytes_rprimitive, str_rprimitive])], |
| 540 |
return_type=bytes_rprimitive, |
| 541 |
c_function_name="LibRTBase64_b64decode_internal", |
| 542 |
error_kind=ERR_MAGIC, |
| 543 |
extra_int_constants=[(0, bool_rprimitive)], |
| 544 |
experimental=True, |
| 545 |
dependencies=[LIBRT_BASE64], |
| 546 |
) |
| 547 |
|
| 548 |
function_op( |
| 549 |
name="librt.base64.urlsafe_b64decode", |
| 550 |
arg_types=[RUnion([bytes_rprimitive, str_rprimitive])], |
| 551 |
return_type=bytes_rprimitive, |
| 552 |
c_function_name="LibRTBase64_b64decode_internal", |
| 553 |
error_kind=ERR_MAGIC, |
| 554 |
extra_int_constants=[(1, bool_rprimitive)], |
| 555 |
experimental=True, |
| 556 |
dependencies=[LIBRT_BASE64], |
| 557 |
) |
| 558 |
|
| 559 |
cpyfunction_get_name = function_op( |
| 560 |
name="CPyFunction_get_name", |
| 561 |
arg_types=[object_rprimitive, c_pointer_rprimitive], |
| 562 |
return_type=object_rprimitive, |
| 563 |
c_function_name="CPyFunction_get_name", |
| 564 |
error_kind=ERR_MAGIC, |
| 565 |
) |
| 566 |
|
| 567 |
cpyfunction_set_name = function_op( |
| 568 |
name="CPyFunction_set_name", |
| 569 |
arg_types=[object_rprimitive, object_rprimitive, c_pointer_rprimitive], |
| 570 |
return_type=c_int_rprimitive, |
| 571 |
c_function_name="CPyFunction_set_name", |
| 572 |
error_kind=ERR_NEG_INT, |
| 573 |
) |
| 574 |
|
| 575 |
cpyfunction_get_code = function_op( |
| 576 |
name="CPyFunction_get_code", |
| 577 |
arg_types=[object_rprimitive, c_pointer_rprimitive], |
| 578 |
return_type=object_rprimitive, |
| 579 |
c_function_name="CPyFunction_get_code", |
| 580 |
error_kind=ERR_MAGIC, |
| 581 |
) |
| 582 |
|
| 583 |
cpyfunction_get_defaults = function_op( |
| 584 |
name="CPyFunction_get_defaults", |
| 585 |
arg_types=[object_rprimitive, c_pointer_rprimitive], |
| 586 |
return_type=object_rprimitive, |
| 587 |
c_function_name="CPyFunction_get_defaults", |
| 588 |
error_kind=ERR_MAGIC, |
| 589 |
) |
| 590 |
|
| 591 |
cpyfunction_get_kwdefaults = function_op( |
| 592 |
name="CPyFunction_get_kwdefaults", |
| 593 |
arg_types=[object_rprimitive, c_pointer_rprimitive], |
| 594 |
return_type=object_rprimitive, |
| 595 |
c_function_name="CPyFunction_get_kwdefaults", |
| 596 |
error_kind=ERR_MAGIC, |
| 597 |
) |
| 598 |
|
| 599 |
cpyfunction_get_annotations = function_op( |
| 600 |
name="CPyFunction_get_annotations", |
| 601 |
arg_types=[object_rprimitive, c_pointer_rprimitive], |
| 602 |
return_type=object_rprimitive, |
| 603 |
c_function_name="CPyFunction_get_annotations", |
| 604 |
error_kind=ERR_MAGIC, |
| 605 |
) |
| 606 |
|
| 607 |
cpyfunction_set_annotations = function_op( |
| 608 |
name="CPyFunction_set_annotations", |
| 609 |
arg_types=[object_rprimitive, object_rprimitive, c_pointer_rprimitive], |
| 610 |
return_type=c_int_rprimitive, |
| 611 |
c_function_name="CPyFunction_set_annotations", |
| 612 |
error_kind=ERR_NEG_INT, |
| 613 |
) |