Skip to content
Open
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
2 changes: 1 addition & 1 deletion mypyc/lib-rt/base64/librt_base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define LIBRT_BASE64_API_VERSION 2
#define LIBRT_BASE64_API_LEN 4

static void *LibRTBase64_API[LIBRT_BASE64_API_LEN];
extern void *LibRTBase64_API[LIBRT_BASE64_API_LEN];

#define LibRTBase64_ABIVersion (*(int (*)(void)) LibRTBase64_API[0])
#define LibRTBase64_APIVersion (*(int (*)(void)) LibRTBase64_API[1])
Expand Down
2 changes: 1 addition & 1 deletion mypyc/lib-rt/internal/librt_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static int NativeInternal_API_Version(void);

#else

static void *NativeInternal_API[LIBRT_INTERNAL_API_LEN];
extern void *NativeInternal_API[LIBRT_INTERNAL_API_LEN];

#define ReadBuffer_internal (*(PyObject* (*)(PyObject *source)) NativeInternal_API[0])
#define WriteBuffer_internal (*(PyObject* (*)(void)) NativeInternal_API[1])
Expand Down
25 changes: 25 additions & 0 deletions mypyc/lib-rt/static_data.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#ifndef STATIC_DATA
#define STATIC_DATA

#include "CPy.h"
#include "static_data.h"
#include "base64/librt_base64.h"
#include "internal/librt_internal.h"
#include "strings/librt_strings.h"
#include "time/librt_time.h"
#include "vecs/librt_vecs.h"

// Adopted from numpy 2.4.0: numpy/_core/src/multiarry/npy_static_data.c

Expand Down Expand Up @@ -72,4 +78,23 @@ intern_strings(void) {
return 0;
}

#ifdef MYPYC_EXPERIMENTAL

void *LibRTStrings_API[LIBRT_STRINGS_API_LEN] = {0};
void *LibRTTime_API[LIBRT_TIME_API_LEN] = {0};
VecCapsule *VecApi = NULL;
VecI64API VecI64Api = {0};
VecI32API VecI32Api = {0};
VecI16API VecI16Api = {0};
VecU8API VecU8Api = {0};
VecFloatAPI VecFloatApi = {0};
VecBoolAPI VecBoolApi = {0};
VecTAPI VecTApi = {0};
VecNestedAPI VecNestedApi = {0};

#endif // MYPYC_EXPERIMENTAL

void *LibRTBase64_API[LIBRT_BASE64_API_LEN] = {0};
void *NativeInternal_API[LIBRT_INTERNAL_API_LEN] = {0};

#endif
2 changes: 1 addition & 1 deletion mypyc/lib-rt/strings/librt_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import_librt_strings(void)
// LIBRT_STRINGS_API_VERSION.
#define LIBRT_STRINGS_API_LEN 14

static void *LibRTStrings_API[LIBRT_STRINGS_API_LEN];
extern void *LibRTStrings_API[LIBRT_STRINGS_API_LEN];

typedef struct {
PyObject_HEAD
Expand Down
2 changes: 1 addition & 1 deletion mypyc/lib-rt/time/librt_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import_librt_time(void)
#define LIBRT_TIME_API_VERSION 1
#define LIBRT_TIME_API_LEN 3

static void *LibRTTime_API[LIBRT_TIME_API_LEN];
extern void *LibRTTime_API[LIBRT_TIME_API_LEN];

#define LibRTTime_ABIVersion (*(int (*)(void)) LibRTTime_API[0])
#define LibRTTime_APIVersion (*(int (*)(void)) LibRTTime_API[1])
Expand Down
18 changes: 9 additions & 9 deletions mypyc/lib-rt/vecs/librt_vecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -847,15 +847,15 @@ PyObject *Vec_GenericPopWrapper(Py_ssize_t *len, PyObject **items, PyObject *arg
PyObject *Vec_GenericPop(Py_ssize_t *len, PyObject **items, Py_ssize_t index);

// Global API pointers initialized by import_librt_vecs()
static VecCapsule *VecApi;
static VecI64API VecI64Api;
static VecI32API VecI32Api;
static VecI16API VecI16Api;
static VecU8API VecU8Api;
static VecFloatAPI VecFloatApi;
static VecBoolAPI VecBoolApi;
static VecTAPI VecTApi;
static VecNestedAPI VecNestedApi;
extern VecCapsule *VecApi;
extern VecI64API VecI64Api;
extern VecI32API VecI32Api;
extern VecI16API VecI16Api;
extern VecU8API VecU8Api;
extern VecFloatAPI VecFloatApi;
extern VecBoolAPI VecBoolApi;
extern VecTAPI VecTApi;
extern VecNestedAPI VecNestedApi;

static int
import_librt_vecs(void)
Expand Down
20 changes: 20 additions & 0 deletions mypyc/test-data/run-multimodule.test
Original file line number Diff line number Diff line change
Expand Up @@ -1390,3 +1390,23 @@ class Parent:
[file driver.py]
from native import test
test()

[case testExtraOpsFunction_experimental_librt]
from librt.strings import BytesWriter

def call_write(b: bytes) -> bytes:
w = BytesWriter()
w.write(b) # calls CPyBytesWriter_Write defined in byteswriter_extra_ops.c
return w.getvalue()

[file other.py]
from native import call_write

def test(b: bytes) -> bytes:
return call_write(b)

[file driver.py]
from other import test

input = b'x' * 512
assert test(input) == input
Loading