Compare commits

..

1 Commits

10 changed files with 38 additions and 168 deletions

View File

@ -61,12 +61,6 @@ else()
add_definitions(-DPK_ENABLE_THREADS=0)
endif()
if(PK_ENABLE_DLL)
add_definitions(-DPK_ENABLE_DLL=1)
else()
add_definitions(-DPK_ENABLE_DLL=0)
endif()
if(PK_ENABLE_DETERMINISM)
add_definitions(-DPK_ENABLE_DETERMINISM=1)
else()
@ -160,7 +154,7 @@ if(PK_ENABLE_THREADS)
endif()
if(UNIX AND NOT APPLE)
if(PK_ENABLE_OS AND PK_ENABLE_DLL)
if(PK_ENABLE_OS)
target_link_libraries(${PROJECT_NAME} dl)
endif()
elseif(WIN32)

View File

@ -8,7 +8,6 @@ endif()
# system features
option(PK_ENABLE_OS "" ON)
option(PK_ENABLE_THREADS "" ON)
option(PK_ENABLE_DLL "" ON)
option(PK_ENABLE_DETERMINISM "" ON)
option(PK_ENABLE_WATCHDOG "" OFF)
option(PK_ENABLE_CUSTOM_SNAME "" OFF)

View File

@ -1,22 +1,18 @@
#pragma once
// clang-format off
#define PK_VERSION "2.1.9"
#define PK_VERSION "2.1.8"
#define PK_VERSION_MAJOR 2
#define PK_VERSION_MINOR 1
#define PK_VERSION_PATCH 9
#define PK_VERSION_PATCH 8
/*************** feature settings ***************/
#ifndef PK_ENABLE_OS // can be overridden by cmake
#define PK_ENABLE_OS 1
#endif
#ifndef PK_ENABLE_THREADS // must be enabled from cmake
#define PK_ENABLE_THREADS 0
#endif
#ifndef PK_ENABLE_DLL // must be enabled from cmake
#define PK_ENABLE_DLL 0
#ifndef PK_ENABLE_THREADS // can be overridden by cmake
#define PK_ENABLE_THREADS 1
#endif
#ifndef PK_ENABLE_DETERMINISM // must be enabled from cmake

View File

@ -70,7 +70,6 @@ args_proxy interface<Derived>::operator* () const {
template <typename Derived>
template <return_value_policy policy, typename... Args>
object interface<Derived>::operator() (Args&&... args) const {
py_StackRef p0 = py_peek(0); // checkpoint before pushing so py_clearexc can safely rewind
py_push(ptr());
py_pushnil();
@ -109,13 +108,7 @@ object interface<Derived>::operator() (Args&&... args) const {
(foreach(std::forward<Args>(args)), ...);
if(!py_vectorcall(argc, kwargsc)) {
py_matchexc(tp_Exception);
object e = object::from_ret();
auto what = py_formatexc();
py_clearexc(p0);
throw python_error(what, std::move(e));
}
raise_call<py_vectorcall>(argc, kwargsc);
return object::from_ret();
}

View File

@ -1,5 +1,3 @@
#pragma once
#include "pybind11.h"
#include <array>

View File

@ -79,18 +79,3 @@ TEST_F(PYBIND11_TEST, exception_cpp_to_python) {
TEST_EXCEPTION(attribute_error, AttributeError);
TEST_EXCEPTION(runtime_error, RuntimeError);
}
// Regression test: operator() must throw python_error instead of crashing when Python raises (#469)
TEST_F(PYBIND11_TEST, operator_call_propagates_python_error) {
py::exec("def f(x):\n raise ValueError('intentional error')");
py::object fn = py::eval("f");
bool caught = false;
try {
fn(py::int_(1));
} catch(py::python_error& e) {
caught = true;
EXPECT_TRUE(e.match(tp_ValueError));
}
EXPECT_TRUE(caught);
}

View File

@ -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;
}

View File

@ -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

View File

@ -1,6 +1,6 @@
#include "pocketpy/pocketpy.h"
#if PK_IS_DESKTOP_PLATFORM && PK_ENABLE_OS && PK_ENABLE_DLL
#if PK_IS_DESKTOP_PLATFORM && PK_ENABLE_OS
#ifdef _WIN32
@ -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;