__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
#ifndef GREENLET_EXCEPTIONS_HPP
#define GREENLET_EXCEPTIONS_HPP
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <stdexcept>
#include <string>
#ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunused-function"
#endif
namespace greenlet {
class PyErrOccurred : public std::runtime_error
{
public:
// CAUTION: In debug builds, may run arbitrary Python code.
static const PyErrOccurred
from_current()
{
assert(PyErr_Occurred());
#ifndef NDEBUG
// This is not exception safe, and
// not necessarily safe in general (what if it switches?)
// But we only do this in debug mode, where we are in
// tight control of what exceptions are getting raised and
// can prevent those issues.
// You can't call PyObject_Str with a pending exception.
PyObject* typ;
PyObject* val;
PyObject* tb;
PyErr_Fetch(&typ, &val, &tb);
PyObject* typs = PyObject_Str(typ);
PyObject* vals = PyObject_Str(val ? val : typ);
const char* typ_msg = PyUnicode_AsUTF8(typs);
const char* val_msg = PyUnicode_AsUTF8(vals);
PyErr_Restore(typ, val, tb);
std::string msg(typ_msg);
msg += ": ";
msg += val_msg;
PyErrOccurred ex(msg);
Py_XDECREF(typs);
Py_XDECREF(vals);
return ex;
#else
return PyErrOccurred();
#endif
}
PyErrOccurred() : std::runtime_error("")
{
assert(PyErr_Occurred());
}
PyErrOccurred(const std::string& msg) : std::runtime_error(msg)
{
assert(PyErr_Occurred());
}
PyErrOccurred(PyObject* exc_kind, const char* const msg)
: std::runtime_error(msg)
{
PyErr_SetString(exc_kind, msg);
}
PyErrOccurred(PyObject* exc_kind, const std::string msg)
: std::runtime_error(msg)
{
// This copies the c_str, so we don't have any lifetime
// issues to worry about.
PyErr_SetString(exc_kind, msg.c_str());
}
PyErrOccurred(PyObject* exc_kind,
const std::string msg, //This is the format
//string; that's not
//usually safe!
PyObject* borrowed_obj_one, PyObject* borrowed_obj_two)
: std::runtime_error(msg)
{
//This is designed specifically for the
//``check_switch_allowed`` function.
// PyObject_Str and PyObject_Repr are safe to call with
// NULL pointers; they return the string "<NULL>" in that
// case.
// This function always returns null.
PyErr_Format(exc_kind,
msg.c_str(),
borrowed_obj_one, borrowed_obj_two);
}
};
class TypeError : public PyErrOccurred
{
public:
TypeError(const char* const what)
: PyErrOccurred(PyExc_TypeError, what)
{
}
TypeError(const std::string what)
: PyErrOccurred(PyExc_TypeError, what)
{
}
};
class ValueError : public PyErrOccurred
{
public:
ValueError(const char* const what)
: PyErrOccurred(PyExc_ValueError, what)
{
}
};
class AttributeError : public PyErrOccurred
{
public:
AttributeError(const char* const what)
: PyErrOccurred(PyExc_AttributeError, what)
{
}
};
/**
* Calls `Py_FatalError` when constructed, so you can't actually
* throw this. It just makes static analysis easier.
*/
class PyFatalError : public std::runtime_error
{
public:
PyFatalError(const char* const msg)
: std::runtime_error(msg)
{
Py_FatalError(msg);
}
};
static inline PyObject*
Require(PyObject* p, const std::string& msg="")
{
if (!p) {
throw PyErrOccurred(msg);
}
return p;
};
static inline void
Require(const int retval)
{
if (retval < 0) {
throw PyErrOccurred();
}
};
};
#ifdef __clang__
# pragma clang diagnostic pop
#endif
#endif
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| platform | Folder | 0755 |
|
|
| tests | Folder | 0755 |
|
|
| CObjects.cpp | File | 3.57 KB | 0644 |
|
| PyGreenlet.cpp | File | 27.52 KB | 0644 |
|
| PyGreenlet.hpp | File | 1.43 KB | 0644 |
|
| PyGreenletUnswitchable.cpp | File | 4.06 KB | 0644 |
|
| PyModule.cpp | File | 8.59 KB | 0644 |
|
| TBrokenGreenlet.cpp | File | 1021 B | 0644 |
|
| TExceptionState.cpp | File | 1.33 KB | 0644 |
|
| TGreenlet.cpp | File | 25.62 KB | 0644 |
|
| TGreenlet.hpp | File | 28.58 KB | 0644 |
|
| TGreenletGlobals.cpp | File | 3.84 KB | 0644 |
|
| TMainGreenlet.cpp | File | 3.51 KB | 0644 |
|
| TPythonState.cpp | File | 19.15 KB | 0644 |
|
| TStackState.cpp | File | 7.21 KB | 0644 |
|
| TThreadState.hpp | File | 23.34 KB | 0644 |
|
| TThreadStateCreator.hpp | File | 2.7 KB | 0644 |
|
| TThreadStateDestroy.cpp | File | 7.99 KB | 0644 |
|
| TUserGreenlet.cpp | File | 23.76 KB | 0644 |
|
| __init__.py | File | 1.41 KB | 0644 |
|
| _greenlet.cpython-312-x86_64-linux-gnu.so | File | 1.32 MB | 0755 |
|
| greenlet.cpp | File | 10.83 KB | 0644 |
|
| greenlet.h | File | 4.64 KB | 0644 |
|
| greenlet_allocator.hpp | File | 1.79 KB | 0644 |
|
| greenlet_compiler_compat.hpp | File | 4.24 KB | 0644 |
|
| greenlet_cpython_compat.hpp | File | 3.25 KB | 0644 |
|
| greenlet_exceptions.hpp | File | 4.4 KB | 0644 |
|
| greenlet_internal.hpp | File | 2.7 KB | 0644 |
|
| greenlet_msvc_compat.hpp | File | 3.12 KB | 0644 |
|
| greenlet_refs.hpp | File | 37.17 KB | 0644 |
|
| greenlet_slp_switch.hpp | File | 3.22 KB | 0644 |
|
| greenlet_thread_support.hpp | File | 867 B | 0644 |
|
| slp_platformselect.h | File | 3.87 KB | 0644 |
|