I try to load python3.dll and python3XX.dll explicitly.
Wrapper works for functions but import variable as PyBool_Type seems to not work (or I miss something)
Here part of code
PyBool_Check(obj) returns always false
Did you try using the boolType pointer directly, rather than implicitly copying the PyTypeObject and referencing the copy? I wouldn’t be surprised if Py_IS_TYPE is implemented in terms of the pointer address. (Also, I don’t see a PyBool_FromLongPtr in the API, and you’re apparently passing a number, not a pointer. Shouldn’t that be PyBool_FromLong?) (Also, since you have “Nelson” in your username, I assume that Nelson::get_function is your own code in your own namespace. How should we be able to verify what it does?)
Yep, I agree, that’s ugly. But since you’re not really working inside the same system anyway, it’s not really necessary to bind yourself to the same #define-based API. What you really want is to simply define PyBool_Check in a correct way for your situation. (I’m a tad confused by PyBool_FromLongPtr, since that function doesn’t exist, only PyBool_FromLong - there’s no way that I’m aware of to construct a bool from a pointer. Anyhow.) So I’d be inclined to replace PyBool_Check with an actual inline function, or possibly just call PyObject_IsInstance directly (since that’s part of the Stable ABI). If you really truly need the performance, an inline PyBool_Check that does a simple pointer comparison between Py_TYPE(obj) and the saved pointer to the bool type should suffice.