Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions mypyc/lib-rt/librt_base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,20 @@ static PyMethodDef librt_base64_module_methods[] = {
{NULL, NULL, 0, NULL}
};

#ifdef MYPYC_EXPERIMENTAL

static int
base64_abi_version(void) {
return 0;
return LIBRT_BASE64_ABI_VERSION;
}

static int
base64_api_version(void) {
return 0;
return LIBRT_BASE64_API_VERSION;
Comment on lines +266 to +271
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you'll have to wrap these in #ifdef MYPYC_EXPERIMENTAL

}

#endif

static int
librt_base64_module_exec(PyObject *m)
{
Expand All @@ -278,6 +282,7 @@ librt_base64_module_exec(PyObject *m)
(void *)base64_abi_version,
(void *)base64_api_version,
(void *)b64encode_internal,
(void *)b64decode_internal,
};
PyObject *c_api_object = PyCapsule_New((void *)base64_api, "librt.base64._C_API", NULL);
if (PyModule_Add(m, "_C_API", c_api_object) < 0) {
Expand Down
5 changes: 3 additions & 2 deletions mypyc/lib-rt/librt_base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import_librt_base64(void)
#else // MYPYC_EXPERIMENTAL

#define LIBRT_BASE64_ABI_VERSION 0
#define LIBRT_BASE64_API_VERSION 0
#define LIBRT_BASE64_API_LEN 3
#define LIBRT_BASE64_API_VERSION 1
#define LIBRT_BASE64_API_LEN 4

static void *LibRTBase64_API[LIBRT_BASE64_API_LEN];

#define LibRTBase64_ABIVersion (*(int (*)(void)) LibRTBase64_API[0])
#define LibRTBase64_APIVersion (*(int (*)(void)) LibRTBase64_API[1])
#define LibRTBase64_b64encode_internal (*(PyObject* (*)(PyObject *source)) LibRTBase64_API[2])
#define LibRTBase64_b64decode_internal (*(PyObject* (*)(PyObject *source)) LibRTBase64_API[3])

static int
import_librt_base64(void)
Expand Down
11 changes: 11 additions & 0 deletions mypyc/primitives/misc_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from mypyc.ir.ops import ERR_FALSE, ERR_MAGIC, ERR_MAGIC_OVERLAPPING, ERR_NEVER
from mypyc.ir.rtypes import (
KNOWN_NATIVE_TYPES,
RUnion,
bit_rprimitive,
bool_rprimitive,
bytes_rprimitive,
Expand Down Expand Up @@ -475,3 +476,13 @@
experimental=True,
capsule="librt.base64",
)

function_op(
name="librt.base64.b64decode",
arg_types=[RUnion([bytes_rprimitive, str_rprimitive])],
return_type=bytes_rprimitive,
c_function_name="LibRTBase64_b64decode_internal",
error_kind=ERR_MAGIC,
experimental=True,
capsule="librt.base64",
)
19 changes: 18 additions & 1 deletion mypyc/test-data/irbuild-base64.test
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
[case testBase64_experimental]
from librt.base64 import b64encode
from librt.base64 import b64encode, b64decode

def enc(b: bytes) -> bytes:
return b64encode(b)

def dec_bytes(b: bytes) -> bytes:
return b64decode(b)

def dec_str(b: str) -> bytes:
return b64decode(b)
[out]
def enc(b):
b, r0 :: bytes
L0:
r0 = LibRTBase64_b64encode_internal(b)
return r0
def dec_bytes(b):
b, r0 :: bytes
L0:
r0 = LibRTBase64_b64decode_internal(b)
return r0
def dec_str(b):
b :: str
r0 :: bytes
L0:
r0 = LibRTBase64_b64decode_internal(b)
return r0

[case testBase64ExperimentalDisabled]
from librt.base64 import b64encode
Expand Down