mirror of
https://github.com/pocketpy/pocketpy
synced 2026-03-22 05:00:17 +00:00
Compare commits
No commits in common. "a2f16e5f1f5fcc3b3d2cc1bdacfc3a027dfe2d76" and "cf70668a2f4ea9984f0d6bddbe89eb39e01e5dcf" have entirely different histories.
a2f16e5f1f
...
cf70668a2f
@ -1530,9 +1530,9 @@ class PocketpyBindings {
|
||||
ffi.NativeFunction<
|
||||
ffi.Bool Function(py_Ref self, py_Name name)>>)>();
|
||||
|
||||
/// Get the current `Callable` object on the stack of the most recent vectorcall.
|
||||
/// Get the current `function` object on the stack.
|
||||
/// Return `NULL` if not available.
|
||||
/// NOTE: This function should be placed at the beginning of your bindings or you will get wrong result.
|
||||
/// NOTE: This function should be placed at the beginning of your decl-based bindings.
|
||||
py_StackRef py_inspect_currentfunction() {
|
||||
return _py_inspect_currentfunction();
|
||||
}
|
||||
@ -3635,22 +3635,6 @@ class PocketpyBindings {
|
||||
late final _py_newvec3i =
|
||||
_py_newvec3iPtr.asFunction<void Function(py_OutRef, c11_vec3i)>();
|
||||
|
||||
void py_newvec4i(
|
||||
py_OutRef out,
|
||||
c11_vec4i arg1,
|
||||
) {
|
||||
return _py_newvec4i(
|
||||
out,
|
||||
arg1,
|
||||
);
|
||||
}
|
||||
|
||||
late final _py_newvec4iPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef, c11_vec4i)>>(
|
||||
'py_newvec4i');
|
||||
late final _py_newvec4i =
|
||||
_py_newvec4iPtr.asFunction<void Function(py_OutRef, c11_vec4i)>();
|
||||
|
||||
void py_newcolor32(
|
||||
py_OutRef out,
|
||||
c11_color32 arg1,
|
||||
@ -3731,19 +3715,6 @@ class PocketpyBindings {
|
||||
late final _py_tovec3i =
|
||||
_py_tovec3iPtr.asFunction<c11_vec3i Function(py_Ref)>();
|
||||
|
||||
c11_vec4i py_tovec4i(
|
||||
py_Ref self,
|
||||
) {
|
||||
return _py_tovec4i(
|
||||
self,
|
||||
);
|
||||
}
|
||||
|
||||
late final _py_tovec4iPtr =
|
||||
_lookup<ffi.NativeFunction<c11_vec4i Function(py_Ref)>>('py_tovec4i');
|
||||
late final _py_tovec4i =
|
||||
_py_tovec4iPtr.asFunction<c11_vec4i Function(py_Ref)>();
|
||||
|
||||
ffi.Pointer<c11_mat3x3> py_tomat3x3(
|
||||
py_Ref self,
|
||||
) {
|
||||
@ -3961,32 +3932,10 @@ final class UnnamedUnion1 extends ffi.Union {
|
||||
@ffi.Int64()
|
||||
external int _i64;
|
||||
|
||||
@ffi.Double()
|
||||
external double _f64;
|
||||
|
||||
@ffi.Bool()
|
||||
external bool _bool;
|
||||
|
||||
external py_CFunction _cfunc;
|
||||
|
||||
external ffi.Pointer<ffi.Void> _obj;
|
||||
|
||||
external ffi.Pointer<ffi.Void> _ptr;
|
||||
|
||||
@ffi.Array.multi([16])
|
||||
external ffi.Array<ffi.Char> _chars;
|
||||
}
|
||||
|
||||
/// Native function signature.
|
||||
/// @param argc number of arguments.
|
||||
/// @param argv array of arguments. Use `py_arg(i)` macro to get the i-th argument.
|
||||
/// @return `true` if the function is successful or `false` if an exception is raised.
|
||||
typedef py_CFunction = ffi.Pointer<
|
||||
ffi.NativeFunction<ffi.Bool Function(ffi.Int argc, py_StackRef argv)>>;
|
||||
|
||||
/// A specific location in the value stack of the VM.
|
||||
typedef py_StackRef = ffi.Pointer<py_TValue>;
|
||||
|
||||
/// A string view type. It is helpful for passing strings which are not null-terminated.
|
||||
final class c11_sv extends ffi.Struct {
|
||||
external ffi.Pointer<ffi.Char> data;
|
||||
@ -4078,12 +4027,22 @@ typedef py_TraceFunc = ffi.Pointer<
|
||||
/// An output reference for returning a value. Only use this for function arguments.
|
||||
typedef py_OutRef = ffi.Pointer<py_TValue>;
|
||||
|
||||
/// A specific location in the value stack of the VM.
|
||||
typedef py_StackRef = ffi.Pointer<py_TValue>;
|
||||
|
||||
/// A 64-bit integer type. Corresponds to `int` in python.
|
||||
typedef py_i64 = ffi.Int64;
|
||||
|
||||
/// A 64-bit floating-point type. Corresponds to `float` in python.
|
||||
typedef py_f64 = ffi.Double;
|
||||
|
||||
/// Native function signature.
|
||||
/// @param argc number of arguments.
|
||||
/// @param argv array of arguments. Use `py_arg(i)` macro to get the i-th argument.
|
||||
/// @return `true` if the function is successful or `false` if an exception is raised.
|
||||
typedef py_CFunction = ffi.Pointer<
|
||||
ffi.NativeFunction<ffi.Bool Function(ffi.Int argc, py_StackRef argv)>>;
|
||||
|
||||
/// A pointer that represents a python identifier. For fast name resolution.
|
||||
typedef py_Name = ffi.Pointer<py_OpaqueName>;
|
||||
|
||||
@ -4166,29 +4125,8 @@ final class UnnamedStruct4 extends ffi.Struct {
|
||||
external int z;
|
||||
}
|
||||
|
||||
final class c11_vec4i extends ffi.Union {
|
||||
external UnnamedStruct5 unnamed;
|
||||
|
||||
@ffi.Array.multi([4])
|
||||
external ffi.Array<ffi.Int> data;
|
||||
}
|
||||
|
||||
final class UnnamedStruct5 extends ffi.Struct {
|
||||
@ffi.Int()
|
||||
external int x;
|
||||
|
||||
@ffi.Int()
|
||||
external int y;
|
||||
|
||||
@ffi.Int()
|
||||
external int z;
|
||||
|
||||
@ffi.Int()
|
||||
external int w;
|
||||
}
|
||||
|
||||
final class c11_color32 extends ffi.Union {
|
||||
external UnnamedStruct6 unnamed;
|
||||
external UnnamedStruct5 unnamed;
|
||||
|
||||
@ffi.Array.multi([4])
|
||||
external ffi.Array<ffi.UnsignedChar> data;
|
||||
@ -4197,7 +4135,7 @@ final class c11_color32 extends ffi.Union {
|
||||
external int u32;
|
||||
}
|
||||
|
||||
final class UnnamedStruct6 extends ffi.Struct {
|
||||
final class UnnamedStruct5 extends ffi.Struct {
|
||||
@ffi.UnsignedChar()
|
||||
external int r;
|
||||
|
||||
@ -4212,7 +4150,7 @@ final class UnnamedStruct6 extends ffi.Struct {
|
||||
}
|
||||
|
||||
final class c11_mat3x3 extends ffi.Union {
|
||||
external UnnamedStruct7 unnamed;
|
||||
external UnnamedStruct6 unnamed;
|
||||
|
||||
@ffi.Array.multi([3, 3])
|
||||
external ffi.Array<ffi.Array<ffi.Float>> m;
|
||||
@ -4221,7 +4159,7 @@ final class c11_mat3x3 extends ffi.Union {
|
||||
external ffi.Array<ffi.Float> data;
|
||||
}
|
||||
|
||||
final class UnnamedStruct7 extends ffi.Struct {
|
||||
final class UnnamedStruct6 extends ffi.Struct {
|
||||
@ffi.Float()
|
||||
external double _11;
|
||||
|
||||
@ -4368,14 +4306,13 @@ abstract class py_PredefinedType {
|
||||
static const int tp_vec3 = 71;
|
||||
static const int tp_vec2i = 72;
|
||||
static const int tp_vec3i = 73;
|
||||
static const int tp_vec4i = 74;
|
||||
static const int tp_mat3x3 = 75;
|
||||
static const int tp_color32 = 76;
|
||||
static const int tp_mat3x3 = 74;
|
||||
static const int tp_color32 = 75;
|
||||
|
||||
/// array2d
|
||||
static const int tp_array2d_like = 77;
|
||||
static const int tp_array2d_like_iterator = 78;
|
||||
static const int tp_array2d = 79;
|
||||
static const int tp_array2d_view = 80;
|
||||
static const int tp_chunked_array2d = 81;
|
||||
static const int tp_array2d_like = 76;
|
||||
static const int tp_array2d_like_iterator = 77;
|
||||
static const int tp_array2d = 78;
|
||||
static const int tp_array2d_view = 79;
|
||||
static const int tp_chunked_array2d = 80;
|
||||
}
|
||||
|
||||
@ -134,10 +134,10 @@ def atan(z: complex):
|
||||
return 1j / 2 * log((1 - 1j * z) / (1 + 1j * z))
|
||||
|
||||
def cos(z: complex):
|
||||
return (exp(1j * z) + exp(-1j * z)) / 2
|
||||
return (exp(z) + exp(-z)) / 2
|
||||
|
||||
def sin(z: complex):
|
||||
return (exp(1j * z) - exp(-1j * z)) / (2 * 1j)
|
||||
return (exp(z) - exp(-z)) / (2 * 1j)
|
||||
|
||||
def tan(z: complex):
|
||||
return sin(z) / cos(z)
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -10,8 +10,6 @@
|
||||
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
typedef bool (*py_module_initialize_t)() PY_RAISE PY_RETURN;
|
||||
@ -23,44 +21,14 @@ int load_module_from_dll_desktop_only(const char* path) PY_RAISE PY_RETURN {
|
||||
if(dll == NULL) return 0;
|
||||
py_module_initialize_t f_init = (py_module_initialize_t)GetProcAddress(dll, f_init_name);
|
||||
#else
|
||||
void* dll = NULL;
|
||||
// On Linux, dlopen doesn't automatically add .so suffix like Windows does with .dll
|
||||
// Also, CMake typically generates libXxx.so instead of Xxx.so
|
||||
// Try: path.so, libpath.so, then the original path
|
||||
char* path_with_so = NULL;
|
||||
char* path_with_lib = NULL;
|
||||
size_t path_len = strlen(path);
|
||||
|
||||
// Try path.so
|
||||
path_with_so = py_malloc(path_len + 4); // .so + null terminator
|
||||
if(path_with_so != NULL) {
|
||||
strcpy(path_with_so, path);
|
||||
strcat(path_with_so, ".so");
|
||||
dll = dlopen(path_with_so, RTLD_LAZY);
|
||||
py_free(path_with_so);
|
||||
}
|
||||
|
||||
// Try libpath.so if path.so didn't work
|
||||
if(dll == NULL) {
|
||||
path_with_lib = py_malloc(path_len + 7); // lib + .so + null terminator
|
||||
if(path_with_lib != NULL) {
|
||||
strcpy(path_with_lib, "lib");
|
||||
strcat(path_with_lib, path);
|
||||
strcat(path_with_lib, ".so");
|
||||
dll = dlopen(path_with_lib, RTLD_LAZY);
|
||||
py_free(path_with_lib);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to original path
|
||||
if(dll == NULL) {
|
||||
dll = dlopen(path, RTLD_LAZY);
|
||||
}
|
||||
|
||||
void* dll = dlopen(path, RTLD_LAZY);
|
||||
if(dll == NULL) return 0;
|
||||
py_module_initialize_t f_init = (py_module_initialize_t)dlsym(dll, f_init_name);
|
||||
#endif
|
||||
if(f_init == NULL) return 0;
|
||||
if(f_init == NULL) {
|
||||
RuntimeError("%s() not found in '%s'", f_init_name, path);
|
||||
return -1;
|
||||
}
|
||||
bool success = f_init();
|
||||
if(!success) return -1;
|
||||
return 1;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user