index
int64
0
0
repo_id
stringclasses
596 values
file_path
stringlengths
31
168
content
stringlengths
1
6.2M
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/ceval.rs
use crate::cpython::pystate::Py_tracefunc; use crate::object::{freefunc, PyObject}; use std::os::raw::c_int; extern "C" { // skipped non-limited _PyEval_CallTracing #[cfg(not(Py_3_11))] pub fn _PyEval_EvalFrameDefault(arg1: *mut crate::PyFrameObject, exc: c_int) -> *mut PyObject; #[cfg(Py_3_11)] pub fn _PyEval_EvalFrameDefault( tstate: *mut crate::PyThreadState, frame: *mut crate::_PyInterpreterFrame, exc: c_int, ) -> *mut crate::PyObject; pub fn _PyEval_RequestCodeExtraIndex(func: freefunc) -> c_int; pub fn PyEval_SetProfile(trace_func: Option<Py_tracefunc>, arg1: *mut PyObject); pub fn PyEval_SetTrace(trace_func: Option<Py_tracefunc>, arg1: *mut PyObject); }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/bytesobject.rs
use crate::object::*; use crate::Py_ssize_t; #[cfg(not(any(PyPy, GraalPy, Py_LIMITED_API)))] use std::os::raw::c_char; use std::os::raw::c_int; #[cfg(not(any(PyPy, GraalPy, Py_LIMITED_API)))] #[repr(C)] pub struct PyBytesObject { pub ob_base: PyVarObject, #[cfg_attr( Py_3_11, deprecated(note = "Deprecated in Python 3.11 and will be removed in a future version.") )] pub ob_shash: crate::Py_hash_t, pub ob_sval: [c_char; 1], } #[cfg(any(PyPy, GraalPy, Py_LIMITED_API))] opaque_struct!(PyBytesObject); extern "C" { #[cfg_attr(PyPy, link_name = "_PyPyBytes_Resize")] pub fn _PyBytes_Resize(bytes: *mut *mut PyObject, newsize: Py_ssize_t) -> c_int; }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/compile.rs
#[cfg(not(any(PyPy, Py_3_10)))] use crate::object::PyObject; #[cfg(not(any(PyPy, Py_3_10)))] use crate::pyarena::*; #[cfg(not(any(PyPy, Py_3_10)))] use crate::pythonrun::*; #[cfg(not(any(PyPy, Py_3_10)))] use crate::PyCodeObject; #[cfg(not(any(PyPy, Py_3_10)))] use std::os::raw::c_char; use std::os::raw::c_int; // skipped non-limited PyCF_MASK // skipped non-limited PyCF_MASK_OBSOLETE // skipped non-limited PyCF_SOURCE_IS_UTF8 // skipped non-limited PyCF_DONT_IMPLY_DEDENT // skipped non-limited PyCF_ONLY_AST // skipped non-limited PyCF_IGNORE_COOKIE // skipped non-limited PyCF_TYPE_COMMENTS // skipped non-limited PyCF_ALLOW_TOP_LEVEL_AWAIT // skipped non-limited PyCF_COMPILE_MASK #[repr(C)] #[derive(Copy, Clone)] pub struct PyCompilerFlags { pub cf_flags: c_int, #[cfg(Py_3_8)] pub cf_feature_version: c_int, } // skipped non-limited _PyCompilerFlags_INIT #[cfg(all(Py_3_12, not(any(Py_3_13, PyPy, GraalPy))))] #[repr(C)] #[derive(Copy, Clone)] pub struct _PyCompilerSrcLocation { pub lineno: c_int, pub end_lineno: c_int, pub col_offset: c_int, pub end_col_offset: c_int, } // skipped SRC_LOCATION_FROM_AST #[cfg(not(any(PyPy, GraalPy, Py_3_13)))] #[repr(C)] #[derive(Copy, Clone)] pub struct PyFutureFeatures { pub ff_features: c_int, #[cfg(not(Py_3_12))] pub ff_lineno: c_int, #[cfg(Py_3_12)] pub ff_location: _PyCompilerSrcLocation, } pub const FUTURE_NESTED_SCOPES: &str = "nested_scopes"; pub const FUTURE_GENERATORS: &str = "generators"; pub const FUTURE_DIVISION: &str = "division"; pub const FUTURE_ABSOLUTE_IMPORT: &str = "absolute_import"; pub const FUTURE_WITH_STATEMENT: &str = "with_statement"; pub const FUTURE_PRINT_FUNCTION: &str = "print_function"; pub const FUTURE_UNICODE_LITERALS: &str = "unicode_literals"; pub const FUTURE_BARRY_AS_BDFL: &str = "barry_as_FLUFL"; pub const FUTURE_GENERATOR_STOP: &str = "generator_stop"; // skipped non-limited FUTURE_ANNOTATIONS extern "C" { #[cfg(not(any(PyPy, Py_3_10)))] pub fn PyNode_Compile(arg1: *mut _node, arg2: *const c_char) -> *mut PyCodeObject; #[cfg(not(any(PyPy, Py_3_10)))] pub fn PyAST_CompileEx( _mod: *mut _mod, filename: *const c_char, flags: *mut PyCompilerFlags, optimize: c_int, arena: *mut PyArena, ) -> *mut PyCodeObject; #[cfg(not(any(PyPy, Py_3_10)))] pub fn PyAST_CompileObject( _mod: *mut _mod, filename: *mut PyObject, flags: *mut PyCompilerFlags, optimize: c_int, arena: *mut PyArena, ) -> *mut PyCodeObject; #[cfg(not(any(PyPy, Py_3_10)))] pub fn PyFuture_FromAST(_mod: *mut _mod, filename: *const c_char) -> *mut PyFutureFeatures; #[cfg(not(any(PyPy, Py_3_10)))] pub fn PyFuture_FromASTObject( _mod: *mut _mod, filename: *mut PyObject, ) -> *mut PyFutureFeatures; // skipped non-limited _Py_Mangle // skipped non-limited PY_INVALID_STACK_EFFECT pub fn PyCompile_OpcodeStackEffect(opcode: c_int, oparg: c_int) -> c_int; #[cfg(Py_3_8)] pub fn PyCompile_OpcodeStackEffectWithJump(opcode: c_int, oparg: c_int, jump: c_int) -> c_int; // skipped non-limited _PyASTOptimizeState // skipped non-limited _PyAST_Optimize }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/initconfig.rs
/* --- PyStatus ----------------------------------------------- */ use crate::Py_ssize_t; use libc::wchar_t; use std::os::raw::{c_char, c_int, c_ulong}; #[repr(C)] #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum _PyStatus_TYPE { _PyStatus_TYPE_OK = 0, _PyStatus_TYPE_ERROR = 1, _PyStatus_TYPE_EXIT = 2, } #[repr(C)] #[derive(Copy, Clone)] pub struct PyStatus { pub _type: _PyStatus_TYPE, pub func: *const c_char, pub err_msg: *const c_char, pub exitcode: c_int, } extern "C" { pub fn PyStatus_Ok() -> PyStatus; pub fn PyStatus_Error(err_msg: *const c_char) -> PyStatus; pub fn PyStatus_NoMemory() -> PyStatus; pub fn PyStatus_Exit(exitcode: c_int) -> PyStatus; pub fn PyStatus_IsError(err: PyStatus) -> c_int; pub fn PyStatus_IsExit(err: PyStatus) -> c_int; pub fn PyStatus_Exception(err: PyStatus) -> c_int; } /* --- PyWideStringList ------------------------------------------------ */ #[repr(C)] #[derive(Copy, Clone)] pub struct PyWideStringList { pub length: Py_ssize_t, pub items: *mut *mut wchar_t, } extern "C" { pub fn PyWideStringList_Append(list: *mut PyWideStringList, item: *const wchar_t) -> PyStatus; pub fn PyWideStringList_Insert( list: *mut PyWideStringList, index: Py_ssize_t, item: *const wchar_t, ) -> PyStatus; } /* --- PyPreConfig ----------------------------------------------- */ #[repr(C)] #[derive(Copy, Clone)] pub struct PyPreConfig { pub _config_init: c_int, pub parse_argv: c_int, pub isolated: c_int, pub use_environment: c_int, pub configure_locale: c_int, pub coerce_c_locale: c_int, pub coerce_c_locale_warn: c_int, #[cfg(windows)] pub legacy_windows_fs_encoding: c_int, pub utf8_mode: c_int, pub dev_mode: c_int, pub allocator: c_int, } extern "C" { pub fn PyPreConfig_InitPythonConfig(config: *mut PyPreConfig); pub fn PyPreConfig_InitIsolatedConfig(config: *mut PyPreConfig); } /* --- PyConfig ---------------------------------------------- */ #[repr(C)] #[derive(Copy, Clone)] pub struct PyConfig { pub _config_init: c_int, pub isolated: c_int, pub use_environment: c_int, pub dev_mode: c_int, pub install_signal_handlers: c_int, pub use_hash_seed: c_int, pub hash_seed: c_ulong, pub faulthandler: c_int, #[cfg(all(Py_3_9, not(Py_3_10)))] pub _use_peg_parser: c_int, pub tracemalloc: c_int, #[cfg(Py_3_12)] pub perf_profiling: c_int, pub import_time: c_int, #[cfg(Py_3_11)] pub code_debug_ranges: c_int, pub show_ref_count: c_int, #[cfg(not(Py_3_9))] pub show_alloc_count: c_int, pub dump_refs: c_int, #[cfg(Py_3_11)] pub dump_refs_file: *mut wchar_t, pub malloc_stats: c_int, pub filesystem_encoding: *mut wchar_t, pub filesystem_errors: *mut wchar_t, pub pycache_prefix: *mut wchar_t, pub parse_argv: c_int, #[cfg(Py_3_10)] pub orig_argv: PyWideStringList, pub argv: PyWideStringList, #[cfg(not(Py_3_10))] pub program_name: *mut wchar_t, pub xoptions: PyWideStringList, pub warnoptions: PyWideStringList, pub site_import: c_int, pub bytes_warning: c_int, #[cfg(Py_3_10)] pub warn_default_encoding: c_int, pub inspect: c_int, pub interactive: c_int, pub optimization_level: c_int, pub parser_debug: c_int, pub write_bytecode: c_int, pub verbose: c_int, pub quiet: c_int, pub user_site_directory: c_int, pub configure_c_stdio: c_int, pub buffered_stdio: c_int, pub stdio_encoding: *mut wchar_t, pub stdio_errors: *mut wchar_t, #[cfg(windows)] pub legacy_windows_stdio: c_int, pub check_hash_pycs_mode: *mut wchar_t, #[cfg(Py_3_11)] pub use_frozen_modules: c_int, #[cfg(Py_3_11)] pub safe_path: c_int, #[cfg(Py_3_12)] pub int_max_str_digits: c_int, #[cfg(Py_3_13)] pub cpu_count: c_int, #[cfg(Py_GIL_DISABLED)] pub enable_gil: c_int, pub pathconfig_warnings: c_int, #[cfg(Py_3_10)] pub program_name: *mut wchar_t, pub pythonpath_env: *mut wchar_t, pub home: *mut wchar_t, #[cfg(Py_3_10)] pub platlibdir: *mut wchar_t, pub module_search_paths_set: c_int, pub module_search_paths: PyWideStringList, #[cfg(Py_3_11)] pub stdlib_dir: *mut wchar_t, pub executable: *mut wchar_t, pub base_executable: *mut wchar_t, pub prefix: *mut wchar_t, pub base_prefix: *mut wchar_t, pub exec_prefix: *mut wchar_t, pub base_exec_prefix: *mut wchar_t, #[cfg(all(Py_3_9, not(Py_3_10)))] pub platlibdir: *mut wchar_t, pub skip_source_first_line: c_int, pub run_command: *mut wchar_t, pub run_module: *mut wchar_t, pub run_filename: *mut wchar_t, #[cfg(Py_3_13)] pub sys_path_0: *mut wchar_t, pub _install_importlib: c_int, pub _init_main: c_int, #[cfg(all(Py_3_9, not(Py_3_12)))] pub _isolated_interpreter: c_int, #[cfg(Py_3_11)] pub _is_python_build: c_int, #[cfg(all(Py_3_9, not(Py_3_10)))] pub _orig_argv: PyWideStringList, #[cfg(all(Py_3_13, py_sys_config = "Py_DEBUG"))] pub run_presite: *mut wchar_t, } extern "C" { pub fn PyConfig_InitPythonConfig(config: *mut PyConfig); pub fn PyConfig_InitIsolatedConfig(config: *mut PyConfig); pub fn PyConfig_Clear(config: *mut PyConfig); pub fn PyConfig_SetString( config: *mut PyConfig, config_str: *mut *mut wchar_t, str: *const wchar_t, ) -> PyStatus; pub fn PyConfig_SetBytesString( config: *mut PyConfig, config_str: *mut *mut wchar_t, str: *const c_char, ) -> PyStatus; pub fn PyConfig_Read(config: *mut PyConfig) -> PyStatus; pub fn PyConfig_SetBytesArgv( config: *mut PyConfig, argc: Py_ssize_t, argv: *mut *const c_char, ) -> PyStatus; pub fn PyConfig_SetArgv( config: *mut PyConfig, argc: Py_ssize_t, argv: *mut *const wchar_t, ) -> PyStatus; pub fn PyConfig_SetWideStringList( config: *mut PyConfig, list: *mut PyWideStringList, length: Py_ssize_t, items: *mut *mut wchar_t, ) -> PyStatus; } /* --- Helper functions --------------------------------------- */ extern "C" { pub fn Py_GetArgcArgv(argc: *mut c_int, argv: *mut *mut *mut wchar_t); }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/frameobject.rs
#[cfg(not(GraalPy))] use crate::cpython::code::PyCodeObject; use crate::object::*; #[cfg(not(GraalPy))] use crate::pystate::PyThreadState; #[cfg(not(any(PyPy, GraalPy, Py_3_11)))] use std::os::raw::c_char; use std::os::raw::c_int; use std::ptr::addr_of_mut; #[cfg(not(any(PyPy, GraalPy, Py_3_11)))] pub type PyFrameState = c_char; #[repr(C)] #[derive(Copy, Clone)] #[cfg(not(any(PyPy, GraalPy, Py_3_11)))] pub struct PyTryBlock { pub b_type: c_int, pub b_handler: c_int, pub b_level: c_int, } #[repr(C)] #[cfg(not(any(PyPy, GraalPy, Py_3_11)))] pub struct PyFrameObject { pub ob_base: PyVarObject, pub f_back: *mut PyFrameObject, pub f_code: *mut PyCodeObject, pub f_builtins: *mut PyObject, pub f_globals: *mut PyObject, pub f_locals: *mut PyObject, pub f_valuestack: *mut *mut PyObject, #[cfg(not(Py_3_10))] pub f_stacktop: *mut *mut PyObject, pub f_trace: *mut PyObject, #[cfg(Py_3_10)] pub f_stackdepth: c_int, pub f_trace_lines: c_char, pub f_trace_opcodes: c_char, pub f_gen: *mut PyObject, pub f_lasti: c_int, pub f_lineno: c_int, pub f_iblock: c_int, #[cfg(not(Py_3_10))] pub f_executing: c_char, #[cfg(Py_3_10)] pub f_state: PyFrameState, pub f_blockstack: [PyTryBlock; crate::CO_MAXBLOCKS], pub f_localsplus: [*mut PyObject; 1], } #[cfg(any(PyPy, GraalPy, Py_3_11))] opaque_struct!(PyFrameObject); // skipped _PyFrame_IsRunnable // skipped _PyFrame_IsExecuting // skipped _PyFrameHasCompleted #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { pub static mut PyFrame_Type: PyTypeObject; } #[inline] pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == addr_of_mut!(PyFrame_Type)) as c_int } extern "C" { #[cfg(not(GraalPy))] #[cfg_attr(PyPy, link_name = "PyPyFrame_New")] pub fn PyFrame_New( tstate: *mut PyThreadState, code: *mut PyCodeObject, globals: *mut PyObject, locals: *mut PyObject, ) -> *mut PyFrameObject; // skipped _PyFrame_New_NoTrack pub fn PyFrame_BlockSetup(f: *mut PyFrameObject, _type: c_int, handler: c_int, level: c_int); #[cfg(not(any(PyPy, GraalPy, Py_3_11)))] pub fn PyFrame_BlockPop(f: *mut PyFrameObject) -> *mut PyTryBlock; pub fn PyFrame_LocalsToFast(f: *mut PyFrameObject, clear: c_int); pub fn PyFrame_FastToLocalsWithError(f: *mut PyFrameObject) -> c_int; pub fn PyFrame_FastToLocals(f: *mut PyFrameObject); // skipped _PyFrame_DebugMallocStats // skipped PyFrame_GetBack #[cfg(not(Py_3_9))] pub fn PyFrame_ClearFreeList() -> c_int; }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/genobject.rs
use crate::object::*; use crate::PyFrameObject; #[cfg(not(any(PyPy, GraalPy)))] use crate::_PyErr_StackItem; #[cfg(Py_3_11)] use std::os::raw::c_char; use std::os::raw::c_int; use std::ptr::addr_of_mut; #[cfg(not(any(PyPy, GraalPy)))] #[repr(C)] pub struct PyGenObject { pub ob_base: PyObject, #[cfg(not(Py_3_11))] pub gi_frame: *mut PyFrameObject, #[cfg(not(Py_3_10))] pub gi_running: c_int, #[cfg(not(Py_3_12))] pub gi_code: *mut PyObject, pub gi_weakreflist: *mut PyObject, pub gi_name: *mut PyObject, pub gi_qualname: *mut PyObject, pub gi_exc_state: _PyErr_StackItem, #[cfg(Py_3_11)] pub gi_origin_or_finalizer: *mut PyObject, #[cfg(Py_3_11)] pub gi_hooks_inited: c_char, #[cfg(Py_3_11)] pub gi_closed: c_char, #[cfg(Py_3_11)] pub gi_running_async: c_char, #[cfg(Py_3_11)] pub gi_frame_state: i8, #[cfg(Py_3_11)] pub gi_iframe: [*mut PyObject; 1], } #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { pub static mut PyGen_Type: PyTypeObject; } #[inline] pub unsafe fn PyGen_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, addr_of_mut!(PyGen_Type)) } #[inline] pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == addr_of_mut!(PyGen_Type)) as c_int } extern "C" { pub fn PyGen_New(frame: *mut PyFrameObject) -> *mut PyObject; // skipped PyGen_NewWithQualName // skipped _PyGen_SetStopIterationValue // skipped _PyGen_FetchStopIterationValue // skipped _PyGen_yf // skipped _PyGen_Finalize #[cfg(not(any(Py_3_9, PyPy)))] #[deprecated(note = "This function was never documented in the Python API.")] pub fn PyGen_NeedsFinalizing(op: *mut PyGenObject) -> c_int; } // skipped PyCoroObject #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { pub static mut PyCoro_Type: PyTypeObject; pub static mut _PyCoroWrapper_Type: PyTypeObject; } #[inline] pub unsafe fn PyCoro_CheckExact(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, addr_of_mut!(PyCoro_Type)) } // skipped _PyCoro_GetAwaitableIter // skipped PyCoro_New // skipped PyAsyncGenObject #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { pub static mut PyAsyncGen_Type: PyTypeObject; // skipped _PyAsyncGenASend_Type // skipped _PyAsyncGenWrappedValue_Type // skipped _PyAsyncGenAThrow_Type } // skipped PyAsyncGen_New #[inline] pub unsafe fn PyAsyncGen_CheckExact(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, addr_of_mut!(PyAsyncGen_Type)) } // skipped _PyAsyncGenValueWrapperNew
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/listobject.rs
use crate::object::*; #[cfg(not(PyPy))] use crate::pyport::Py_ssize_t; #[cfg(not(any(PyPy, GraalPy)))] #[repr(C)] pub struct PyListObject { pub ob_base: PyVarObject, pub ob_item: *mut *mut PyObject, pub allocated: Py_ssize_t, } #[cfg(any(PyPy, GraalPy))] pub struct PyListObject { pub ob_base: PyObject, } // skipped _PyList_Extend // skipped _PyList_DebugMallocStats // skipped _PyList_CAST (used inline below) /// Macro, trading safety for speed #[inline] #[cfg(not(any(PyPy, GraalPy)))] pub unsafe fn PyList_GET_ITEM(op: *mut PyObject, i: Py_ssize_t) -> *mut PyObject { *(*(op as *mut PyListObject)).ob_item.offset(i) } /// Macro, *only* to be used to fill in brand new lists #[inline] #[cfg(not(any(PyPy, GraalPy)))] pub unsafe fn PyList_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) { *(*(op as *mut PyListObject)).ob_item.offset(i) = v; } #[inline] #[cfg(not(PyPy))] pub unsafe fn PyList_GET_SIZE(op: *mut PyObject) -> Py_ssize_t { Py_SIZE(op) }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/methodobject.rs
use crate::object::*; #[cfg(not(GraalPy))] use crate::{PyCFunctionObject, PyMethodDefPointer, METH_METHOD, METH_STATIC}; use std::os::raw::c_int; use std::ptr::addr_of_mut; #[cfg(not(GraalPy))] pub struct PyCMethodObject { pub func: PyCFunctionObject, pub mm_class: *mut PyTypeObject, } #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { pub static mut PyCMethod_Type: PyTypeObject; } #[inline] pub unsafe fn PyCMethod_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == addr_of_mut!(PyCMethod_Type)) as c_int } #[inline] pub unsafe fn PyCMethod_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, addr_of_mut!(PyCMethod_Type)) } #[cfg(not(GraalPy))] #[inline] pub unsafe fn PyCFunction_GET_FUNCTION(func: *mut PyObject) -> PyMethodDefPointer { debug_assert_eq!(PyCMethod_Check(func), 1); let func = func.cast::<PyCFunctionObject>(); (*(*func).m_ml).ml_meth } #[cfg(not(GraalPy))] #[inline] pub unsafe fn PyCFunction_GET_SELF(func: *mut PyObject) -> *mut PyObject { debug_assert_eq!(PyCMethod_Check(func), 1); let func = func.cast::<PyCFunctionObject>(); if (*(*func).m_ml).ml_flags & METH_STATIC != 0 { std::ptr::null_mut() } else { (*func).m_self } } #[cfg(not(GraalPy))] #[inline] pub unsafe fn PyCFunction_GET_FLAGS(func: *mut PyObject) -> c_int { debug_assert_eq!(PyCMethod_Check(func), 1); let func = func.cast::<PyCFunctionObject>(); (*(*func).m_ml).ml_flags } #[cfg(not(GraalPy))] #[inline] pub unsafe fn PyCFunction_GET_CLASS(func: *mut PyObject) -> *mut PyTypeObject { debug_assert_eq!(PyCMethod_Check(func), 1); let func = func.cast::<PyCFunctionObject>(); if (*(*func).m_ml).ml_flags & METH_METHOD != 0 { let func = func.cast::<PyCMethodObject>(); (*func).mm_class } else { std::ptr::null_mut() } }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/funcobject.rs
use std::os::raw::c_int; #[cfg(not(all(PyPy, not(Py_3_8))))] use std::ptr::addr_of_mut; use crate::PyObject; #[cfg(all(not(any(PyPy, GraalPy)), not(Py_3_10)))] #[repr(C)] pub struct PyFunctionObject { pub ob_base: PyObject, pub func_code: *mut PyObject, pub func_globals: *mut PyObject, pub func_defaults: *mut PyObject, pub func_kwdefaults: *mut PyObject, pub func_closure: *mut PyObject, pub func_doc: *mut PyObject, pub func_name: *mut PyObject, pub func_dict: *mut PyObject, pub func_weakreflist: *mut PyObject, pub func_module: *mut PyObject, pub func_annotations: *mut PyObject, pub func_qualname: *mut PyObject, #[cfg(Py_3_8)] pub vectorcall: Option<crate::vectorcallfunc>, } #[cfg(all(not(any(PyPy, GraalPy)), Py_3_10))] #[repr(C)] pub struct PyFunctionObject { pub ob_base: PyObject, pub func_globals: *mut PyObject, pub func_builtins: *mut PyObject, pub func_name: *mut PyObject, pub func_qualname: *mut PyObject, pub func_code: *mut PyObject, pub func_defaults: *mut PyObject, pub func_kwdefaults: *mut PyObject, pub func_closure: *mut PyObject, pub func_doc: *mut PyObject, pub func_dict: *mut PyObject, pub func_weakreflist: *mut PyObject, pub func_module: *mut PyObject, pub func_annotations: *mut PyObject, #[cfg(Py_3_12)] pub func_typeparams: *mut PyObject, pub vectorcall: Option<crate::vectorcallfunc>, #[cfg(Py_3_11)] pub func_version: u32, } #[cfg(PyPy)] #[repr(C)] pub struct PyFunctionObject { pub ob_base: PyObject, pub func_name: *mut PyObject, } #[cfg(GraalPy)] pub struct PyFunctionObject { pub ob_base: PyObject, } #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { #[cfg(not(all(PyPy, not(Py_3_8))))] #[cfg_attr(PyPy, link_name = "PyPyFunction_Type")] pub static mut PyFunction_Type: crate::PyTypeObject; } #[cfg(not(all(PyPy, not(Py_3_8))))] #[inline] pub unsafe fn PyFunction_Check(op: *mut PyObject) -> c_int { (crate::Py_TYPE(op) == addr_of_mut!(PyFunction_Type)) as c_int } extern "C" { pub fn PyFunction_New(code: *mut PyObject, globals: *mut PyObject) -> *mut PyObject; pub fn PyFunction_NewWithQualName( code: *mut PyObject, globals: *mut PyObject, qualname: *mut PyObject, ) -> *mut PyObject; pub fn PyFunction_GetCode(op: *mut PyObject) -> *mut PyObject; pub fn PyFunction_GetGlobals(op: *mut PyObject) -> *mut PyObject; pub fn PyFunction_GetModule(op: *mut PyObject) -> *mut PyObject; pub fn PyFunction_GetDefaults(op: *mut PyObject) -> *mut PyObject; pub fn PyFunction_SetDefaults(op: *mut PyObject, defaults: *mut PyObject) -> c_int; pub fn PyFunction_GetKwDefaults(op: *mut PyObject) -> *mut PyObject; pub fn PyFunction_SetKwDefaults(op: *mut PyObject, defaults: *mut PyObject) -> c_int; pub fn PyFunction_GetClosure(op: *mut PyObject) -> *mut PyObject; pub fn PyFunction_SetClosure(op: *mut PyObject, closure: *mut PyObject) -> c_int; pub fn PyFunction_GetAnnotations(op: *mut PyObject) -> *mut PyObject; pub fn PyFunction_SetAnnotations(op: *mut PyObject, annotations: *mut PyObject) -> c_int; } // skipped _PyFunction_Vectorcall // skipped PyFunction_GET_CODE // skipped PyFunction_GET_GLOBALS // skipped PyFunction_GET_MODULE // skipped PyFunction_GET_DEFAULTS // skipped PyFunction_GET_KW_DEFAULTS // skipped PyFunction_GET_CLOSURE // skipped PyFunction_GET_ANNOTATIONS // skipped PyClassMethod_Type // skipped PyStaticMethod_Type // skipped PyClassMethod_New // skipped PyStaticMethod_New
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/descrobject.rs
use crate::{PyGetSetDef, PyMethodDef, PyObject, PyTypeObject}; use std::os::raw::{c_char, c_int, c_void}; pub type wrapperfunc = Option< unsafe extern "C" fn( slf: *mut PyObject, args: *mut PyObject, wrapped: *mut c_void, ) -> *mut PyObject, >; pub type wrapperfunc_kwds = Option< unsafe extern "C" fn( slf: *mut PyObject, args: *mut PyObject, wrapped: *mut c_void, kwds: *mut PyObject, ) -> *mut PyObject, >; #[repr(C)] pub struct wrapperbase { pub name: *const c_char, pub offset: c_int, pub function: *mut c_void, pub wrapper: wrapperfunc, pub doc: *const c_char, pub flags: c_int, pub name_strobj: *mut PyObject, } pub const PyWrapperFlag_KEYWORDS: c_int = 1; #[repr(C)] pub struct PyDescrObject { pub ob_base: PyObject, pub d_type: *mut PyTypeObject, pub d_name: *mut PyObject, pub d_qualname: *mut PyObject, } // skipped non-limited PyDescr_TYPE // skipped non-limited PyDescr_NAME #[repr(C)] pub struct PyMethodDescrObject { pub d_common: PyDescrObject, pub d_method: *mut PyMethodDef, #[cfg(all(not(PyPy), Py_3_8))] pub vectorcall: Option<crate::vectorcallfunc>, } #[repr(C)] pub struct PyMemberDescrObject { pub d_common: PyDescrObject, pub d_member: *mut PyGetSetDef, } #[repr(C)] pub struct PyGetSetDescrObject { pub d_common: PyDescrObject, pub d_getset: *mut PyGetSetDef, } #[repr(C)] pub struct PyWrapperDescrObject { pub d_common: PyDescrObject, pub d_base: *mut wrapperbase, pub d_wrapped: *mut c_void, } #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { pub static mut _PyMethodWrapper_Type: PyTypeObject; } // skipped non-limited PyDescr_NewWrapper // skipped non-limited PyDescr_IsData
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/complexobject.rs
use crate::PyObject; use std::os::raw::c_double; #[repr(C)] #[derive(Copy, Clone)] pub struct Py_complex { pub real: c_double, pub imag: c_double, } // skipped private function _Py_c_sum // skipped private function _Py_c_diff // skipped private function _Py_c_neg // skipped private function _Py_c_prod // skipped private function _Py_c_quot // skipped private function _Py_c_pow // skipped private function _Py_c_abs #[repr(C)] pub struct PyComplexObject { pub ob_base: PyObject, #[cfg(not(GraalPy))] pub cval: Py_complex, } extern "C" { #[cfg_attr(PyPy, link_name = "PyPyComplex_FromCComplex")] pub fn PyComplex_FromCComplex(v: Py_complex) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyComplex_AsCComplex")] pub fn PyComplex_AsCComplex(op: *mut PyObject) -> Py_complex; }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/unicodeobject.rs
#[cfg(not(any(PyPy, GraalPy)))] use crate::Py_hash_t; use crate::{PyObject, Py_UCS1, Py_UCS2, Py_UCS4, Py_ssize_t}; use libc::wchar_t; use std::os::raw::{c_char, c_int, c_uint, c_void}; // skipped Py_UNICODE_ISSPACE() // skipped Py_UNICODE_ISLOWER() // skipped Py_UNICODE_ISUPPER() // skipped Py_UNICODE_ISTITLE() // skipped Py_UNICODE_ISLINEBREAK // skipped Py_UNICODE_TOLOWER // skipped Py_UNICODE_TOUPPER // skipped Py_UNICODE_TOTITLE // skipped Py_UNICODE_ISDECIMAL // skipped Py_UNICODE_ISDIGIT // skipped Py_UNICODE_ISNUMERIC // skipped Py_UNICODE_ISPRINTABLE // skipped Py_UNICODE_TODECIMAL // skipped Py_UNICODE_TODIGIT // skipped Py_UNICODE_TONUMERIC // skipped Py_UNICODE_ISALPHA // skipped Py_UNICODE_ISALNUM // skipped Py_UNICODE_COPY // skipped Py_UNICODE_FILL // skipped Py_UNICODE_IS_SURROGATE // skipped Py_UNICODE_IS_HIGH_SURROGATE // skipped Py_UNICODE_IS_LOW_SURROGATE // skipped Py_UNICODE_JOIN_SURROGATES // skipped Py_UNICODE_HIGH_SURROGATE // skipped Py_UNICODE_LOW_SURROGATE // generated by bindgen v0.63.0 (with small adaptations) #[repr(C)] struct BitfieldUnit<Storage> { storage: Storage, } impl<Storage> BitfieldUnit<Storage> { #[inline] pub const fn new(storage: Storage) -> Self { Self { storage } } } #[cfg(not(GraalPy))] impl<Storage> BitfieldUnit<Storage> where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[inline] fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; let byte = self.storage.as_ref()[byte_index]; let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { index % 8 }; let mask = 1 << bit_index; byte & mask == mask } #[inline] fn set_bit(&mut self, index: usize, val: bool) { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; let byte = &mut self.storage.as_mut()[byte_index]; let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { index % 8 }; let mask = 1 << bit_index; if val { *byte |= mask; } else { *byte &= !mask; } } #[inline] fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); let mut val = 0; for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { i }; val |= 1 << index; } } val } #[inline] fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); for i in 0..(bit_width as usize) { let mask = 1 << i; let val_bit_is_set = val & mask == mask; let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { i }; self.set_bit(index + bit_offset, val_bit_is_set); } } } #[cfg(not(GraalPy))] const STATE_INTERNED_INDEX: usize = 0; #[cfg(not(GraalPy))] const STATE_INTERNED_WIDTH: u8 = 2; #[cfg(not(GraalPy))] const STATE_KIND_INDEX: usize = STATE_INTERNED_WIDTH as usize; #[cfg(not(GraalPy))] const STATE_KIND_WIDTH: u8 = 3; #[cfg(not(GraalPy))] const STATE_COMPACT_INDEX: usize = (STATE_INTERNED_WIDTH + STATE_KIND_WIDTH) as usize; #[cfg(not(GraalPy))] const STATE_COMPACT_WIDTH: u8 = 1; #[cfg(not(GraalPy))] const STATE_ASCII_INDEX: usize = (STATE_INTERNED_WIDTH + STATE_KIND_WIDTH + STATE_COMPACT_WIDTH) as usize; #[cfg(not(GraalPy))] const STATE_ASCII_WIDTH: u8 = 1; #[cfg(not(any(Py_3_12, GraalPy)))] const STATE_READY_INDEX: usize = (STATE_INTERNED_WIDTH + STATE_KIND_WIDTH + STATE_COMPACT_WIDTH + STATE_ASCII_WIDTH) as usize; #[cfg(not(any(Py_3_12, GraalPy)))] const STATE_READY_WIDTH: u8 = 1; // generated by bindgen v0.63.0 (with small adaptations) // The same code is generated for Python 3.7, 3.8, 3.9, 3.10, and 3.11, but the "ready" field // has been removed from Python 3.12. /// Wrapper around the `PyASCIIObject.state` bitfield with getters and setters that work /// on most little- and big-endian architectures. /// /// Memory layout of C bitfields is implementation defined, so these functions are still /// unsafe. Users must verify that they work as expected on the architectures they target. #[repr(C)] #[repr(align(4))] struct PyASCIIObjectState { bitfield_align: [u8; 0], bitfield: BitfieldUnit<[u8; 4usize]>, } // c_uint and u32 are not necessarily the same type on all targets / architectures #[cfg(not(GraalPy))] #[allow(clippy::useless_transmute)] impl PyASCIIObjectState { #[inline] unsafe fn interned(&self) -> c_uint { std::mem::transmute( self.bitfield .get(STATE_INTERNED_INDEX, STATE_INTERNED_WIDTH) as u32, ) } #[inline] unsafe fn set_interned(&mut self, val: c_uint) { let val: u32 = std::mem::transmute(val); self.bitfield .set(STATE_INTERNED_INDEX, STATE_INTERNED_WIDTH, val as u64) } #[inline] unsafe fn kind(&self) -> c_uint { std::mem::transmute(self.bitfield.get(STATE_KIND_INDEX, STATE_KIND_WIDTH) as u32) } #[inline] unsafe fn set_kind(&mut self, val: c_uint) { let val: u32 = std::mem::transmute(val); self.bitfield .set(STATE_KIND_INDEX, STATE_KIND_WIDTH, val as u64) } #[inline] unsafe fn compact(&self) -> c_uint { std::mem::transmute(self.bitfield.get(STATE_COMPACT_INDEX, STATE_COMPACT_WIDTH) as u32) } #[inline] unsafe fn set_compact(&mut self, val: c_uint) { let val: u32 = std::mem::transmute(val); self.bitfield .set(STATE_COMPACT_INDEX, STATE_COMPACT_WIDTH, val as u64) } #[inline] unsafe fn ascii(&self) -> c_uint { std::mem::transmute(self.bitfield.get(STATE_ASCII_INDEX, STATE_ASCII_WIDTH) as u32) } #[inline] unsafe fn set_ascii(&mut self, val: c_uint) { let val: u32 = std::mem::transmute(val); self.bitfield .set(STATE_ASCII_INDEX, STATE_ASCII_WIDTH, val as u64) } #[cfg(not(Py_3_12))] #[inline] unsafe fn ready(&self) -> c_uint { std::mem::transmute(self.bitfield.get(STATE_READY_INDEX, STATE_READY_WIDTH) as u32) } #[cfg(not(Py_3_12))] #[inline] unsafe fn set_ready(&mut self, val: c_uint) { let val: u32 = std::mem::transmute(val); self.bitfield .set(STATE_READY_INDEX, STATE_READY_WIDTH, val as u64) } } impl From<u32> for PyASCIIObjectState { #[inline] fn from(value: u32) -> Self { PyASCIIObjectState { bitfield_align: [], bitfield: BitfieldUnit::new(value.to_ne_bytes()), } } } impl From<PyASCIIObjectState> for u32 { #[inline] fn from(value: PyASCIIObjectState) -> Self { u32::from_ne_bytes(value.bitfield.storage) } } #[repr(C)] pub struct PyASCIIObject { pub ob_base: PyObject, #[cfg(not(GraalPy))] pub length: Py_ssize_t, #[cfg(not(any(PyPy, GraalPy)))] pub hash: Py_hash_t, /// A bit field with various properties. /// /// Rust doesn't expose bitfields. So we have accessor functions for /// retrieving values. /// /// unsigned int interned:2; // SSTATE_* constants. /// unsigned int kind:3; // PyUnicode_*_KIND constants. /// unsigned int compact:1; /// unsigned int ascii:1; /// unsigned int ready:1; /// unsigned int :24; #[cfg(not(GraalPy))] pub state: u32, #[cfg(not(any(Py_3_12, GraalPy)))] pub wstr: *mut wchar_t, } /// Interacting with the bitfield is not actually well-defined, so we mark these APIs unsafe. #[cfg(not(GraalPy))] impl PyASCIIObject { #[cfg_attr(not(Py_3_12), allow(rustdoc::broken_intra_doc_links))] // SSTATE_INTERNED_IMMORTAL_STATIC requires 3.12 /// Get the `interned` field of the [`PyASCIIObject`] state bitfield. /// /// Returns one of: [`SSTATE_NOT_INTERNED`], [`SSTATE_INTERNED_MORTAL`], /// [`SSTATE_INTERNED_IMMORTAL`], or [`SSTATE_INTERNED_IMMORTAL_STATIC`]. #[inline] pub unsafe fn interned(&self) -> c_uint { PyASCIIObjectState::from(self.state).interned() } #[cfg_attr(not(Py_3_12), allow(rustdoc::broken_intra_doc_links))] // SSTATE_INTERNED_IMMORTAL_STATIC requires 3.12 /// Set the `interned` field of the [`PyASCIIObject`] state bitfield. /// /// Calling this function with an argument that is not [`SSTATE_NOT_INTERNED`], /// [`SSTATE_INTERNED_MORTAL`], [`SSTATE_INTERNED_IMMORTAL`], or /// [`SSTATE_INTERNED_IMMORTAL_STATIC`] is invalid. #[inline] pub unsafe fn set_interned(&mut self, val: c_uint) { let mut state = PyASCIIObjectState::from(self.state); state.set_interned(val); self.state = u32::from(state); } /// Get the `kind` field of the [`PyASCIIObject`] state bitfield. /// /// Returns one of: #[cfg_attr(not(Py_3_12), doc = "[`PyUnicode_WCHAR_KIND`], ")] /// [`PyUnicode_1BYTE_KIND`], [`PyUnicode_2BYTE_KIND`], or [`PyUnicode_4BYTE_KIND`]. #[inline] pub unsafe fn kind(&self) -> c_uint { PyASCIIObjectState::from(self.state).kind() } /// Set the `kind` field of the [`PyASCIIObject`] state bitfield. /// /// Calling this function with an argument that is not #[cfg_attr(not(Py_3_12), doc = "[`PyUnicode_WCHAR_KIND`], ")] /// [`PyUnicode_1BYTE_KIND`], [`PyUnicode_2BYTE_KIND`], or [`PyUnicode_4BYTE_KIND`] is invalid. #[inline] pub unsafe fn set_kind(&mut self, val: c_uint) { let mut state = PyASCIIObjectState::from(self.state); state.set_kind(val); self.state = u32::from(state); } /// Get the `compact` field of the [`PyASCIIObject`] state bitfield. /// /// Returns either `0` or `1`. #[inline] pub unsafe fn compact(&self) -> c_uint { PyASCIIObjectState::from(self.state).compact() } /// Set the `compact` flag of the [`PyASCIIObject`] state bitfield. /// /// Calling this function with an argument that is neither `0` nor `1` is invalid. #[inline] pub unsafe fn set_compact(&mut self, val: c_uint) { let mut state = PyASCIIObjectState::from(self.state); state.set_compact(val); self.state = u32::from(state); } /// Get the `ascii` field of the [`PyASCIIObject`] state bitfield. /// /// Returns either `0` or `1`. #[inline] pub unsafe fn ascii(&self) -> c_uint { PyASCIIObjectState::from(self.state).ascii() } /// Set the `ascii` flag of the [`PyASCIIObject`] state bitfield. /// /// Calling this function with an argument that is neither `0` nor `1` is invalid. #[inline] pub unsafe fn set_ascii(&mut self, val: c_uint) { let mut state = PyASCIIObjectState::from(self.state); state.set_ascii(val); self.state = u32::from(state); } /// Get the `ready` field of the [`PyASCIIObject`] state bitfield. /// /// Returns either `0` or `1`. #[cfg(not(Py_3_12))] #[inline] pub unsafe fn ready(&self) -> c_uint { PyASCIIObjectState::from(self.state).ready() } /// Set the `ready` flag of the [`PyASCIIObject`] state bitfield. /// /// Calling this function with an argument that is neither `0` nor `1` is invalid. #[cfg(not(Py_3_12))] #[inline] pub unsafe fn set_ready(&mut self, val: c_uint) { let mut state = PyASCIIObjectState::from(self.state); state.set_ready(val); self.state = u32::from(state); } } #[repr(C)] pub struct PyCompactUnicodeObject { pub _base: PyASCIIObject, #[cfg(not(GraalPy))] pub utf8_length: Py_ssize_t, #[cfg(not(GraalPy))] pub utf8: *mut c_char, #[cfg(not(any(Py_3_12, GraalPy)))] pub wstr_length: Py_ssize_t, } #[repr(C)] pub union PyUnicodeObjectData { pub any: *mut c_void, pub latin1: *mut Py_UCS1, pub ucs2: *mut Py_UCS2, pub ucs4: *mut Py_UCS4, } #[repr(C)] pub struct PyUnicodeObject { pub _base: PyCompactUnicodeObject, #[cfg(not(GraalPy))] pub data: PyUnicodeObjectData, } extern "C" { #[cfg(not(any(PyPy, GraalPy)))] pub fn _PyUnicode_CheckConsistency(op: *mut PyObject, check_content: c_int) -> c_int; } // skipped PyUnicode_GET_SIZE // skipped PyUnicode_GET_DATA_SIZE // skipped PyUnicode_AS_UNICODE // skipped PyUnicode_AS_DATA pub const SSTATE_NOT_INTERNED: c_uint = 0; pub const SSTATE_INTERNED_MORTAL: c_uint = 1; pub const SSTATE_INTERNED_IMMORTAL: c_uint = 2; #[cfg(Py_3_12)] pub const SSTATE_INTERNED_IMMORTAL_STATIC: c_uint = 3; #[cfg(not(GraalPy))] #[inline] pub unsafe fn PyUnicode_IS_ASCII(op: *mut PyObject) -> c_uint { debug_assert!(crate::PyUnicode_Check(op) != 0); #[cfg(not(Py_3_12))] debug_assert!(PyUnicode_IS_READY(op) != 0); (*(op as *mut PyASCIIObject)).ascii() } #[cfg(not(GraalPy))] #[inline] pub unsafe fn PyUnicode_IS_COMPACT(op: *mut PyObject) -> c_uint { (*(op as *mut PyASCIIObject)).compact() } #[cfg(not(GraalPy))] #[inline] pub unsafe fn PyUnicode_IS_COMPACT_ASCII(op: *mut PyObject) -> c_uint { ((*(op as *mut PyASCIIObject)).ascii() != 0 && PyUnicode_IS_COMPACT(op) != 0).into() } #[cfg(not(Py_3_12))] #[deprecated(note = "Removed in Python 3.12")] pub const PyUnicode_WCHAR_KIND: c_uint = 0; pub const PyUnicode_1BYTE_KIND: c_uint = 1; pub const PyUnicode_2BYTE_KIND: c_uint = 2; pub const PyUnicode_4BYTE_KIND: c_uint = 4; #[cfg(not(any(GraalPy, PyPy)))] #[inline] pub unsafe fn PyUnicode_1BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS1 { PyUnicode_DATA(op) as *mut Py_UCS1 } #[cfg(not(any(GraalPy, PyPy)))] #[inline] pub unsafe fn PyUnicode_2BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS2 { PyUnicode_DATA(op) as *mut Py_UCS2 } #[cfg(not(any(GraalPy, PyPy)))] #[inline] pub unsafe fn PyUnicode_4BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS4 { PyUnicode_DATA(op) as *mut Py_UCS4 } #[cfg(not(GraalPy))] #[inline] pub unsafe fn PyUnicode_KIND(op: *mut PyObject) -> c_uint { debug_assert!(crate::PyUnicode_Check(op) != 0); #[cfg(not(Py_3_12))] debug_assert!(PyUnicode_IS_READY(op) != 0); (*(op as *mut PyASCIIObject)).kind() } #[cfg(not(GraalPy))] #[inline] pub unsafe fn _PyUnicode_COMPACT_DATA(op: *mut PyObject) -> *mut c_void { if PyUnicode_IS_ASCII(op) != 0 { (op as *mut PyASCIIObject).offset(1) as *mut c_void } else { (op as *mut PyCompactUnicodeObject).offset(1) as *mut c_void } } #[cfg(not(any(GraalPy, PyPy)))] #[inline] pub unsafe fn _PyUnicode_NONCOMPACT_DATA(op: *mut PyObject) -> *mut c_void { debug_assert!(!(*(op as *mut PyUnicodeObject)).data.any.is_null()); (*(op as *mut PyUnicodeObject)).data.any } #[cfg(not(any(GraalPy, PyPy)))] #[inline] pub unsafe fn PyUnicode_DATA(op: *mut PyObject) -> *mut c_void { debug_assert!(crate::PyUnicode_Check(op) != 0); if PyUnicode_IS_COMPACT(op) != 0 { _PyUnicode_COMPACT_DATA(op) } else { _PyUnicode_NONCOMPACT_DATA(op) } } // skipped PyUnicode_WRITE // skipped PyUnicode_READ // skipped PyUnicode_READ_CHAR #[cfg(not(GraalPy))] #[inline] pub unsafe fn PyUnicode_GET_LENGTH(op: *mut PyObject) -> Py_ssize_t { debug_assert!(crate::PyUnicode_Check(op) != 0); #[cfg(not(Py_3_12))] debug_assert!(PyUnicode_IS_READY(op) != 0); (*(op as *mut PyASCIIObject)).length } #[cfg(any(Py_3_12, GraalPy))] #[inline] pub unsafe fn PyUnicode_IS_READY(_op: *mut PyObject) -> c_uint { // kept in CPython for backwards compatibility 1 } #[cfg(not(any(GraalPy, Py_3_12)))] #[inline] pub unsafe fn PyUnicode_IS_READY(op: *mut PyObject) -> c_uint { (*(op as *mut PyASCIIObject)).ready() } #[cfg(any(Py_3_12, GraalPy))] #[inline] pub unsafe fn PyUnicode_READY(_op: *mut PyObject) -> c_int { 0 } #[cfg(not(any(Py_3_12, GraalPy)))] #[inline] pub unsafe fn PyUnicode_READY(op: *mut PyObject) -> c_int { debug_assert!(crate::PyUnicode_Check(op) != 0); if PyUnicode_IS_READY(op) != 0 { 0 } else { _PyUnicode_Ready(op) } } // skipped PyUnicode_MAX_CHAR_VALUE // skipped _PyUnicode_get_wstr_length // skipped PyUnicode_WSTR_LENGTH extern "C" { #[cfg_attr(PyPy, link_name = "PyPyUnicode_New")] pub fn PyUnicode_New(size: Py_ssize_t, maxchar: Py_UCS4) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "_PyPyUnicode_Ready")] pub fn _PyUnicode_Ready(unicode: *mut PyObject) -> c_int; // skipped _PyUnicode_Copy #[cfg(not(PyPy))] pub fn PyUnicode_CopyCharacters( to: *mut PyObject, to_start: Py_ssize_t, from: *mut PyObject, from_start: Py_ssize_t, how_many: Py_ssize_t, ) -> Py_ssize_t; // skipped _PyUnicode_FastCopyCharacters #[cfg(not(PyPy))] pub fn PyUnicode_Fill( unicode: *mut PyObject, start: Py_ssize_t, length: Py_ssize_t, fill_char: Py_UCS4, ) -> Py_ssize_t; // skipped _PyUnicode_FastFill #[cfg(not(Py_3_12))] #[deprecated] #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromUnicode")] pub fn PyUnicode_FromUnicode(u: *const wchar_t, size: Py_ssize_t) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromKindAndData")] pub fn PyUnicode_FromKindAndData( kind: c_int, buffer: *const c_void, size: Py_ssize_t, ) -> *mut PyObject; // skipped _PyUnicode_FromASCII // skipped _PyUnicode_FindMaxChar #[cfg(not(Py_3_12))] #[deprecated] #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicode")] pub fn PyUnicode_AsUnicode(unicode: *mut PyObject) -> *mut wchar_t; // skipped _PyUnicode_AsUnicode #[cfg(not(Py_3_12))] #[deprecated] #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicodeAndSize")] pub fn PyUnicode_AsUnicodeAndSize( unicode: *mut PyObject, size: *mut Py_ssize_t, ) -> *mut wchar_t; // skipped PyUnicode_GetMax } // skipped _PyUnicodeWriter // skipped _PyUnicodeWriter_Init // skipped _PyUnicodeWriter_Prepare // skipped _PyUnicodeWriter_PrepareInternal // skipped _PyUnicodeWriter_PrepareKind // skipped _PyUnicodeWriter_PrepareKindInternal // skipped _PyUnicodeWriter_WriteChar // skipped _PyUnicodeWriter_WriteStr // skipped _PyUnicodeWriter_WriteSubstring // skipped _PyUnicodeWriter_WriteASCIIString // skipped _PyUnicodeWriter_WriteLatin1String // skipped _PyUnicodeWriter_Finish // skipped _PyUnicodeWriter_Dealloc // skipped _PyUnicode_FormatAdvancedWriter extern "C" { // skipped _PyUnicode_AsStringAndSize #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8")] pub fn PyUnicode_AsUTF8(unicode: *mut PyObject) -> *const c_char; // skipped _PyUnicode_AsString pub fn PyUnicode_Encode( s: *const wchar_t, size: Py_ssize_t, encoding: *const c_char, errors: *const c_char, ) -> *mut PyObject; pub fn PyUnicode_EncodeUTF7( data: *const wchar_t, length: Py_ssize_t, base64SetO: c_int, base64WhiteSpace: c_int, errors: *const c_char, ) -> *mut PyObject; // skipped _PyUnicode_EncodeUTF7 // skipped _PyUnicode_AsUTF8String #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeUTF8")] pub fn PyUnicode_EncodeUTF8( data: *const wchar_t, length: Py_ssize_t, errors: *const c_char, ) -> *mut PyObject; pub fn PyUnicode_EncodeUTF32( data: *const wchar_t, length: Py_ssize_t, errors: *const c_char, byteorder: c_int, ) -> *mut PyObject; // skipped _PyUnicode_EncodeUTF32 pub fn PyUnicode_EncodeUTF16( data: *const wchar_t, length: Py_ssize_t, errors: *const c_char, byteorder: c_int, ) -> *mut PyObject; // skipped _PyUnicode_EncodeUTF16 // skipped _PyUnicode_DecodeUnicodeEscape pub fn PyUnicode_EncodeUnicodeEscape(data: *const wchar_t, length: Py_ssize_t) -> *mut PyObject; pub fn PyUnicode_EncodeRawUnicodeEscape( data: *const wchar_t, length: Py_ssize_t, ) -> *mut PyObject; // skipped _PyUnicode_AsLatin1String #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeLatin1")] pub fn PyUnicode_EncodeLatin1( data: *const wchar_t, length: Py_ssize_t, errors: *const c_char, ) -> *mut PyObject; // skipped _PyUnicode_AsASCIIString #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeASCII")] pub fn PyUnicode_EncodeASCII( data: *const wchar_t, length: Py_ssize_t, errors: *const c_char, ) -> *mut PyObject; pub fn PyUnicode_EncodeCharmap( data: *const wchar_t, length: Py_ssize_t, mapping: *mut PyObject, errors: *const c_char, ) -> *mut PyObject; // skipped _PyUnicode_EncodeCharmap pub fn PyUnicode_TranslateCharmap( data: *const wchar_t, length: Py_ssize_t, table: *mut PyObject, errors: *const c_char, ) -> *mut PyObject; // skipped PyUnicode_EncodeMBCS #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeDecimal")] pub fn PyUnicode_EncodeDecimal( s: *mut wchar_t, length: Py_ssize_t, output: *mut c_char, errors: *const c_char, ) -> c_int; #[cfg_attr(PyPy, link_name = "PyPyUnicode_TransformDecimalToASCII")] pub fn PyUnicode_TransformDecimalToASCII(s: *mut wchar_t, length: Py_ssize_t) -> *mut PyObject; // skipped _PyUnicode_TransformDecimalAndSpaceToASCII } // skipped _PyUnicode_JoinArray // skipped _PyUnicode_EqualToASCIIId // skipped _PyUnicode_EqualToASCIIString // skipped _PyUnicode_XStrip // skipped _PyUnicode_InsertThousandsGrouping // skipped _Py_ascii_whitespace // skipped _PyUnicode_IsLowercase // skipped _PyUnicode_IsUppercase // skipped _PyUnicode_IsTitlecase // skipped _PyUnicode_IsXidStart // skipped _PyUnicode_IsXidContinue // skipped _PyUnicode_IsWhitespace // skipped _PyUnicode_IsLinebreak // skipped _PyUnicode_ToLowercase // skipped _PyUnicode_ToUppercase // skipped _PyUnicode_ToTitlecase // skipped _PyUnicode_ToLowerFull // skipped _PyUnicode_ToTitleFull // skipped _PyUnicode_ToUpperFull // skipped _PyUnicode_ToFoldedFull // skipped _PyUnicode_IsCaseIgnorable // skipped _PyUnicode_IsCased // skipped _PyUnicode_ToDecimalDigit // skipped _PyUnicode_ToDigit // skipped _PyUnicode_ToNumeric // skipped _PyUnicode_IsDecimalDigit // skipped _PyUnicode_IsDigit // skipped _PyUnicode_IsNumeric // skipped _PyUnicode_IsPrintable // skipped _PyUnicode_IsAlpha // skipped Py_UNICODE_strlen // skipped Py_UNICODE_strcpy // skipped Py_UNICODE_strcat // skipped Py_UNICODE_strncpy // skipped Py_UNICODE_strcmp // skipped Py_UNICODE_strncmp // skipped Py_UNICODE_strchr // skipped Py_UNICODE_strrchr // skipped _PyUnicode_FormatLong // skipped PyUnicode_AsUnicodeCopy // skipped _PyUnicode_FromId // skipped _PyUnicode_EQ // skipped _PyUnicode_ScanIdentifier
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/floatobject.rs
#[cfg(GraalPy)] use crate::PyFloat_AsDouble; use crate::{PyFloat_Check, PyObject}; use std::os::raw::c_double; #[repr(C)] pub struct PyFloatObject { pub ob_base: PyObject, #[cfg(not(GraalPy))] pub ob_fval: c_double, } #[inline] pub unsafe fn _PyFloat_CAST(op: *mut PyObject) -> *mut PyFloatObject { debug_assert_eq!(PyFloat_Check(op), 1); op.cast() } #[inline] pub unsafe fn PyFloat_AS_DOUBLE(op: *mut PyObject) -> c_double { #[cfg(not(GraalPy))] return (*_PyFloat_CAST(op)).ob_fval; #[cfg(GraalPy)] return PyFloat_AsDouble(op); } // skipped PyFloat_Pack2 // skipped PyFloat_Pack4 // skipped PyFloat_Pack8 // skipped PyFloat_Unpack2 // skipped PyFloat_Unpack4 // skipped PyFloat_Unpack8
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/objimpl.rs
use libc::size_t; use std::os::raw::c_int; #[cfg(not(any(PyPy, GraalPy)))] use std::os::raw::c_void; use crate::object::*; // skipped _PyObject_SIZE // skipped _PyObject_VAR_SIZE #[cfg(not(Py_3_11))] extern "C" { pub fn _Py_GetAllocatedBlocks() -> crate::Py_ssize_t; } #[cfg(not(any(PyPy, GraalPy)))] #[repr(C)] #[derive(Copy, Clone)] pub struct PyObjectArenaAllocator { pub ctx: *mut c_void, pub alloc: Option<extern "C" fn(ctx: *mut c_void, size: size_t) -> *mut c_void>, pub free: Option<extern "C" fn(ctx: *mut c_void, ptr: *mut c_void, size: size_t)>, } #[cfg(not(any(PyPy, GraalPy)))] impl Default for PyObjectArenaAllocator { #[inline] fn default() -> Self { unsafe { std::mem::zeroed() } } } extern "C" { #[cfg(not(any(PyPy, GraalPy)))] pub fn PyObject_GetArenaAllocator(allocator: *mut PyObjectArenaAllocator); #[cfg(not(any(PyPy, GraalPy)))] pub fn PyObject_SetArenaAllocator(allocator: *mut PyObjectArenaAllocator); #[cfg(Py_3_9)] pub fn PyObject_IS_GC(o: *mut PyObject) -> c_int; } #[inline] #[cfg(not(Py_3_9))] pub unsafe fn PyObject_IS_GC(o: *mut PyObject) -> c_int { (crate::PyType_IS_GC(Py_TYPE(o)) != 0 && match (*Py_TYPE(o)).tp_is_gc { Some(tp_is_gc) => tp_is_gc(o) != 0, None => true, }) as c_int } #[cfg(not(Py_3_11))] extern "C" { pub fn _PyObject_GC_Malloc(size: size_t) -> *mut PyObject; pub fn _PyObject_GC_Calloc(size: size_t) -> *mut PyObject; } #[inline] pub unsafe fn PyType_SUPPORTS_WEAKREFS(t: *mut PyTypeObject) -> c_int { ((*t).tp_weaklistoffset > 0) as c_int } #[inline] pub unsafe fn PyObject_GET_WEAKREFS_LISTPTR(o: *mut PyObject) -> *mut *mut PyObject { let weaklistoffset = (*Py_TYPE(o)).tp_weaklistoffset; o.offset(weaklistoffset) as *mut *mut PyObject } // skipped PyUnstable_Object_GC_NewWithExtraData
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/code.rs
use crate::object::*; use crate::pyport::Py_ssize_t; #[allow(unused_imports)] use std::os::raw::{c_char, c_int, c_short, c_uchar, c_void}; #[cfg(not(any(PyPy, GraalPy)))] use std::ptr::addr_of_mut; #[cfg(all(Py_3_8, not(any(PyPy, GraalPy)), not(Py_3_11)))] opaque_struct!(_PyOpcache); #[cfg(Py_3_12)] pub const _PY_MONITORING_LOCAL_EVENTS: usize = 10; #[cfg(Py_3_12)] pub const _PY_MONITORING_UNGROUPED_EVENTS: usize = 15; #[cfg(Py_3_12)] pub const _PY_MONITORING_EVENTS: usize = 17; #[cfg(Py_3_12)] #[repr(C)] #[derive(Clone, Copy)] pub struct _Py_LocalMonitors { pub tools: [u8; if cfg!(Py_3_13) { _PY_MONITORING_LOCAL_EVENTS } else { _PY_MONITORING_UNGROUPED_EVENTS }], } #[cfg(Py_3_12)] #[repr(C)] #[derive(Clone, Copy)] pub struct _Py_GlobalMonitors { pub tools: [u8; _PY_MONITORING_UNGROUPED_EVENTS], } // skipped _Py_CODEUNIT // skipped _Py_OPCODE // skipped _Py_OPARG // skipped _py_make_codeunit // skipped _py_set_opcode // skipped _Py_MAKE_CODEUNIT // skipped _Py_SET_OPCODE #[cfg(Py_3_12)] #[repr(C)] #[derive(Copy, Clone)] pub struct _PyCoCached { pub _co_code: *mut PyObject, pub _co_varnames: *mut PyObject, pub _co_cellvars: *mut PyObject, pub _co_freevars: *mut PyObject, } #[cfg(Py_3_12)] #[repr(C)] #[derive(Copy, Clone)] pub struct _PyCoLineInstrumentationData { pub original_opcode: u8, pub line_delta: i8, } #[cfg(Py_3_12)] #[repr(C)] #[derive(Copy, Clone)] pub struct _PyCoMonitoringData { pub local_monitors: _Py_LocalMonitors, pub active_monitors: _Py_LocalMonitors, pub tools: *mut u8, pub lines: *mut _PyCoLineInstrumentationData, pub line_tools: *mut u8, pub per_instruction_opcodes: *mut u8, pub per_instruction_tools: *mut u8, } #[cfg(all(not(any(PyPy, GraalPy)), not(Py_3_7)))] opaque_struct!(PyCodeObject); #[cfg(all(not(any(PyPy, GraalPy)), Py_3_7, not(Py_3_8)))] #[repr(C)] pub struct PyCodeObject { pub ob_base: PyObject, pub co_argcount: c_int, pub co_kwonlyargcount: c_int, pub co_nlocals: c_int, pub co_stacksize: c_int, pub co_flags: c_int, pub co_firstlineno: c_int, pub co_code: *mut PyObject, pub co_consts: *mut PyObject, pub co_names: *mut PyObject, pub co_varnames: *mut PyObject, pub co_freevars: *mut PyObject, pub co_cellvars: *mut PyObject, pub co_cell2arg: *mut Py_ssize_t, pub co_filename: *mut PyObject, pub co_name: *mut PyObject, pub co_lnotab: *mut PyObject, pub co_zombieframe: *mut c_void, pub co_weakreflist: *mut PyObject, pub co_extra: *mut c_void, } #[cfg(Py_3_13)] opaque_struct!(_PyExecutorArray); #[cfg(all(not(any(PyPy, GraalPy)), Py_3_8, not(Py_3_11)))] #[repr(C)] pub struct PyCodeObject { pub ob_base: PyObject, pub co_argcount: c_int, pub co_posonlyargcount: c_int, pub co_kwonlyargcount: c_int, pub co_nlocals: c_int, pub co_stacksize: c_int, pub co_flags: c_int, pub co_firstlineno: c_int, pub co_code: *mut PyObject, pub co_consts: *mut PyObject, pub co_names: *mut PyObject, pub co_varnames: *mut PyObject, pub co_freevars: *mut PyObject, pub co_cellvars: *mut PyObject, pub co_cell2arg: *mut Py_ssize_t, pub co_filename: *mut PyObject, pub co_name: *mut PyObject, #[cfg(not(Py_3_10))] pub co_lnotab: *mut PyObject, #[cfg(Py_3_10)] pub co_linetable: *mut PyObject, pub co_zombieframe: *mut c_void, pub co_weakreflist: *mut PyObject, pub co_extra: *mut c_void, pub co_opcache_map: *mut c_uchar, pub co_opcache: *mut _PyOpcache, pub co_opcache_flag: c_int, pub co_opcache_size: c_uchar, } #[cfg(all(not(any(PyPy, GraalPy)), Py_3_11))] #[repr(C)] pub struct PyCodeObject { pub ob_base: PyVarObject, pub co_consts: *mut PyObject, pub co_names: *mut PyObject, pub co_exceptiontable: *mut PyObject, pub co_flags: c_int, #[cfg(not(Py_3_12))] pub co_warmup: c_int, pub co_argcount: c_int, pub co_posonlyargcount: c_int, pub co_kwonlyargcount: c_int, pub co_stacksize: c_int, pub co_firstlineno: c_int, pub co_nlocalsplus: c_int, #[cfg(Py_3_12)] pub co_framesize: c_int, pub co_nlocals: c_int, #[cfg(not(Py_3_12))] pub co_nplaincellvars: c_int, pub co_ncellvars: c_int, pub co_nfreevars: c_int, #[cfg(Py_3_12)] pub co_version: u32, pub co_localsplusnames: *mut PyObject, pub co_localspluskinds: *mut PyObject, pub co_filename: *mut PyObject, pub co_name: *mut PyObject, pub co_qualname: *mut PyObject, pub co_linetable: *mut PyObject, pub co_weakreflist: *mut PyObject, #[cfg(not(Py_3_12))] pub _co_code: *mut PyObject, #[cfg(not(Py_3_12))] pub _co_linearray: *mut c_char, #[cfg(Py_3_13)] pub co_executors: *mut _PyExecutorArray, #[cfg(Py_3_12)] pub _co_cached: *mut _PyCoCached, #[cfg(Py_3_12)] pub _co_instrumentation_version: u64, #[cfg(Py_3_12)] pub _co_monitoring: *mut _PyCoMonitoringData, pub _co_firsttraceable: c_int, pub co_extra: *mut c_void, pub co_code_adaptive: [c_char; 1], } #[cfg(PyPy)] #[repr(C)] pub struct PyCodeObject { pub ob_base: PyObject, pub co_name: *mut PyObject, pub co_filename: *mut PyObject, pub co_argcount: c_int, pub co_flags: c_int, } /* Masks for co_flags */ pub const CO_OPTIMIZED: c_int = 0x0001; pub const CO_NEWLOCALS: c_int = 0x0002; pub const CO_VARARGS: c_int = 0x0004; pub const CO_VARKEYWORDS: c_int = 0x0008; pub const CO_NESTED: c_int = 0x0010; pub const CO_GENERATOR: c_int = 0x0020; /* The CO_NOFREE flag is set if there are no free or cell variables. This information is redundant, but it allows a single flag test to determine whether there is any extra work to be done when the call frame it setup. */ pub const CO_NOFREE: c_int = 0x0040; /* The CO_COROUTINE flag is set for coroutine functions (defined with ``async def`` keywords) */ pub const CO_COROUTINE: c_int = 0x0080; pub const CO_ITERABLE_COROUTINE: c_int = 0x0100; pub const CO_ASYNC_GENERATOR: c_int = 0x0200; pub const CO_FUTURE_DIVISION: c_int = 0x2000; pub const CO_FUTURE_ABSOLUTE_IMPORT: c_int = 0x4000; /* do absolute imports by default */ pub const CO_FUTURE_WITH_STATEMENT: c_int = 0x8000; pub const CO_FUTURE_PRINT_FUNCTION: c_int = 0x1_0000; pub const CO_FUTURE_UNICODE_LITERALS: c_int = 0x2_0000; pub const CO_FUTURE_BARRY_AS_BDFL: c_int = 0x4_0000; pub const CO_FUTURE_GENERATOR_STOP: c_int = 0x8_0000; // skipped CO_FUTURE_ANNOTATIONS // skipped CO_CELL_NOT_AN_ARG pub const CO_MAXBLOCKS: usize = 20; #[cfg(not(any(PyPy, GraalPy)))] #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { pub static mut PyCode_Type: PyTypeObject; } #[inline] #[cfg(not(any(PyPy, GraalPy)))] pub unsafe fn PyCode_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == addr_of_mut!(PyCode_Type)) as c_int } #[inline] #[cfg(all(not(any(PyPy, GraalPy)), Py_3_10, not(Py_3_11)))] pub unsafe fn PyCode_GetNumFree(op: *mut PyCodeObject) -> Py_ssize_t { crate::PyTuple_GET_SIZE((*op).co_freevars) } #[inline] #[cfg(all(not(Py_3_10), Py_3_11, not(any(PyPy, GraalPy))))] pub unsafe fn PyCode_GetNumFree(op: *mut PyCodeObject) -> c_int { (*op).co_nfreevars } extern "C" { #[cfg(PyPy)] #[link_name = "PyPyCode_Check"] pub fn PyCode_Check(op: *mut PyObject) -> c_int; #[cfg(PyPy)] #[link_name = "PyPyCode_GetNumFree"] pub fn PyCode_GetNumFree(op: *mut PyCodeObject) -> Py_ssize_t; } extern "C" { #[cfg(not(GraalPy))] #[cfg_attr(PyPy, link_name = "PyPyCode_New")] pub fn PyCode_New( argcount: c_int, kwonlyargcount: c_int, nlocals: c_int, stacksize: c_int, flags: c_int, code: *mut PyObject, consts: *mut PyObject, names: *mut PyObject, varnames: *mut PyObject, freevars: *mut PyObject, cellvars: *mut PyObject, filename: *mut PyObject, name: *mut PyObject, firstlineno: c_int, lnotab: *mut PyObject, ) -> *mut PyCodeObject; #[cfg(not(GraalPy))] #[cfg(Py_3_8)] pub fn PyCode_NewWithPosOnlyArgs( argcount: c_int, posonlyargcount: c_int, kwonlyargcount: c_int, nlocals: c_int, stacksize: c_int, flags: c_int, code: *mut PyObject, consts: *mut PyObject, names: *mut PyObject, varnames: *mut PyObject, freevars: *mut PyObject, cellvars: *mut PyObject, filename: *mut PyObject, name: *mut PyObject, firstlineno: c_int, lnotab: *mut PyObject, ) -> *mut PyCodeObject; #[cfg(not(GraalPy))] #[cfg_attr(PyPy, link_name = "PyPyCode_NewEmpty")] pub fn PyCode_NewEmpty( filename: *const c_char, funcname: *const c_char, firstlineno: c_int, ) -> *mut PyCodeObject; #[cfg(not(GraalPy))] pub fn PyCode_Addr2Line(arg1: *mut PyCodeObject, arg2: c_int) -> c_int; // skipped PyCodeAddressRange "for internal use only" // skipped _PyCode_CheckLineNumber // skipped _PyCode_ConstantKey pub fn PyCode_Optimize( code: *mut PyObject, consts: *mut PyObject, names: *mut PyObject, lnotab: *mut PyObject, ) -> *mut PyObject; pub fn _PyCode_GetExtra( code: *mut PyObject, index: Py_ssize_t, extra: *const *mut c_void, ) -> c_int; pub fn _PyCode_SetExtra(code: *mut PyObject, index: Py_ssize_t, extra: *mut c_void) -> c_int; }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/longobject.rs
use crate::longobject::*; use crate::object::*; #[cfg(Py_3_13)] use crate::pyport::Py_ssize_t; use libc::size_t; #[cfg(Py_3_13)] use std::os::raw::c_void; use std::os::raw::{c_int, c_uchar}; #[cfg(Py_3_13)] extern "C" { pub fn PyLong_FromUnicodeObject(u: *mut PyObject, base: c_int) -> *mut PyObject; } #[cfg(Py_3_13)] pub const Py_ASNATIVEBYTES_DEFAULTS: c_int = -1; #[cfg(Py_3_13)] pub const Py_ASNATIVEBYTES_BIG_ENDIAN: c_int = 0; #[cfg(Py_3_13)] pub const Py_ASNATIVEBYTES_LITTLE_ENDIAN: c_int = 1; #[cfg(Py_3_13)] pub const Py_ASNATIVEBYTES_NATIVE_ENDIAN: c_int = 3; #[cfg(Py_3_13)] pub const Py_ASNATIVEBYTES_UNSIGNED_BUFFER: c_int = 4; #[cfg(Py_3_13)] pub const Py_ASNATIVEBYTES_REJECT_NEGATIVE: c_int = 8; extern "C" { // skipped _PyLong_Sign #[cfg(Py_3_13)] pub fn PyLong_AsNativeBytes( v: *mut PyObject, buffer: *mut c_void, n_bytes: Py_ssize_t, flags: c_int, ) -> Py_ssize_t; #[cfg(Py_3_13)] pub fn PyLong_FromNativeBytes( buffer: *const c_void, n_bytes: size_t, flags: c_int, ) -> *mut PyObject; #[cfg(Py_3_13)] pub fn PyLong_FromUnsignedNativeBytes( buffer: *const c_void, n_bytes: size_t, flags: c_int, ) -> *mut PyObject; // skipped PyUnstable_Long_IsCompact // skipped PyUnstable_Long_CompactValue #[cfg_attr(PyPy, link_name = "_PyPyLong_FromByteArray")] pub fn _PyLong_FromByteArray( bytes: *const c_uchar, n: size_t, little_endian: c_int, is_signed: c_int, ) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "_PyPyLong_AsByteArrayO")] pub fn _PyLong_AsByteArray( v: *mut PyLongObject, bytes: *mut c_uchar, n: size_t, little_endian: c_int, is_signed: c_int, ) -> c_int; // skipped _PyLong_GCD }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/lock.rs
use std::marker::PhantomPinned; use std::sync::atomic::AtomicU8; #[repr(transparent)] #[derive(Debug)] pub struct PyMutex { pub(crate) _bits: AtomicU8, pub(crate) _pin: PhantomPinned, } extern "C" { pub fn PyMutex_Lock(m: *mut PyMutex); pub fn PyMutex_Unlock(m: *mut PyMutex); }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/pyerrors.rs
use crate::PyObject; #[cfg(not(any(PyPy, GraalPy)))] use crate::Py_ssize_t; #[repr(C)] #[derive(Debug)] pub struct PyBaseExceptionObject { pub ob_base: PyObject, #[cfg(not(any(PyPy, GraalPy)))] pub dict: *mut PyObject, #[cfg(not(any(PyPy, GraalPy)))] pub args: *mut PyObject, #[cfg(all(Py_3_11, not(any(PyPy, GraalPy))))] pub notes: *mut PyObject, #[cfg(not(any(PyPy, GraalPy)))] pub traceback: *mut PyObject, #[cfg(not(any(PyPy, GraalPy)))] pub context: *mut PyObject, #[cfg(not(any(PyPy, GraalPy)))] pub cause: *mut PyObject, #[cfg(not(any(PyPy, GraalPy)))] pub suppress_context: char, } #[cfg(not(any(PyPy, GraalPy)))] #[repr(C)] #[derive(Debug)] pub struct PySyntaxErrorObject { pub ob_base: PyObject, pub dict: *mut PyObject, pub args: *mut PyObject, #[cfg(Py_3_11)] pub notes: *mut PyObject, pub traceback: *mut PyObject, pub context: *mut PyObject, pub cause: *mut PyObject, pub suppress_context: char, pub msg: *mut PyObject, pub filename: *mut PyObject, pub lineno: *mut PyObject, pub offset: *mut PyObject, #[cfg(Py_3_10)] pub end_lineno: *mut PyObject, #[cfg(Py_3_10)] pub end_offset: *mut PyObject, pub text: *mut PyObject, pub print_file_and_line: *mut PyObject, } #[cfg(not(any(PyPy, GraalPy)))] #[repr(C)] #[derive(Debug)] pub struct PyImportErrorObject { pub ob_base: PyObject, pub dict: *mut PyObject, pub args: *mut PyObject, #[cfg(Py_3_11)] pub notes: *mut PyObject, pub traceback: *mut PyObject, pub context: *mut PyObject, pub cause: *mut PyObject, pub suppress_context: char, pub msg: *mut PyObject, pub name: *mut PyObject, pub path: *mut PyObject, #[cfg(Py_3_12)] pub name_from: *mut PyObject, } #[cfg(not(any(PyPy, GraalPy)))] #[repr(C)] #[derive(Debug)] pub struct PyUnicodeErrorObject { pub ob_base: PyObject, pub dict: *mut PyObject, pub args: *mut PyObject, #[cfg(Py_3_11)] pub notes: *mut PyObject, pub traceback: *mut PyObject, pub context: *mut PyObject, pub cause: *mut PyObject, pub suppress_context: char, pub encoding: *mut PyObject, pub object: *mut PyObject, pub start: Py_ssize_t, pub end: Py_ssize_t, pub reason: *mut PyObject, } #[cfg(not(any(PyPy, GraalPy)))] #[repr(C)] #[derive(Debug)] pub struct PySystemExitObject { pub ob_base: PyObject, pub dict: *mut PyObject, pub args: *mut PyObject, #[cfg(Py_3_11)] pub notes: *mut PyObject, pub traceback: *mut PyObject, pub context: *mut PyObject, pub cause: *mut PyObject, pub suppress_context: char, pub code: *mut PyObject, } #[cfg(not(any(PyPy, GraalPy)))] #[repr(C)] #[derive(Debug)] pub struct PyOSErrorObject { pub ob_base: PyObject, pub dict: *mut PyObject, pub args: *mut PyObject, #[cfg(Py_3_11)] pub notes: *mut PyObject, pub traceback: *mut PyObject, pub context: *mut PyObject, pub cause: *mut PyObject, pub suppress_context: char, pub myerrno: *mut PyObject, pub strerror: *mut PyObject, pub filename: *mut PyObject, pub filename2: *mut PyObject, #[cfg(windows)] pub winerror: *mut PyObject, pub written: Py_ssize_t, } #[repr(C)] #[derive(Debug)] pub struct PyStopIterationObject { pub ob_base: PyObject, #[cfg(not(any(PyPy, GraalPy)))] pub dict: *mut PyObject, #[cfg(not(any(PyPy, GraalPy)))] pub args: *mut PyObject, #[cfg(all(Py_3_11, not(any(PyPy, GraalPy))))] pub notes: *mut PyObject, #[cfg(not(any(PyPy, GraalPy)))] pub traceback: *mut PyObject, #[cfg(not(any(PyPy, GraalPy)))] pub context: *mut PyObject, #[cfg(not(any(PyPy, GraalPy)))] pub cause: *mut PyObject, #[cfg(not(any(PyPy, GraalPy)))] pub suppress_context: char, pub value: *mut PyObject, } // skipped _PyErr_ChainExceptions // skipped PyNameErrorObject // skipped PyAttributeErrorObject // skipped PyEnvironmentErrorObject // skipped PyWindowsErrorObject // skipped _PyErr_SetKeyError // skipped _PyErr_GetTopmostException // skipped _PyErr_GetExcInfo // skipped PyErr_SetFromErrnoWithUnicodeFilename // skipped _PyErr_FormatFromCause // skipped PyErr_SetFromWindowsErrWithUnicodeFilename // skipped PyErr_SetExcFromWindowsErrWithUnicodeFilename // skipped _PyErr_TrySetFromCause // skipped PySignal_SetWakeupFd // skipped _PyErr_CheckSignals // skipped PyErr_SyntaxLocationObject // skipped PyErr_RangedSyntaxLocationObject // skipped PyErr_ProgramTextObject // skipped _PyErr_ProgramDecodedTextObject // skipped _PyUnicodeTranslateError_Create // skipped _PyErr_WriteUnraisableMsg // skipped _Py_FatalErrorFunc // skipped _Py_FatalErrorFormat // skipped Py_FatalError
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/abstract_.rs
use crate::{PyObject, Py_ssize_t}; use std::os::raw::{c_char, c_int}; #[cfg(not(Py_3_11))] use crate::Py_buffer; #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))] use crate::{ vectorcallfunc, PyCallable_Check, PyThreadState, PyThreadState_GET, PyTuple_Check, PyType_HasFeature, Py_TPFLAGS_HAVE_VECTORCALL, }; #[cfg(Py_3_8)] use libc::size_t; extern "C" { #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))] pub fn _PyStack_AsDict(values: *const *mut PyObject, kwnames: *mut PyObject) -> *mut PyObject; } #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))] const _PY_FASTCALL_SMALL_STACK: size_t = 5; extern "C" { #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))] pub fn _Py_CheckFunctionResult( tstate: *mut PyThreadState, callable: *mut PyObject, result: *mut PyObject, where_: *const c_char, ) -> *mut PyObject; #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))] pub fn _PyObject_MakeTpCall( tstate: *mut PyThreadState, callable: *mut PyObject, args: *const *mut PyObject, nargs: Py_ssize_t, keywords: *mut PyObject, ) -> *mut PyObject; } #[cfg(Py_3_8)] pub const PY_VECTORCALL_ARGUMENTS_OFFSET: size_t = 1 << (8 * std::mem::size_of::<size_t>() as size_t - 1); #[cfg(Py_3_8)] #[inline(always)] pub unsafe fn PyVectorcall_NARGS(n: size_t) -> Py_ssize_t { let n = n & !PY_VECTORCALL_ARGUMENTS_OFFSET; n.try_into().expect("cannot fail due to mask") } #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))] #[inline(always)] pub unsafe fn PyVectorcall_Function(callable: *mut PyObject) -> Option<vectorcallfunc> { assert!(!callable.is_null()); let tp = crate::Py_TYPE(callable); if PyType_HasFeature(tp, Py_TPFLAGS_HAVE_VECTORCALL) == 0 { return None; } assert!(PyCallable_Check(callable) > 0); let offset = (*tp).tp_vectorcall_offset; assert!(offset > 0); let ptr = callable.cast::<c_char>().offset(offset).cast(); *ptr } #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))] #[inline(always)] pub unsafe fn _PyObject_VectorcallTstate( tstate: *mut PyThreadState, callable: *mut PyObject, args: *const *mut PyObject, nargsf: size_t, kwnames: *mut PyObject, ) -> *mut PyObject { assert!(kwnames.is_null() || PyTuple_Check(kwnames) > 0); assert!(!args.is_null() || PyVectorcall_NARGS(nargsf) == 0); match PyVectorcall_Function(callable) { None => { let nargs = PyVectorcall_NARGS(nargsf); _PyObject_MakeTpCall(tstate, callable, args, nargs, kwnames) } Some(func) => { let res = func(callable, args, nargsf, kwnames); _Py_CheckFunctionResult(tstate, callable, res, std::ptr::null_mut()) } } } #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))] #[inline(always)] pub unsafe fn PyObject_Vectorcall( callable: *mut PyObject, args: *const *mut PyObject, nargsf: size_t, kwnames: *mut PyObject, ) -> *mut PyObject { _PyObject_VectorcallTstate(PyThreadState_GET(), callable, args, nargsf, kwnames) } extern "C" { #[cfg(all(PyPy, Py_3_8))] #[cfg_attr(not(Py_3_9), link_name = "_PyPyObject_Vectorcall")] #[cfg_attr(Py_3_9, link_name = "PyPyObject_Vectorcall")] pub fn PyObject_Vectorcall( callable: *mut PyObject, args: *const *mut PyObject, nargsf: size_t, kwnames: *mut PyObject, ) -> *mut PyObject; #[cfg(Py_3_8)] #[cfg_attr( all(not(any(PyPy, GraalPy)), not(Py_3_9)), link_name = "_PyObject_VectorcallDict" )] #[cfg_attr(all(PyPy, not(Py_3_9)), link_name = "_PyPyObject_VectorcallDict")] #[cfg_attr(all(PyPy, Py_3_9), link_name = "PyPyObject_VectorcallDict")] pub fn PyObject_VectorcallDict( callable: *mut PyObject, args: *const *mut PyObject, nargsf: size_t, kwdict: *mut PyObject, ) -> *mut PyObject; #[cfg(Py_3_8)] #[cfg_attr(not(any(Py_3_9, PyPy)), link_name = "_PyVectorcall_Call")] #[cfg_attr(PyPy, link_name = "PyPyVectorcall_Call")] pub fn PyVectorcall_Call( callable: *mut PyObject, tuple: *mut PyObject, dict: *mut PyObject, ) -> *mut PyObject; } #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))] #[inline(always)] pub unsafe fn _PyObject_FastCallTstate( tstate: *mut PyThreadState, func: *mut PyObject, args: *const *mut PyObject, nargs: Py_ssize_t, ) -> *mut PyObject { _PyObject_VectorcallTstate(tstate, func, args, nargs as size_t, std::ptr::null_mut()) } #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))] #[inline(always)] pub unsafe fn _PyObject_FastCall( func: *mut PyObject, args: *const *mut PyObject, nargs: Py_ssize_t, ) -> *mut PyObject { _PyObject_FastCallTstate(PyThreadState_GET(), func, args, nargs) } #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))] #[inline(always)] pub unsafe fn _PyObject_CallNoArg(func: *mut PyObject) -> *mut PyObject { _PyObject_VectorcallTstate( PyThreadState_GET(), func, std::ptr::null_mut(), 0, std::ptr::null_mut(), ) } extern "C" { #[cfg(PyPy)] #[link_name = "_PyPyObject_CallNoArg"] pub fn _PyObject_CallNoArg(func: *mut PyObject) -> *mut PyObject; } #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))] #[inline(always)] pub unsafe fn PyObject_CallOneArg(func: *mut PyObject, arg: *mut PyObject) -> *mut PyObject { assert!(!arg.is_null()); let args_array = [std::ptr::null_mut(), arg]; let args = args_array.as_ptr().offset(1); // For PY_VECTORCALL_ARGUMENTS_OFFSET let tstate = PyThreadState_GET(); let nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET; _PyObject_VectorcallTstate(tstate, func, args, nargsf, std::ptr::null_mut()) } extern "C" { #[cfg(all(Py_3_9, not(any(PyPy, GraalPy))))] pub fn PyObject_VectorcallMethod( name: *mut PyObject, args: *const *mut PyObject, nargsf: size_t, kwnames: *mut PyObject, ) -> *mut PyObject; } #[cfg(all(Py_3_9, not(any(PyPy, GraalPy))))] #[inline(always)] pub unsafe fn PyObject_CallMethodNoArgs( self_: *mut PyObject, name: *mut PyObject, ) -> *mut PyObject { PyObject_VectorcallMethod( name, &self_, 1 | PY_VECTORCALL_ARGUMENTS_OFFSET, std::ptr::null_mut(), ) } #[cfg(all(Py_3_9, not(any(PyPy, GraalPy))))] #[inline(always)] pub unsafe fn PyObject_CallMethodOneArg( self_: *mut PyObject, name: *mut PyObject, arg: *mut PyObject, ) -> *mut PyObject { let args = [self_, arg]; assert!(!arg.is_null()); PyObject_VectorcallMethod( name, args.as_ptr(), 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, std::ptr::null_mut(), ) } // skipped _PyObject_VectorcallMethodId // skipped _PyObject_CallMethodIdNoArgs // skipped _PyObject_CallMethodIdOneArg // skipped _PyObject_HasLen extern "C" { #[cfg_attr(PyPy, link_name = "PyPyObject_LengthHint")] pub fn PyObject_LengthHint(o: *mut PyObject, arg1: Py_ssize_t) -> Py_ssize_t; #[cfg(not(Py_3_11))] // moved to src/buffer.rs from 3.11 #[cfg(all(Py_3_9, not(any(PyPy, GraalPy))))] pub fn PyObject_CheckBuffer(obj: *mut PyObject) -> c_int; } #[cfg(not(any(Py_3_9, PyPy)))] #[inline] pub unsafe fn PyObject_CheckBuffer(o: *mut PyObject) -> c_int { let tp_as_buffer = (*crate::Py_TYPE(o)).tp_as_buffer; (!tp_as_buffer.is_null() && (*tp_as_buffer).bf_getbuffer.is_some()) as c_int } #[cfg(not(Py_3_11))] // moved to src/buffer.rs from 3.11 extern "C" { #[cfg_attr(PyPy, link_name = "PyPyObject_GetBuffer")] pub fn PyObject_GetBuffer(obj: *mut PyObject, view: *mut Py_buffer, flags: c_int) -> c_int; #[cfg_attr(PyPy, link_name = "PyPyBuffer_GetPointer")] pub fn PyBuffer_GetPointer( view: *mut Py_buffer, indices: *mut Py_ssize_t, ) -> *mut std::os::raw::c_void; #[cfg_attr(PyPy, link_name = "PyPyBuffer_SizeFromFormat")] pub fn PyBuffer_SizeFromFormat(format: *const c_char) -> Py_ssize_t; #[cfg_attr(PyPy, link_name = "PyPyBuffer_ToContiguous")] pub fn PyBuffer_ToContiguous( buf: *mut std::os::raw::c_void, view: *mut Py_buffer, len: Py_ssize_t, order: c_char, ) -> c_int; #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromContiguous")] pub fn PyBuffer_FromContiguous( view: *mut Py_buffer, buf: *mut std::os::raw::c_void, len: Py_ssize_t, order: c_char, ) -> c_int; pub fn PyObject_CopyData(dest: *mut PyObject, src: *mut PyObject) -> c_int; #[cfg_attr(PyPy, link_name = "PyPyBuffer_IsContiguous")] pub fn PyBuffer_IsContiguous(view: *const Py_buffer, fort: c_char) -> c_int; pub fn PyBuffer_FillContiguousStrides( ndims: c_int, shape: *mut Py_ssize_t, strides: *mut Py_ssize_t, itemsize: c_int, fort: c_char, ); #[cfg_attr(PyPy, link_name = "PyPyBuffer_FillInfo")] pub fn PyBuffer_FillInfo( view: *mut Py_buffer, o: *mut PyObject, buf: *mut std::os::raw::c_void, len: Py_ssize_t, readonly: c_int, flags: c_int, ) -> c_int; #[cfg_attr(PyPy, link_name = "PyPyBuffer_Release")] pub fn PyBuffer_Release(view: *mut Py_buffer); } // PyIter_Check defined in ffi/abstract_.rs // PyIndex_Check defined in ffi/abstract_.rs // Not defined here because this file is not compiled under the // limited API, but the macros need to be defined for 3.6, 3.7 which // predate the limited API changes. // skipped PySequence_ITEM pub const PY_ITERSEARCH_COUNT: c_int = 1; pub const PY_ITERSEARCH_INDEX: c_int = 2; pub const PY_ITERSEARCH_CONTAINS: c_int = 3; extern "C" { #[cfg(not(any(PyPy, GraalPy)))] pub fn _PySequence_IterSearch( seq: *mut PyObject, obj: *mut PyObject, operation: c_int, ) -> Py_ssize_t; } // skipped _PyObject_RealIsInstance // skipped _PyObject_RealIsSubclass // skipped _PySequence_BytesToCharpArray // skipped _Py_FreeCharPArray // skipped _Py_add_one_to_index_F // skipped _Py_add_one_to_index_C // skipped _Py_convert_optional_to_ssize_t // skipped _PyNumber_Index(*mut PyObject o)
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/object.rs
#[cfg(Py_3_8)] use crate::vectorcallfunc; use crate::{object, PyGetSetDef, PyMemberDef, PyMethodDef, PyObject, Py_ssize_t}; use std::mem; use std::os::raw::{c_char, c_int, c_uint, c_void}; // skipped private _Py_NewReference // skipped private _Py_NewReferenceNoTotal // skipped private _Py_ResurrectReference // skipped private _Py_GetGlobalRefTotal // skipped private _Py_GetRefTotal // skipped private _Py_GetLegacyRefTotal // skipped private _PyInterpreterState_GetRefTotal // skipped private _Py_Identifier // skipped private _Py_static_string_init // skipped private _Py_static_string // skipped private _Py_IDENTIFIER #[cfg(not(Py_3_11))] // moved to src/buffer.rs from Python mod bufferinfo { use crate::Py_ssize_t; use std::os::raw::{c_char, c_int, c_void}; use std::ptr; #[repr(C)] #[derive(Copy, Clone)] pub struct Py_buffer { pub buf: *mut c_void, /// Owned reference pub obj: *mut crate::PyObject, pub len: Py_ssize_t, pub itemsize: Py_ssize_t, pub readonly: c_int, pub ndim: c_int, pub format: *mut c_char, pub shape: *mut Py_ssize_t, pub strides: *mut Py_ssize_t, pub suboffsets: *mut Py_ssize_t, pub internal: *mut c_void, #[cfg(PyPy)] pub flags: c_int, #[cfg(PyPy)] pub _strides: [Py_ssize_t; PyBUF_MAX_NDIM as usize], #[cfg(PyPy)] pub _shape: [Py_ssize_t; PyBUF_MAX_NDIM as usize], } impl Py_buffer { #[allow(clippy::new_without_default)] pub const fn new() -> Self { Py_buffer { buf: ptr::null_mut(), obj: ptr::null_mut(), len: 0, itemsize: 0, readonly: 0, ndim: 0, format: ptr::null_mut(), shape: ptr::null_mut(), strides: ptr::null_mut(), suboffsets: ptr::null_mut(), internal: ptr::null_mut(), #[cfg(PyPy)] flags: 0, #[cfg(PyPy)] _strides: [0; PyBUF_MAX_NDIM as usize], #[cfg(PyPy)] _shape: [0; PyBUF_MAX_NDIM as usize], } } } pub type getbufferproc = unsafe extern "C" fn( arg1: *mut crate::PyObject, arg2: *mut Py_buffer, arg3: c_int, ) -> c_int; pub type releasebufferproc = unsafe extern "C" fn(arg1: *mut crate::PyObject, arg2: *mut Py_buffer); /// Maximum number of dimensions pub const PyBUF_MAX_NDIM: c_int = if cfg!(PyPy) { 36 } else { 64 }; /* Flags for getting buffers */ pub const PyBUF_SIMPLE: c_int = 0; pub const PyBUF_WRITABLE: c_int = 0x0001; /* we used to include an E, backwards compatible alias */ pub const PyBUF_WRITEABLE: c_int = PyBUF_WRITABLE; pub const PyBUF_FORMAT: c_int = 0x0004; pub const PyBUF_ND: c_int = 0x0008; pub const PyBUF_STRIDES: c_int = 0x0010 | PyBUF_ND; pub const PyBUF_C_CONTIGUOUS: c_int = 0x0020 | PyBUF_STRIDES; pub const PyBUF_F_CONTIGUOUS: c_int = 0x0040 | PyBUF_STRIDES; pub const PyBUF_ANY_CONTIGUOUS: c_int = 0x0080 | PyBUF_STRIDES; pub const PyBUF_INDIRECT: c_int = 0x0100 | PyBUF_STRIDES; pub const PyBUF_CONTIG: c_int = PyBUF_ND | PyBUF_WRITABLE; pub const PyBUF_CONTIG_RO: c_int = PyBUF_ND; pub const PyBUF_STRIDED: c_int = PyBUF_STRIDES | PyBUF_WRITABLE; pub const PyBUF_STRIDED_RO: c_int = PyBUF_STRIDES; pub const PyBUF_RECORDS: c_int = PyBUF_STRIDES | PyBUF_WRITABLE | PyBUF_FORMAT; pub const PyBUF_RECORDS_RO: c_int = PyBUF_STRIDES | PyBUF_FORMAT; pub const PyBUF_FULL: c_int = PyBUF_INDIRECT | PyBUF_WRITABLE | PyBUF_FORMAT; pub const PyBUF_FULL_RO: c_int = PyBUF_INDIRECT | PyBUF_FORMAT; pub const PyBUF_READ: c_int = 0x100; pub const PyBUF_WRITE: c_int = 0x200; } #[cfg(not(Py_3_11))] pub use self::bufferinfo::*; #[repr(C)] #[derive(Copy, Clone)] pub struct PyNumberMethods { pub nb_add: Option<object::binaryfunc>, pub nb_subtract: Option<object::binaryfunc>, pub nb_multiply: Option<object::binaryfunc>, pub nb_remainder: Option<object::binaryfunc>, pub nb_divmod: Option<object::binaryfunc>, pub nb_power: Option<object::ternaryfunc>, pub nb_negative: Option<object::unaryfunc>, pub nb_positive: Option<object::unaryfunc>, pub nb_absolute: Option<object::unaryfunc>, pub nb_bool: Option<object::inquiry>, pub nb_invert: Option<object::unaryfunc>, pub nb_lshift: Option<object::binaryfunc>, pub nb_rshift: Option<object::binaryfunc>, pub nb_and: Option<object::binaryfunc>, pub nb_xor: Option<object::binaryfunc>, pub nb_or: Option<object::binaryfunc>, pub nb_int: Option<object::unaryfunc>, pub nb_reserved: *mut c_void, pub nb_float: Option<object::unaryfunc>, pub nb_inplace_add: Option<object::binaryfunc>, pub nb_inplace_subtract: Option<object::binaryfunc>, pub nb_inplace_multiply: Option<object::binaryfunc>, pub nb_inplace_remainder: Option<object::binaryfunc>, pub nb_inplace_power: Option<object::ternaryfunc>, pub nb_inplace_lshift: Option<object::binaryfunc>, pub nb_inplace_rshift: Option<object::binaryfunc>, pub nb_inplace_and: Option<object::binaryfunc>, pub nb_inplace_xor: Option<object::binaryfunc>, pub nb_inplace_or: Option<object::binaryfunc>, pub nb_floor_divide: Option<object::binaryfunc>, pub nb_true_divide: Option<object::binaryfunc>, pub nb_inplace_floor_divide: Option<object::binaryfunc>, pub nb_inplace_true_divide: Option<object::binaryfunc>, pub nb_index: Option<object::unaryfunc>, pub nb_matrix_multiply: Option<object::binaryfunc>, pub nb_inplace_matrix_multiply: Option<object::binaryfunc>, } #[repr(C)] #[derive(Clone)] pub struct PySequenceMethods { pub sq_length: Option<object::lenfunc>, pub sq_concat: Option<object::binaryfunc>, pub sq_repeat: Option<object::ssizeargfunc>, pub sq_item: Option<object::ssizeargfunc>, pub was_sq_slice: *mut c_void, pub sq_ass_item: Option<object::ssizeobjargproc>, pub was_sq_ass_slice: *mut c_void, pub sq_contains: Option<object::objobjproc>, pub sq_inplace_concat: Option<object::binaryfunc>, pub sq_inplace_repeat: Option<object::ssizeargfunc>, } #[repr(C)] #[derive(Clone, Default)] pub struct PyMappingMethods { pub mp_length: Option<object::lenfunc>, pub mp_subscript: Option<object::binaryfunc>, pub mp_ass_subscript: Option<object::objobjargproc>, } #[cfg(Py_3_10)] pub type sendfunc = unsafe extern "C" fn( iter: *mut PyObject, value: *mut PyObject, result: *mut *mut PyObject, ) -> object::PySendResult; #[repr(C)] #[derive(Clone, Default)] pub struct PyAsyncMethods { pub am_await: Option<object::unaryfunc>, pub am_aiter: Option<object::unaryfunc>, pub am_anext: Option<object::unaryfunc>, #[cfg(Py_3_10)] pub am_send: Option<sendfunc>, } #[repr(C)] #[derive(Clone, Default)] pub struct PyBufferProcs { pub bf_getbuffer: Option<crate::getbufferproc>, pub bf_releasebuffer: Option<crate::releasebufferproc>, } pub type printfunc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut ::libc::FILE, arg3: c_int) -> c_int; #[repr(C)] #[derive(Debug)] pub struct PyTypeObject { pub ob_base: object::PyVarObject, #[cfg(GraalPy)] pub ob_size: Py_ssize_t, pub tp_name: *const c_char, pub tp_basicsize: Py_ssize_t, pub tp_itemsize: Py_ssize_t, pub tp_dealloc: Option<object::destructor>, #[cfg(not(Py_3_8))] pub tp_print: Option<printfunc>, #[cfg(Py_3_8)] pub tp_vectorcall_offset: Py_ssize_t, pub tp_getattr: Option<object::getattrfunc>, pub tp_setattr: Option<object::setattrfunc>, pub tp_as_async: *mut PyAsyncMethods, pub tp_repr: Option<object::reprfunc>, pub tp_as_number: *mut PyNumberMethods, pub tp_as_sequence: *mut PySequenceMethods, pub tp_as_mapping: *mut PyMappingMethods, pub tp_hash: Option<object::hashfunc>, pub tp_call: Option<object::ternaryfunc>, pub tp_str: Option<object::reprfunc>, pub tp_getattro: Option<object::getattrofunc>, pub tp_setattro: Option<object::setattrofunc>, pub tp_as_buffer: *mut PyBufferProcs, #[cfg(not(Py_GIL_DISABLED))] pub tp_flags: std::os::raw::c_ulong, #[cfg(Py_GIL_DISABLED)] pub tp_flags: crate::impl_::AtomicCULong, pub tp_doc: *const c_char, pub tp_traverse: Option<object::traverseproc>, pub tp_clear: Option<object::inquiry>, pub tp_richcompare: Option<object::richcmpfunc>, pub tp_weaklistoffset: Py_ssize_t, pub tp_iter: Option<object::getiterfunc>, pub tp_iternext: Option<object::iternextfunc>, pub tp_methods: *mut PyMethodDef, pub tp_members: *mut PyMemberDef, pub tp_getset: *mut PyGetSetDef, pub tp_base: *mut PyTypeObject, pub tp_dict: *mut object::PyObject, pub tp_descr_get: Option<object::descrgetfunc>, pub tp_descr_set: Option<object::descrsetfunc>, pub tp_dictoffset: Py_ssize_t, pub tp_init: Option<object::initproc>, pub tp_alloc: Option<object::allocfunc>, pub tp_new: Option<object::newfunc>, pub tp_free: Option<object::freefunc>, pub tp_is_gc: Option<object::inquiry>, pub tp_bases: *mut object::PyObject, pub tp_mro: *mut object::PyObject, pub tp_cache: *mut object::PyObject, pub tp_subclasses: *mut object::PyObject, pub tp_weaklist: *mut object::PyObject, pub tp_del: Option<object::destructor>, pub tp_version_tag: c_uint, pub tp_finalize: Option<object::destructor>, #[cfg(Py_3_8)] pub tp_vectorcall: Option<vectorcallfunc>, #[cfg(Py_3_12)] pub tp_watched: c_char, #[cfg(any(all(PyPy, Py_3_8, not(Py_3_10)), all(not(PyPy), Py_3_8, not(Py_3_9))))] pub tp_print: Option<printfunc>, #[cfg(all(PyPy, not(Py_3_10)))] pub tp_pypy_flags: std::os::raw::c_long, #[cfg(py_sys_config = "COUNT_ALLOCS")] pub tp_allocs: Py_ssize_t, #[cfg(py_sys_config = "COUNT_ALLOCS")] pub tp_frees: Py_ssize_t, #[cfg(py_sys_config = "COUNT_ALLOCS")] pub tp_maxalloc: Py_ssize_t, #[cfg(py_sys_config = "COUNT_ALLOCS")] pub tp_prev: *mut PyTypeObject, #[cfg(py_sys_config = "COUNT_ALLOCS")] pub tp_next: *mut PyTypeObject, } #[cfg(Py_3_11)] #[repr(C)] #[derive(Clone)] struct _specialization_cache { getitem: *mut PyObject, #[cfg(Py_3_12)] getitem_version: u32, #[cfg(Py_3_13)] init: *mut PyObject, } #[repr(C)] pub struct PyHeapTypeObject { pub ht_type: PyTypeObject, pub as_async: PyAsyncMethods, pub as_number: PyNumberMethods, pub as_mapping: PyMappingMethods, pub as_sequence: PySequenceMethods, pub as_buffer: PyBufferProcs, pub ht_name: *mut object::PyObject, pub ht_slots: *mut object::PyObject, pub ht_qualname: *mut object::PyObject, #[cfg(not(PyPy))] pub ht_cached_keys: *mut c_void, #[cfg(Py_3_9)] pub ht_module: *mut object::PyObject, #[cfg(Py_3_11)] _ht_tpname: *mut c_char, #[cfg(Py_3_11)] _spec_cache: _specialization_cache, } impl Default for PyHeapTypeObject { #[inline] fn default() -> Self { unsafe { mem::zeroed() } } } #[inline] #[cfg(not(Py_3_11))] pub unsafe fn PyHeapType_GET_MEMBERS(etype: *mut PyHeapTypeObject) -> *mut PyMemberDef { let py_type = object::Py_TYPE(etype as *mut object::PyObject); let ptr = etype.offset((*py_type).tp_basicsize); ptr as *mut PyMemberDef } // skipped private _PyType_Name // skipped private _PyType_Lookup // skipped private _PyType_LookupRef extern "C" { #[cfg(Py_3_12)] pub fn PyType_GetDict(o: *mut PyTypeObject) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyObject_Print")] pub fn PyObject_Print(o: *mut PyObject, fp: *mut ::libc::FILE, flags: c_int) -> c_int; // skipped private _Py_BreakPoint // skipped private _PyObject_Dump // skipped _PyObject_GetAttrId // skipped private _PyObject_GetDictPtr pub fn PyObject_CallFinalizer(arg1: *mut PyObject); #[cfg_attr(PyPy, link_name = "PyPyObject_CallFinalizerFromDealloc")] pub fn PyObject_CallFinalizerFromDealloc(arg1: *mut PyObject) -> c_int; // skipped private _PyObject_GenericGetAttrWithDict // skipped private _PyObject_GenericSetAttrWithDict // skipped private _PyObject_FunctionStr } // skipped Py_SETREF // skipped Py_XSETREF // skipped private _PyObject_ASSERT_FROM // skipped private _PyObject_ASSERT_WITH_MSG // skipped private _PyObject_ASSERT // skipped private _PyObject_ASSERT_FAILED_MSG // skipped private _PyObject_AssertFailed // skipped private _PyTrash_begin // skipped private _PyTrash_end // skipped _PyTrash_thread_deposit_object // skipped _PyTrash_thread_destroy_chain // skipped Py_TRASHCAN_BEGIN // skipped Py_TRASHCAN_END // skipped PyObject_GetItemData // skipped PyObject_VisitManagedDict // skipped _PyObject_SetManagedDict // skipped PyObject_ClearManagedDict // skipped TYPE_MAX_WATCHERS // skipped PyType_WatchCallback // skipped PyType_AddWatcher // skipped PyType_ClearWatcher // skipped PyType_Watch // skipped PyType_Unwatch // skipped PyUnstable_Type_AssignVersionTag // skipped PyRefTracerEvent // skipped PyRefTracer // skipped PyRefTracer_SetTracer // skipped PyRefTracer_GetTracer
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/pydebug.rs
use std::os::raw::{c_char, c_int}; #[cfg(not(Py_LIMITED_API))] #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { #[deprecated(note = "Python 3.12")] #[cfg_attr(PyPy, link_name = "PyPy_DebugFlag")] pub static mut Py_DebugFlag: c_int; #[deprecated(note = "Python 3.12")] #[cfg_attr(PyPy, link_name = "PyPy_VerboseFlag")] pub static mut Py_VerboseFlag: c_int; #[deprecated(note = "Python 3.12")] pub static mut Py_QuietFlag: c_int; #[deprecated(note = "Python 3.12")] #[cfg_attr(PyPy, link_name = "PyPy_InteractiveFlag")] pub static mut Py_InteractiveFlag: c_int; #[deprecated(note = "Python 3.12")] #[cfg_attr(PyPy, link_name = "PyPy_InspectFlag")] pub static mut Py_InspectFlag: c_int; #[deprecated(note = "Python 3.12")] #[cfg_attr(PyPy, link_name = "PyPy_OptimizeFlag")] pub static mut Py_OptimizeFlag: c_int; #[deprecated(note = "Python 3.12")] #[cfg_attr(PyPy, link_name = "PyPy_NoSiteFlag")] pub static mut Py_NoSiteFlag: c_int; #[deprecated(note = "Python 3.12")] #[cfg_attr(PyPy, link_name = "PyPy_BytesWarningFlag")] pub static mut Py_BytesWarningFlag: c_int; #[deprecated(note = "Python 3.12")] #[cfg_attr(PyPy, link_name = "PyPy_UseClassExceptionsFlag")] pub static mut Py_UseClassExceptionsFlag: c_int; #[deprecated(note = "Python 3.12")] #[cfg_attr(PyPy, link_name = "PyPy_FrozenFlag")] pub static mut Py_FrozenFlag: c_int; #[deprecated(note = "Python 3.12")] #[cfg_attr(PyPy, link_name = "PyPy_IgnoreEnvironmentFlag")] pub static mut Py_IgnoreEnvironmentFlag: c_int; #[deprecated(note = "Python 3.12")] #[cfg_attr(PyPy, link_name = "PyPy_DontWriteBytecodeFlag")] pub static mut Py_DontWriteBytecodeFlag: c_int; #[deprecated(note = "Python 3.12")] #[cfg_attr(PyPy, link_name = "PyPy_NoUserSiteDirectory")] pub static mut Py_NoUserSiteDirectory: c_int; #[deprecated(note = "Python 3.12")] pub static mut Py_UnbufferedStdioFlag: c_int; #[cfg_attr(PyPy, link_name = "PyPy_HashRandomizationFlag")] pub static mut Py_HashRandomizationFlag: c_int; #[deprecated(note = "Python 3.12")] pub static mut Py_IsolatedFlag: c_int; #[cfg(windows)] #[deprecated(note = "Python 3.12")] pub static mut Py_LegacyWindowsFSEncodingFlag: c_int; #[cfg(windows)] #[deprecated(note = "Python 3.12")] pub static mut Py_LegacyWindowsStdioFlag: c_int; } extern "C" { #[cfg(Py_3_11)] pub fn Py_GETENV(name: *const c_char) -> *mut c_char; } #[cfg(not(Py_3_11))] #[inline(always)] pub unsafe fn Py_GETENV(name: *const c_char) -> *mut c_char { #[allow(deprecated)] if Py_IgnoreEnvironmentFlag != 0 { std::ptr::null_mut() } else { libc::getenv(name) } }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/dictobject.rs
use crate::object::*; use crate::pyport::Py_ssize_t; use std::os::raw::c_int; opaque_struct!(PyDictKeysObject); #[cfg(Py_3_11)] opaque_struct!(PyDictValues); #[cfg(not(GraalPy))] #[repr(C)] #[derive(Debug)] pub struct PyDictObject { pub ob_base: PyObject, pub ma_used: Py_ssize_t, #[cfg_attr( Py_3_12, deprecated(note = "Deprecated in Python 3.12 and will be removed in the future.") )] pub ma_version_tag: u64, pub ma_keys: *mut PyDictKeysObject, #[cfg(not(Py_3_11))] pub ma_values: *mut *mut PyObject, #[cfg(Py_3_11)] pub ma_values: *mut PyDictValues, } extern "C" { // skipped _PyDict_GetItem_KnownHash // skipped _PyDict_GetItemIdWithError // skipped _PyDict_GetItemStringWithError // skipped PyDict_SetDefault pub fn _PyDict_SetItem_KnownHash( mp: *mut PyObject, key: *mut PyObject, item: *mut PyObject, hash: crate::Py_hash_t, ) -> c_int; // skipped _PyDict_DelItem_KnownHash // skipped _PyDict_DelItemIf // skipped _PyDict_NewKeysForClass pub fn _PyDict_Next( mp: *mut PyObject, pos: *mut Py_ssize_t, key: *mut *mut PyObject, value: *mut *mut PyObject, hash: *mut crate::Py_hash_t, ) -> c_int; // skipped PyDict_GET_SIZE // skipped _PyDict_ContainsId pub fn _PyDict_NewPresized(minused: Py_ssize_t) -> *mut PyObject; // skipped _PyDict_MaybeUntrack // skipped _PyDict_HasOnlyStringKeys // skipped _PyDict_KeysSize // skipped _PyDict_SizeOf // skipped _PyDict_Pop // skipped _PyDict_Pop_KnownHash // skipped _PyDict_FromKeys // skipped _PyDict_HasSplitTable // skipped _PyDict_MergeEx // skipped _PyDict_SetItemId // skipped _PyDict_DelItemId // skipped _PyDict_DebugMallocStats // skipped _PyObjectDict_SetItem // skipped _PyDict_LoadGlobal // skipped _PyDict_GetItemHint // skipped _PyDictViewObject // skipped _PyDictView_New // skipped _PyDictView_Intersect #[cfg(Py_3_10)] pub fn _PyDict_Contains_KnownHash( op: *mut PyObject, key: *mut PyObject, hash: crate::Py_hash_t, ) -> c_int; #[cfg(not(Py_3_10))] pub fn _PyDict_Contains(mp: *mut PyObject, key: *mut PyObject, hash: Py_ssize_t) -> c_int; }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/pythonrun.rs
use crate::object::*; #[cfg(not(any(PyPy, GraalPy, Py_LIMITED_API, Py_3_10)))] use crate::pyarena::PyArena; use crate::PyCompilerFlags; #[cfg(not(any(PyPy, GraalPy, Py_3_10)))] use crate::{_mod, _node}; use libc::FILE; use std::os::raw::{c_char, c_int}; extern "C" { pub fn PyRun_SimpleStringFlags(arg1: *const c_char, arg2: *mut PyCompilerFlags) -> c_int; pub fn _PyRun_SimpleFileObject( fp: *mut FILE, filename: *mut PyObject, closeit: c_int, flags: *mut PyCompilerFlags, ) -> c_int; pub fn PyRun_AnyFileExFlags( fp: *mut FILE, filename: *const c_char, closeit: c_int, flags: *mut PyCompilerFlags, ) -> c_int; pub fn _PyRun_AnyFileObject( fp: *mut FILE, filename: *mut PyObject, closeit: c_int, flags: *mut PyCompilerFlags, ) -> c_int; pub fn PyRun_SimpleFileExFlags( fp: *mut FILE, filename: *const c_char, closeit: c_int, flags: *mut PyCompilerFlags, ) -> c_int; pub fn PyRun_InteractiveOneFlags( fp: *mut FILE, filename: *const c_char, flags: *mut PyCompilerFlags, ) -> c_int; pub fn PyRun_InteractiveOneObject( fp: *mut FILE, filename: *mut PyObject, flags: *mut PyCompilerFlags, ) -> c_int; pub fn PyRun_InteractiveLoopFlags( fp: *mut FILE, filename: *const c_char, flags: *mut PyCompilerFlags, ) -> c_int; pub fn _PyRun_InteractiveLoopObject( fp: *mut FILE, filename: *mut PyObject, flags: *mut PyCompilerFlags, ) -> c_int; #[cfg(not(any(PyPy, GraalPy, Py_3_10)))] pub fn PyParser_ASTFromString( s: *const c_char, filename: *const c_char, start: c_int, flags: *mut PyCompilerFlags, arena: *mut PyArena, ) -> *mut _mod; #[cfg(not(any(PyPy, GraalPy, Py_3_10)))] pub fn PyParser_ASTFromStringObject( s: *const c_char, filename: *mut PyObject, start: c_int, flags: *mut PyCompilerFlags, arena: *mut PyArena, ) -> *mut _mod; #[cfg(not(any(PyPy, GraalPy, Py_3_10)))] pub fn PyParser_ASTFromFile( fp: *mut FILE, filename: *const c_char, enc: *const c_char, start: c_int, ps1: *const c_char, ps2: *const c_char, flags: *mut PyCompilerFlags, errcode: *mut c_int, arena: *mut PyArena, ) -> *mut _mod; #[cfg(not(any(PyPy, GraalPy, Py_3_10)))] pub fn PyParser_ASTFromFileObject( fp: *mut FILE, filename: *mut PyObject, enc: *const c_char, start: c_int, ps1: *const c_char, ps2: *const c_char, flags: *mut PyCompilerFlags, errcode: *mut c_int, arena: *mut PyArena, ) -> *mut _mod; } extern "C" { #[cfg_attr(PyPy, link_name = "PyPyRun_StringFlags")] pub fn PyRun_StringFlags( arg1: *const c_char, arg2: c_int, arg3: *mut PyObject, arg4: *mut PyObject, arg5: *mut PyCompilerFlags, ) -> *mut PyObject; #[cfg(not(any(PyPy, GraalPy)))] pub fn PyRun_FileExFlags( fp: *mut FILE, filename: *const c_char, start: c_int, globals: *mut PyObject, locals: *mut PyObject, closeit: c_int, flags: *mut PyCompilerFlags, ) -> *mut PyObject; #[cfg(not(any(PyPy, GraalPy)))] pub fn Py_CompileStringExFlags( str: *const c_char, filename: *const c_char, start: c_int, flags: *mut PyCompilerFlags, optimize: c_int, ) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] pub fn Py_CompileStringObject( str: *const c_char, filename: *mut PyObject, start: c_int, flags: *mut PyCompilerFlags, optimize: c_int, ) -> *mut PyObject; } #[inline] #[cfg(not(any(PyPy, GraalPy)))] pub unsafe fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int) -> *mut PyObject { Py_CompileStringExFlags(string, p, s, std::ptr::null_mut(), -1) } #[inline] #[cfg(not(any(PyPy, GraalPy)))] pub unsafe fn Py_CompileStringFlags( string: *const c_char, p: *const c_char, s: c_int, f: *mut PyCompilerFlags, ) -> *mut PyObject { Py_CompileStringExFlags(string, p, s, f, -1) } // skipped _Py_SourceAsString extern "C" { #[cfg_attr(PyPy, link_name = "PyPyRun_String")] pub fn PyRun_String( string: *const c_char, s: c_int, g: *mut PyObject, l: *mut PyObject, ) -> *mut PyObject; #[cfg(not(any(PyPy, GraalPy)))] pub fn PyRun_AnyFile(fp: *mut FILE, name: *const c_char) -> c_int; #[cfg(not(any(PyPy, GraalPy)))] pub fn PyRun_AnyFileEx(fp: *mut FILE, name: *const c_char, closeit: c_int) -> c_int; #[cfg(not(any(PyPy, GraalPy)))] pub fn PyRun_AnyFileFlags( arg1: *mut FILE, arg2: *const c_char, arg3: *mut PyCompilerFlags, ) -> c_int; #[cfg_attr(PyPy, link_name = "PyPyRun_SimpleString")] pub fn PyRun_SimpleString(s: *const c_char) -> c_int; #[cfg(not(any(PyPy, GraalPy)))] pub fn PyRun_SimpleFile(f: *mut FILE, p: *const c_char) -> c_int; #[cfg(not(any(PyPy, GraalPy)))] pub fn PyRun_SimpleFileEx(f: *mut FILE, p: *const c_char, c: c_int) -> c_int; #[cfg(not(any(PyPy, GraalPy)))] pub fn PyRun_InteractiveOne(f: *mut FILE, p: *const c_char) -> c_int; #[cfg(not(any(PyPy, GraalPy)))] pub fn PyRun_InteractiveLoop(f: *mut FILE, p: *const c_char) -> c_int; #[cfg_attr(PyPy, link_name = "PyPyRun_File")] pub fn PyRun_File( fp: *mut FILE, p: *const c_char, s: c_int, g: *mut PyObject, l: *mut PyObject, ) -> *mut PyObject; #[cfg(not(any(PyPy, GraalPy)))] pub fn PyRun_FileEx( fp: *mut FILE, p: *const c_char, s: c_int, g: *mut PyObject, l: *mut PyObject, c: c_int, ) -> *mut PyObject; #[cfg(not(any(PyPy, GraalPy)))] pub fn PyRun_FileFlags( fp: *mut FILE, p: *const c_char, s: c_int, g: *mut PyObject, l: *mut PyObject, flags: *mut PyCompilerFlags, ) -> *mut PyObject; } // skipped macro PyRun_String // skipped macro PyRun_AnyFile // skipped macro PyRun_AnyFileEx // skipped macro PyRun_AnyFileFlags extern "C" { #[cfg(not(any(PyPy, GraalPy, Py_3_10)))] #[cfg_attr(Py_3_9, deprecated(note = "Python 3.9"))] pub fn PyParser_SimpleParseStringFlags( arg1: *const c_char, arg2: c_int, arg3: c_int, ) -> *mut _node; #[cfg(not(any(PyPy, GraalPy, Py_3_10)))] #[cfg_attr(Py_3_9, deprecated(note = "Python 3.9"))] pub fn PyParser_SimpleParseStringFlagsFilename( arg1: *const c_char, arg2: *const c_char, arg3: c_int, arg4: c_int, ) -> *mut _node; #[cfg(not(any(PyPy, GraalPy, Py_3_10)))] #[cfg_attr(Py_3_9, deprecated(note = "Python 3.9"))] pub fn PyParser_SimpleParseFileFlags( arg1: *mut FILE, arg2: *const c_char, arg3: c_int, arg4: c_int, ) -> *mut _node; #[cfg(PyPy)] #[cfg_attr(PyPy, link_name = "PyPy_CompileStringFlags")] pub fn Py_CompileStringFlags( string: *const c_char, p: *const c_char, s: c_int, f: *mut PyCompilerFlags, ) -> *mut PyObject; }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/tupleobject.rs
use crate::object::*; #[cfg(not(PyPy))] use crate::pyport::Py_ssize_t; #[repr(C)] pub struct PyTupleObject { pub ob_base: PyVarObject, #[cfg(not(GraalPy))] pub ob_item: [*mut PyObject; 1], } // skipped _PyTuple_Resize // skipped _PyTuple_MaybeUntrack // skipped _PyTuple_CAST /// Macro, trading safety for speed #[inline] #[cfg(not(PyPy))] pub unsafe fn PyTuple_GET_SIZE(op: *mut PyObject) -> Py_ssize_t { Py_SIZE(op) } #[inline] #[cfg(not(any(PyPy, GraalPy)))] pub unsafe fn PyTuple_GET_ITEM(op: *mut PyObject, i: Py_ssize_t) -> *mut PyObject { *(*(op as *mut PyTupleObject)).ob_item.as_ptr().offset(i) } /// Macro, *only* to be used to fill in brand new tuples #[inline] #[cfg(not(any(PyPy, GraalPy)))] pub unsafe fn PyTuple_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) { *(*(op as *mut PyTupleObject)).ob_item.as_mut_ptr().offset(i) = v; } // skipped _PyTuple_DebugMallocStats
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/pyframe.rs
#[cfg(Py_3_11)] opaque_struct!(_PyInterpreterFrame);
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/weakrefobject.rs
#[cfg(not(any(PyPy, GraalPy)))] pub struct _PyWeakReference { pub ob_base: crate::PyObject, pub wr_object: *mut crate::PyObject, pub wr_callback: *mut crate::PyObject, pub hash: crate::Py_hash_t, pub wr_prev: *mut crate::PyWeakReference, pub wr_next: *mut crate::PyWeakReference, #[cfg(Py_3_11)] pub vectorcall: Option<crate::vectorcallfunc>, #[cfg(all(Py_3_13, Py_GIL_DISABLED))] pub weakrefs_lock: *mut crate::PyMutex, } // skipped _PyWeakref_GetWeakrefCount // skipped _PyWeakref_ClearRef // skipped PyWeakRef_GET_OBJECT
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/pylifecycle.rs
use crate::{PyConfig, PyPreConfig, PyStatus, Py_ssize_t}; use libc::wchar_t; use std::os::raw::{c_char, c_int}; // "private" functions in cpython/pylifecycle.h accepted in PEP 587 extern "C" { // skipped _Py_SetStandardStreamEncoding; pub fn Py_PreInitialize(src_config: *const PyPreConfig) -> PyStatus; pub fn Py_PreInitializeFromBytesArgs( src_config: *const PyPreConfig, argc: Py_ssize_t, argv: *mut *mut c_char, ) -> PyStatus; pub fn Py_PreInitializeFromArgs( src_config: *const PyPreConfig, argc: Py_ssize_t, argv: *mut *mut wchar_t, ) -> PyStatus; pub fn _Py_IsCoreInitialized() -> c_int; pub fn Py_InitializeFromConfig(config: *const PyConfig) -> PyStatus; pub fn _Py_InitializeMain() -> PyStatus; pub fn Py_RunMain() -> c_int; pub fn Py_ExitStatusException(status: PyStatus) -> !; // skipped _Py_RestoreSignals // skipped Py_FdIsInteractive // skipped _Py_FdIsInteractive // skipped _Py_SetProgramFullPath // skipped _Py_gitidentifier // skipped _Py_getversion // skipped _Py_IsFinalizing // skipped _PyOS_URandom // skipped _PyOS_URandomNonblock // skipped _Py_CoerceLegacyLocale // skipped _Py_LegacyLocaleDetected // skipped _Py_SetLocaleFromEnv } #[cfg(Py_3_12)] pub const PyInterpreterConfig_DEFAULT_GIL: c_int = 0; #[cfg(Py_3_12)] pub const PyInterpreterConfig_SHARED_GIL: c_int = 1; #[cfg(Py_3_12)] pub const PyInterpreterConfig_OWN_GIL: c_int = 2; #[cfg(Py_3_12)] #[repr(C)] pub struct PyInterpreterConfig { pub use_main_obmalloc: c_int, pub allow_fork: c_int, pub allow_exec: c_int, pub allow_threads: c_int, pub allow_daemon_threads: c_int, pub check_multi_interp_extensions: c_int, pub gil: c_int, } #[cfg(Py_3_12)] pub const _PyInterpreterConfig_INIT: PyInterpreterConfig = PyInterpreterConfig { use_main_obmalloc: 0, allow_fork: 0, allow_exec: 0, allow_threads: 1, allow_daemon_threads: 0, check_multi_interp_extensions: 1, gil: PyInterpreterConfig_OWN_GIL, }; #[cfg(Py_3_12)] pub const _PyInterpreterConfig_LEGACY_INIT: PyInterpreterConfig = PyInterpreterConfig { use_main_obmalloc: 1, allow_fork: 1, allow_exec: 1, allow_threads: 1, allow_daemon_threads: 1, check_multi_interp_extensions: 0, gil: PyInterpreterConfig_SHARED_GIL, }; extern "C" { #[cfg(Py_3_12)] pub fn Py_NewInterpreterFromConfig( tstate_p: *mut *mut crate::PyThreadState, config: *const PyInterpreterConfig, ) -> PyStatus; } // skipped atexit_datacallbackfunc // skipped _Py_AtExit
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/import.rs
use crate::{PyInterpreterState, PyObject}; #[cfg(not(PyPy))] use std::os::raw::c_uchar; use std::os::raw::{c_char, c_int}; // skipped PyInit__imp extern "C" { pub fn _PyImport_IsInitialized(state: *mut PyInterpreterState) -> c_int; // skipped _PyImport_GetModuleId pub fn _PyImport_SetModule(name: *mut PyObject, module: *mut PyObject) -> c_int; pub fn _PyImport_SetModuleString(name: *const c_char, module: *mut PyObject) -> c_int; pub fn _PyImport_AcquireLock(); pub fn _PyImport_ReleaseLock() -> c_int; #[cfg(not(Py_3_9))] pub fn _PyImport_FindBuiltin(name: *const c_char, modules: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_3_11))] pub fn _PyImport_FindExtensionObject(a: *mut PyObject, b: *mut PyObject) -> *mut PyObject; pub fn _PyImport_FixupBuiltin( module: *mut PyObject, name: *const c_char, modules: *mut PyObject, ) -> c_int; pub fn _PyImport_FixupExtensionObject( a: *mut PyObject, b: *mut PyObject, c: *mut PyObject, d: *mut PyObject, ) -> c_int; } #[cfg(not(PyPy))] #[repr(C)] #[derive(Copy, Clone)] pub struct _inittab { pub name: *const c_char, pub initfunc: Option<unsafe extern "C" fn() -> *mut PyObject>, } #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { #[cfg(not(PyPy))] pub static mut PyImport_Inittab: *mut _inittab; } extern "C" { #[cfg(not(PyPy))] pub fn PyImport_ExtendInittab(newtab: *mut _inittab) -> c_int; } #[cfg(not(PyPy))] #[repr(C)] #[derive(Copy, Clone)] pub struct _frozen { pub name: *const c_char, pub code: *const c_uchar, pub size: c_int, #[cfg(Py_3_11)] pub is_package: c_int, #[cfg(all(Py_3_11, not(Py_3_13)))] pub get_code: Option<unsafe extern "C" fn() -> *mut PyObject>, } #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { #[cfg(not(PyPy))] pub static mut PyImport_FrozenModules: *const _frozen; #[cfg(all(not(PyPy), Py_3_11))] pub static mut _PyImport_FrozenBootstrap: *const _frozen; #[cfg(all(not(PyPy), Py_3_11))] pub static mut _PyImport_FrozenStdlib: *const _frozen; #[cfg(all(not(PyPy), Py_3_11))] pub static mut _PyImport_FrozenTest: *const _frozen; }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/pymem.rs
use libc::size_t; use std::os::raw::c_void; extern "C" { #[cfg_attr(PyPy, link_name = "PyPyMem_RawMalloc")] pub fn PyMem_RawMalloc(size: size_t) -> *mut c_void; #[cfg_attr(PyPy, link_name = "PyPyMem_RawCalloc")] pub fn PyMem_RawCalloc(nelem: size_t, elsize: size_t) -> *mut c_void; #[cfg_attr(PyPy, link_name = "PyPyMem_RawRealloc")] pub fn PyMem_RawRealloc(ptr: *mut c_void, new_size: size_t) -> *mut c_void; #[cfg_attr(PyPy, link_name = "PyPyMem_RawFree")] pub fn PyMem_RawFree(ptr: *mut c_void); // skipped _PyMem_GetCurrentAllocatorName // skipped _PyMem_RawStrdup // skipped _PyMem_Strdup // skipped _PyMem_RawWcsdup } #[repr(C)] #[derive(Copy, Clone)] pub enum PyMemAllocatorDomain { PYMEM_DOMAIN_RAW, PYMEM_DOMAIN_MEM, PYMEM_DOMAIN_OBJ, } // skipped PyMemAllocatorName #[cfg(not(any(PyPy, GraalPy)))] #[repr(C)] #[derive(Copy, Clone)] pub struct PyMemAllocatorEx { pub ctx: *mut c_void, pub malloc: Option<extern "C" fn(ctx: *mut c_void, size: size_t) -> *mut c_void>, pub calloc: Option<extern "C" fn(ctx: *mut c_void, nelem: size_t, elsize: size_t) -> *mut c_void>, pub realloc: Option<extern "C" fn(ctx: *mut c_void, ptr: *mut c_void, new_size: size_t) -> *mut c_void>, pub free: Option<extern "C" fn(ctx: *mut c_void, ptr: *mut c_void)>, } extern "C" { #[cfg(not(any(PyPy, GraalPy)))] pub fn PyMem_GetAllocator(domain: PyMemAllocatorDomain, allocator: *mut PyMemAllocatorEx); #[cfg(not(any(PyPy, GraalPy)))] pub fn PyMem_SetAllocator(domain: PyMemAllocatorDomain, allocator: *mut PyMemAllocatorEx); #[cfg(not(any(PyPy, GraalPy)))] pub fn PyMem_SetupDebugHooks(); }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/mod.rs
pub(crate) mod abstract_; // skipped bytearrayobject.h pub(crate) mod bytesobject; #[cfg(not(PyPy))] pub(crate) mod ceval; pub(crate) mod code; pub(crate) mod compile; pub(crate) mod complexobject; #[cfg(Py_3_13)] pub(crate) mod critical_section; pub(crate) mod descrobject; #[cfg(not(PyPy))] pub(crate) mod dictobject; // skipped fileobject.h // skipped fileutils.h pub(crate) mod frameobject; pub(crate) mod funcobject; pub(crate) mod genobject; pub(crate) mod import; #[cfg(all(Py_3_8, not(PyPy)))] pub(crate) mod initconfig; // skipped interpreteridobject.h pub(crate) mod listobject; #[cfg(Py_3_13)] pub(crate) mod lock; pub(crate) mod longobject; #[cfg(all(Py_3_9, not(PyPy)))] pub(crate) mod methodobject; pub(crate) mod object; pub(crate) mod objimpl; pub(crate) mod pydebug; pub(crate) mod pyerrors; #[cfg(all(Py_3_8, not(PyPy)))] pub(crate) mod pylifecycle; pub(crate) mod pymem; pub(crate) mod pystate; pub(crate) mod pythonrun; // skipped sysmodule.h pub(crate) mod floatobject; pub(crate) mod pyframe; pub(crate) mod tupleobject; pub(crate) mod unicodeobject; pub(crate) mod weakrefobject; pub use self::abstract_::*; pub use self::bytesobject::*; #[cfg(not(PyPy))] pub use self::ceval::*; pub use self::code::*; pub use self::compile::*; pub use self::complexobject::*; #[cfg(Py_3_13)] pub use self::critical_section::*; pub use self::descrobject::*; #[cfg(not(PyPy))] pub use self::dictobject::*; pub use self::floatobject::*; pub use self::frameobject::*; pub use self::funcobject::*; pub use self::genobject::*; pub use self::import::*; #[cfg(all(Py_3_8, not(PyPy)))] pub use self::initconfig::*; pub use self::listobject::*; #[cfg(Py_3_13)] pub use self::lock::*; pub use self::longobject::*; #[cfg(all(Py_3_9, not(PyPy)))] pub use self::methodobject::*; pub use self::object::*; pub use self::objimpl::*; pub use self::pydebug::*; pub use self::pyerrors::*; #[cfg(Py_3_11)] pub use self::pyframe::*; #[cfg(all(Py_3_8, not(PyPy)))] pub use self::pylifecycle::*; pub use self::pymem::*; pub use self::pystate::*; pub use self::pythonrun::*; pub use self::tupleobject::*; pub use self::unicodeobject::*; #[cfg(not(any(PyPy, GraalPy)))] pub use self::weakrefobject::*;
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/cpython/critical_section.rs
#[cfg(Py_GIL_DISABLED)] use crate::PyMutex; use crate::PyObject; #[repr(C)] #[cfg(Py_GIL_DISABLED)] pub struct PyCriticalSection { _cs_prev: usize, _cs_mutex: *mut PyMutex, } #[repr(C)] #[cfg(Py_GIL_DISABLED)] pub struct PyCriticalSection2 { _cs_base: PyCriticalSection, _cs_mutex2: *mut PyMutex, } #[cfg(not(Py_GIL_DISABLED))] opaque_struct!(PyCriticalSection); #[cfg(not(Py_GIL_DISABLED))] opaque_struct!(PyCriticalSection2); extern "C" { pub fn PyCriticalSection_Begin(c: *mut PyCriticalSection, op: *mut PyObject); pub fn PyCriticalSection_End(c: *mut PyCriticalSection); pub fn PyCriticalSection2_Begin(c: *mut PyCriticalSection2, a: *mut PyObject, b: *mut PyObject); pub fn PyCriticalSection2_End(c: *mut PyCriticalSection2); }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src
lc_public_repos/langsmith-sdk/vendor/pyo3/pyo3-ffi/src/impl_/mod.rs
#[cfg(Py_GIL_DISABLED)] mod atomic_c_ulong { pub struct GetAtomicCULong<const WIDTH: usize>(); pub trait AtomicCULongType { type Type; } impl AtomicCULongType for GetAtomicCULong<32> { type Type = std::sync::atomic::AtomicU32; } impl AtomicCULongType for GetAtomicCULong<64> { type Type = std::sync::atomic::AtomicU64; } pub type TYPE = <GetAtomicCULong<{ std::mem::size_of::<std::os::raw::c_ulong>() * 8 }> as AtomicCULongType>::Type; } /// Typedef for an atomic integer to match the platform-dependent c_ulong type. #[cfg(Py_GIL_DISABLED)] #[doc(hidden)] pub type AtomicCULong = atomic_c_ulong::TYPE;
0
lc_public_repos/langsmith-sdk/vendor/pyo3
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/Cargo.toml
[package] name = "pyo3-examples" version = "0.0.0" publish = false edition = "2021" [dev-dependencies] pyo3 = { path = "..", features = ["auto-initialize", "extension-module"] } [[example]] name = "decorator" path = "decorator/src/lib.rs" crate-type = ["cdylib"] doc-scrape-examples = true
0
lc_public_repos/langsmith-sdk/vendor/pyo3
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/README.md
# PyO3 Examples These example crates are a collection of toy extension modules built with PyO3. They are all tested using `nox` in PyO3's CI. Below is a brief description of each of these: | Example | Description | | ------- | ----------- | | `decorator` | A project showcasing the example from the [Emulating callable objects](https://pyo3.rs/latest/class/call.html) chapter of the guide. | | `maturin-starter` | A template project which is configured to use [`maturin`](https://github.com/PyO3/maturin) for development. | | `setuptools-rust-starter` | A template project which is configured to use [`setuptools_rust`](https://github.com/PyO3/setuptools-rust/) for development. | | `plugin` | Illustrates how to use Python as a scripting language within a Rust application | Note that there are also other examples in the `pyo3-ffi/examples` directory that illustrate how to create rust extensions using raw FFI calls into the CPython C API instead of using PyO3's abstractions. ## Creating new projects from these examples To copy an example, use [`cargo-generate`](https://crates.io/crates/cargo-generate). Follow the commands below, replacing `<example>` with the example to start from: ```bash $ cargo install cargo-generate $ cargo generate --git https://github.com/PyO3/pyo3 examples/<example> ``` (`cargo generate` will take a little while to clone the PyO3 repo first; be patient when waiting for the command to run.)
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/getitem/noxfile.py
import nox @nox.session def python(session: nox.Session): session.env["MATURIN_PEP517_ARGS"] = "--profile=dev" session.install(".[dev]") session.run("pytest")
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/getitem/Cargo.toml
[package] name = "getitem" version = "0.1.0" edition = "2021" [lib] name = "getitem" crate-type = ["cdylib"] [dependencies] pyo3 = { path = "../../", features = ["extension-module"] } [workspace]
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/getitem/MANIFEST.in
include pyproject.toml Cargo.toml recursive-include src *
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/getitem/README.md
# getitem A project showcasing how to create a `__getitem__` override that also showcases how to deal with multiple incoming types ## Relevant Documentation Some of the relevant documentation links for this example: * Converting Slices to Indices: https://docs.rs/pyo3/latest/pyo3/types/struct.PySlice.html#method.indices * GetItem Docs: https://pyo3.rs/latest/class/protocols.html?highlight=__getitem__#mapping--sequence-types * Extract: https://pyo3.rs/latest/conversions/traits.html?highlight=extract#extract-and-the-frompyobject-trait * Downcast and getattr: https://pyo3.rs/v0.19.0/types.html?highlight=getattr#pyany ## Building and Testing To build this package, first install `maturin`: ```shell pip install maturin ``` To build and test use `maturin develop`: ```shell pip install -r requirements-dev.txt maturin develop pytest ``` Alternatively, install nox and run the tests inside an isolated environment: ```shell nox ``` ## Copying this example Use [`cargo-generate`](https://crates.io/crates/cargo-generate): ```bash $ cargo install cargo-generate $ cargo generate --git https://github.com/PyO3/pyo3 examples/decorator ``` (`cargo generate` will take a little while to clone the PyO3 repo first; be patient when waiting for the command to run.)
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/getitem/pyproject.toml
[build-system] requires = ["maturin>=1,<2"] build-backend = "maturin" [project] name = "getitem" version = "0.1.0" classifiers = [ "License :: OSI Approved :: MIT License", "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Programming Language :: Python", "Programming Language :: Rust", "Operating System :: POSIX", "Operating System :: MacOS :: MacOS X", ] [project.optional-dependencies] dev = ["pytest"]
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/getitem/cargo-generate.toml
[template] ignore = [".nox"] [hooks] pre = [".template/pre-script.rhai"]
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/getitem
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/getitem/tests/test_getitem.py
import getitem import pytest def test_simple(): container = getitem.ExampleContainer() assert container[3] == 3 assert container[4] == 4 assert container[-1] == -1 assert container[5:3] == 2 assert container[3:5] == 2 # test setitem, but this just displays, no return to check container[3:5] = 2 container[2] = 2 # and note we will get an error on this one since we didn't # add strings with pytest.raises(TypeError): container["foo"] = 2
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/getitem
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/getitem/src/lib.rs
// This is a very fake example of how to check __getitem__ parameter and handle appropriately use pyo3::exceptions::PyTypeError; use pyo3::prelude::*; use pyo3::types::PySlice; #[derive(FromPyObject)] enum IntOrSlice<'py> { Int(i32), Slice(Bound<'py, PySlice>), } #[pyclass] struct ExampleContainer { // represent the maximum length our container is pretending to be max_length: i32, } #[pymethods] impl ExampleContainer { #[new] fn new() -> Self { ExampleContainer { max_length: 100 } } fn __getitem__(&self, key: &Bound<'_, PyAny>) -> PyResult<i32> { if let Ok(position) = key.extract::<i32>() { return Ok(position); } else if let Ok(slice) = key.downcast::<PySlice>() { // METHOD 1 - the use PySliceIndices to help with bounds checking and for cases when only start or end are provided // in this case the start/stop/step all filled in to give valid values based on the max_length given let index = slice.indices(self.max_length as isize).unwrap(); let _delta = index.stop - index.start; // METHOD 2 - Do the getattr manually really only needed if you have some special cases for stop/_step not being present // convert to indices and this will help you deal with stop being the max length let start: i32 = slice.getattr("start")?.extract()?; // This particular example assumes stop is present, but note that if not present, this will cause us to return due to the // extract failing. Not needing custom code to deal with this is a good reason to use the Indices method. let stop: i32 = slice.getattr("stop")?.extract()?; // example of grabbing step since it is not always present let _step: i32 = match slice.getattr("step")?.extract() { // if no value found assume step is 1 Ok(v) => v, Err(_) => 1 as i32, }; // Use something like this if you don't support negative stepping and want to give users // leeway on how they provide their ordering let (start, stop) = if start > stop { (stop, start) } else { (start, stop) }; let delta = stop - start; return Ok(delta); } else { return Err(PyTypeError::new_err("Unsupported type")); } } fn __setitem__(&self, idx: IntOrSlice, value: u32) -> PyResult<()> { match idx { IntOrSlice::Slice(slice) => { let index = slice.indices(self.max_length as isize).unwrap(); println!( "Got a slice! {}-{}, step: {}, value: {}", index.start, index.stop, index.step, value ); } IntOrSlice::Int(index) => { println!("Got an index! {} : value: {}", index, value); } } Ok(()) } } #[pymodule(name = "getitem")] fn example(m: &Bound<'_, PyModule>) -> PyResult<()> { // ? -https://github.com/PyO3/maturin/issues/475 m.add_class::<ExampleContainer>()?; Ok(()) }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/getitem
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/getitem/.template/Cargo.toml
[package] authors = ["{{authors}}"] name = "{{project-name}}" version = "0.1.0" edition = "2021" [lib] name = "getitem" crate-type = ["cdylib"] [dependencies] pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/getitem
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/getitem/.template/pyproject.toml
[build-system] requires = ["maturin>=1,<2"] build-backend = "maturin" [project] name = "{{project-name}}" version = "0.1.0" [project.optional-dependencies] dev = ["pytest"]
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/getitem
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/getitem/.template/pre-script.rhai
variable::set("PYO3_VERSION", "0.19.0"); file::rename(".template/Cargo.toml", "Cargo.toml"); file::rename(".template/pyproject.toml", "pyproject.toml"); file::delete(".template");
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/Cargo.toml
[package] name = "plugin_example" version = "0.1.0" edition = "2021" [dependencies] pyo3={path="../../", features=["macros"]} plugin_api={path="plugin_api"} [workspace]
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/README.md
# plugin An example of a Rust app that uses Python for a plugin. A Python extension module built using PyO3 and [`maturin`](https://github.com/PyO3/maturin) is used to provide interface types that can be used to exchange data between Rust and Python. This also deals with how to separately test and load python modules. # Building and Testing ## Host application To run the app itself, you only need to run ```shell cargo run ``` It will build the app, as well as the plugin API, then run the app, load the plugin and show it working. ## Plugin API testing The plugin API is in a separate crate `plugin_api`, so you can test it separately from the main app. To build the API only package, first install `maturin`: ```shell pip install maturin ``` When building the plugin, simply using `maturin develop` will fail to produce a viable extension module due to the features arrangement of PyO3. Instead, one needs to enable the optional feature as follows: ```shell cd plugin_api maturin build --features "extension-module" ``` Alternatively, install nox and run the tests inside an isolated environment: ```shell nox ``` ## Copying this example Use [`cargo-generate`](https://crates.io/crates/cargo-generate): ```bash $ cargo install cargo-generate $ cargo generate --git https://github.com/PyO3/pyo3 examples/plugin ``` (`cargo generate` will take a little while to clone the PyO3 repo first; be patient when waiting for the command to run.)
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/cargo-generate.toml
[template] ignore = [".nox"] [hooks] pre = [".template/pre-script.rhai"]
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/python_plugin/rng.py
def get_random_number(): # verified by the roll of a fair die to be random return 4
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/python_plugin/gadget_init_plugin.py
import plugin_api import rng def start(): """create an instance of Gadget, configure it and return to Rust""" g = plugin_api.Gadget() g.push(1) g.push(2) g.push(3) g.prop = rng.get_random_number() return g
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/plugin_api/noxfile.py
import nox @nox.session def python(session): session.env["MATURIN_PEP517_ARGS"] = "--profile=dev" session.install(".[dev]") session.run("pytest")
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/plugin_api/Cargo.toml
[package] name = "plugin_api" version = "0.1.0" description = "Plugin API example" edition = "2021" [lib] name = "plugin_api" crate-type = ["cdylib", "rlib"] [dependencies] #!!! Important - DO NOT ENABLE extension-module FEATURE HERE!!! pyo3 = { path = "../../../" } [features] # instead extension-module feature for pyo3 is enabled conditionally when we want to build a standalone extension module to test our plugins without "main" program extension-module = ["pyo3/extension-module"]
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/plugin_api/pyproject.toml
[build-system] requires = ["maturin>=1,<2"] build-backend = "maturin" [project] name = "plugin_api" requires-python = ">=3.7" classifiers = [ "Programming Language :: Rust", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", ] [project.optional-dependencies] dev = ["pytest"]
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/plugin_api
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/plugin_api/tests/test_Gadget.py
import pytest @pytest.fixture def gadget(): import plugin_api as pa g = pa.Gadget() return g def test_creation(gadget): pass def test_property(gadget): gadget.prop = 42 assert gadget.prop == 42 def test_push(gadget): gadget.push(42)
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/plugin_api
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/plugin_api/tests/test_import.py
def test_import(): import plugin_api # noqa: F401
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/plugin_api
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/plugin_api/src/lib.rs
use pyo3::prelude::*; ///this is our Gadget that python plugin code can create, and rust app can then access natively. #[pyclass] pub struct Gadget { #[pyo3(get, set)] pub prop: usize, //this field will only be accessible to rust code pub rustonly: Vec<usize>, } #[pymethods] impl Gadget { #[new] fn new() -> Self { Gadget { prop: 777, rustonly: Vec::new(), } } fn push(&mut self, v: usize) { self.rustonly.push(v); } } /// A Python module for plugin interface types #[pymodule] pub fn plugin_api(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::<Gadget>()?; Ok(()) }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/src/main.rs
use plugin_api::plugin_api as pylib_module; use pyo3::prelude::*; use pyo3::types::PyList; use std::path::Path; fn main() -> Result<(), Box<dyn std::error::Error>> { //"export" our API module to the python runtime pyo3::append_to_inittab!(pylib_module); //spawn runtime pyo3::prepare_freethreaded_python(); //import path for python let path = Path::new("./python_plugin/"); //do useful work Python::with_gil(|py| { //add the current directory to import path of Python (do not use this in production!) let syspath: Bound<PyList> = py.import("sys")?.getattr("path")?.extract()?; syspath.insert(0, &path)?; println!("Import path is: {:?}", syspath); // Now we can load our python_plugin/gadget_init_plugin.py file. // It can in turn import other stuff as it deems appropriate let plugin = PyModule::import(py, "gadget_init_plugin")?; // and call start function there, which will return a python reference to Gadget. // Gadget here is a "pyclass" object reference let gadget = plugin.getattr("start")?.call0()?; //now we extract (i.e. mutably borrow) the rust struct from python object { //this scope will have mutable access to the gadget instance, which will be dropped on //scope exit so Python can access it again. let mut gadget_rs: PyRefMut<'_, plugin_api::Gadget> = gadget.extract()?; // we can now modify it as if it was a native rust struct gadget_rs.prop = 42; //which includes access to rust-only fields that are not visible to python println!("rust-only vec contains {:?}", gadget_rs.rustonly); gadget_rs.rustonly.clear(); } //any modifications we make to rust object are reflected on Python object as well let res: usize = gadget.getattr("prop")?.extract()?; println!("{res}"); Ok(()) }) }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/.template/Cargo.toml
[package] authors = ["{{authors}}"] name = "{{project-name}}" version = "0.1.0" edition = "2021" [dependencies] pyo3 = "{{PYO3_VERSION}}" plugin_api = { path = "plugin_api" }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/.template/pre-script.rhai
variable::set("PYO3_VERSION", "0.22.5"); file::rename(".template/Cargo.toml", "Cargo.toml"); file::rename(".template/plugin_api/Cargo.toml", "plugin_api/Cargo.toml"); file::delete(".template");
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/.template
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/plugin/.template/plugin_api/Cargo.toml
[package] name = "plugin_api" version = "0.1.0" description = "Plugin API example" edition = "2021" [lib] name = "plugin_api" crate-type = ["cdylib", "rlib"] [dependencies] #!!! Important - DO NOT ENABLE extension-module FEATURE HERE!!! pyo3 = "{{PYO3_VERSION}}" [features] # instead extension-module feature for pyo3 is enabled conditionally when we want to build a standalone extension module to test our plugins without "main" program extension-module = ["pyo3/extension-module"]
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter/noxfile.py
import nox @nox.session def python(session): session.env["MATURIN_PEP517_ARGS"] = "--profile=dev" session.install(".[dev]") session.run("pytest")
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter/Cargo.toml
[package] name = "maturin-starter" version = "0.1.0" edition = "2021" [lib] name = "maturin_starter" crate-type = ["cdylib"] [dependencies] pyo3 = { path = "../../", features = ["extension-module"] } [features] abi3 = ["pyo3/abi3-py37", "generate-import-lib"] generate-import-lib = ["pyo3/generate-import-lib"] [workspace]
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter/MANIFEST.in
include pyproject.toml Cargo.toml recursive-include src *
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter/README.md
# maturin-starter An example of a basic Python extension module built using PyO3 and [`maturin`](https://github.com/PyO3/maturin). ## Building and Testing To build this package, first install `maturin`: ```shell pip install maturin ``` To build and test use `maturin develop`: ```shell pip install -r requirements-dev.txt maturin develop && pytest ``` Alternatively, install nox and run the tests inside an isolated environment: ```shell nox ``` ## Copying this example Use [`cargo-generate`](https://crates.io/crates/cargo-generate): ```bash $ cargo install cargo-generate $ cargo generate --git https://github.com/PyO3/pyo3 examples/maturin-starter ``` (`cargo generate` will take a little while to clone the PyO3 repo first; be patient when waiting for the command to run.)
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter/pyproject.toml
[build-system] requires = ["maturin>=1,<2"] build-backend = "maturin" [project] name = "maturin-starter" version = "0.1.0" classifiers = [ "License :: OSI Approved :: MIT License", "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Programming Language :: Python", "Programming Language :: Rust", "Operating System :: POSIX", "Operating System :: MacOS :: MacOS X", ] [project.optional-dependencies] dev = ["pytest"]
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter/cargo-generate.toml
[template] ignore = [".nox"] [hooks] pre = [".template/pre-script.rhai"]
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter/maturin_starter/__init__.py
# import the contents of the Rust library into the Python extension from .maturin_starter import * from .maturin_starter import __all__ # optional: include the documentation from the Rust module from .maturin_starter import __doc__ # noqa: F401 __all__ = __all__ + ["PythonClass"] class PythonClass: def __init__(self, value: int) -> None: self.value = value
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter/tests/test_maturin_starter.py
from maturin_starter import ExampleClass, PythonClass def test_python_class() -> None: py_class = PythonClass(value=10) assert py_class.value == 10 def test_example_class() -> None: example = ExampleClass(value=11) assert example.value == 11 def test_doc() -> None: import maturin_starter assert ( maturin_starter.__doc__ == "An example module implemented in Rust using PyO3." )
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter/tests/test_submodule.py
from maturin_starter.submodule import SubmoduleClass def test_submodule_class() -> None: submodule_class = SubmoduleClass() assert submodule_class.greeting() == "Hello, world!"
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter/src/lib.rs
use pyo3::prelude::*; use pyo3::types::PyDict; use pyo3::wrap_pymodule; mod submodule; #[pyclass] struct ExampleClass { #[pyo3(get, set)] value: i32, } #[pymethods] impl ExampleClass { #[new] pub fn new(value: i32) -> Self { ExampleClass { value } } } /// An example module implemented in Rust using PyO3. #[pymodule] fn maturin_starter(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::<ExampleClass>()?; m.add_wrapped(wrap_pymodule!(submodule::submodule))?; // Inserting to sys.modules allows importing submodules nicely from Python // e.g. from maturin_starter.submodule import SubmoduleClass let sys = PyModule::import(py, "sys")?; let sys_modules: Bound<'_, PyDict> = sys.getattr("modules")?.downcast_into()?; sys_modules.set_item("maturin_starter.submodule", m.getattr("submodule")?)?; Ok(()) }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter/src/submodule.rs
use pyo3::prelude::*; #[pyclass] struct SubmoduleClass {} #[pymethods] impl SubmoduleClass { #[new] pub fn __new__() -> Self { SubmoduleClass {} } pub fn greeting(&self) -> &'static str { "Hello, world!" } } #[pymodule] pub fn submodule(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::<SubmoduleClass>()?; Ok(()) }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter/.template/Cargo.toml
[package] authors = ["{{authors}}"] name = "{{project-name}}" version = "0.1.0" edition = "2021" [lib] name = "maturin_starter" crate-type = ["cdylib"] [dependencies] pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter/.template/pyproject.toml
[build-system] requires = ["maturin>=1,<2"] build-backend = "maturin" [project] name = "{{project-name}}" version = "0.1.0" [project.optional-dependencies] dev = ["pytest"]
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/maturin-starter/.template/pre-script.rhai
variable::set("PYO3_VERSION", "0.22.5"); file::rename(".template/Cargo.toml", "Cargo.toml"); file::rename(".template/pyproject.toml", "pyproject.toml"); file::delete(".template");
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter/noxfile.py
import nox @nox.session def python(session: nox.Session): session.install("-rrequirements-dev.txt") session.run_always( "pip", "install", "-e", ".", "--no-build-isolation", env={"BUILD_DEBUG": "1"} ) session.run("pytest")
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter/setup.cfg
[metadata] name = setuptools-rust-starter version = 0.1.0 classifiers = License :: OSI Approved :: MIT License Development Status :: 3 - Alpha Intended Audience :: Developers Programming Language :: Python Programming Language :: Rust Operating System :: POSIX Operating System :: MacOS :: MacOS X [options] packages = setuptools_rust_starter include_package_data = True zip_safe = False
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter/setup.py
import os from setuptools import setup from setuptools_rust import RustExtension setup( rust_extensions=[ RustExtension( "setuptools_rust_starter._setuptools_rust_starter", debug=os.environ.get("BUILD_DEBUG") == "1", ) ], )
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter/Cargo.toml
[package] name = "setuptools-rust-starter" version = "0.1.0" edition = "2021" [lib] name = "setuptools_rust_starter" crate-type = ["cdylib"] [dependencies] pyo3 = { path = "../../", features = ["extension-module"] } [workspace]
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter/MANIFEST.in
include pyproject.toml Cargo.toml recursive-include src *
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter/requirements-dev.txt
pytest>=3.5.0 setuptools_rust~=1.0.0 pip>=21.3 wheel
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter/README.md
# setuptools-rust-starter An example of a basic Python extension module built using PyO3 and [`setuptools_rust`](https://github.com/PyO3/setuptools-rust). ## Building and Testing To build this package, first install `setuptools_rust`: ```shell pip install setuptools_rust ``` To build and test use `python setup.py develop`: ```shell pip install -r requirements-dev.txt python setup.py develop && pytest ``` Alternatively, install nox and run the tests inside an isolated environment: ```shell nox ``` ## Copying this example Use [`cargo-generate`](https://crates.io/crates/cargo-generate): ```bash $ cargo install cargo-generate $ cargo generate --git https://github.com/PyO3/pyo3 examples/setuptools-rust-starter ``` (`cargo generate` will take a little while to clone the PyO3 repo first; be patient when waiting for the command to run.)
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter/pyproject.toml
[build-system] requires = ["setuptools>=41.0.0", "wheel", "setuptools_rust>=1.0.0"]
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter/cargo-generate.toml
[template] ignore = [".nox"] [hooks] pre = [".template/pre-script.rhai"]
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter/setuptools_rust_starter/__init__.py
# import the contents of the Rust library into the Python extension from ._setuptools_rust_starter import * from ._setuptools_rust_starter import __all__ # optional: include the documentation from the Rust module from ._setuptools_rust_starter import __doc__ # noqa: F401 __all__ = __all__ + ["PythonClass"] class PythonClass: def __init__(self, value: int) -> None: self.value = value
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter/tests/test_submodule.py
from setuptools_rust_starter.submodule import SubmoduleClass def test_submodule_class() -> None: submodule_class = SubmoduleClass() assert submodule_class.greeting() == "Hello, world!"
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter/tests/test_setuptools_rust_starter.py
from setuptools_rust_starter import ExampleClass, PythonClass def test_python_class() -> None: py_class = PythonClass(value=10) assert py_class.value == 10 def test_example_class() -> None: example = ExampleClass(value=11) assert example.value == 11 def test_doc() -> None: import setuptools_rust_starter assert ( setuptools_rust_starter.__doc__ == "An example module implemented in Rust using PyO3." )
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter/src/lib.rs
use pyo3::prelude::*; use pyo3::types::PyDict; use pyo3::wrap_pymodule; mod submodule; #[pyclass] struct ExampleClass { #[pyo3(get, set)] value: i32, } #[pymethods] impl ExampleClass { #[new] pub fn new(value: i32) -> Self { ExampleClass { value } } } /// An example module implemented in Rust using PyO3. #[pymodule] fn _setuptools_rust_starter(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::<ExampleClass>()?; m.add_wrapped(wrap_pymodule!(submodule::submodule))?; // Inserting to sys.modules allows importing submodules nicely from Python // e.g. from setuptools_rust_starter.submodule import SubmoduleClass let sys = PyModule::import(py, "sys")?; let sys_modules: Bound<'_, PyDict> = sys.getattr("modules")?.downcast_into()?; sys_modules.set_item("setuptools_rust_starter.submodule", m.getattr("submodule")?)?; Ok(()) }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter/src/submodule.rs
use pyo3::prelude::*; #[pyclass] struct SubmoduleClass {} #[pymethods] impl SubmoduleClass { #[new] pub fn __new__() -> Self { SubmoduleClass {} } pub fn greeting(&self) -> &'static str { "Hello, world!" } } #[pymodule] pub fn submodule(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::<SubmoduleClass>()?; Ok(()) }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter/.template/setup.cfg
[metadata] name = {{project-name}} version = 0.1.0 packages = setuptools_rust_starter [options] include_package_data = True zip_safe = False
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter/.template/Cargo.toml
[package] authors = ["{{authors}}"] name = "{{project-name}}" version = "0.1.0" edition = "2021" [lib] name = "setuptools_rust_starter" crate-type = ["cdylib"] [dependencies] pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] }
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/setuptools-rust-starter/.template/pre-script.rhai
variable::set("PYO3_VERSION", "0.22.5"); file::rename(".template/Cargo.toml", "Cargo.toml"); file::rename(".template/setup.cfg", "setup.cfg"); file::delete(".template");
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/word-count/noxfile.py
import nox nox.options.sessions = ["test"] @nox.session def test(session: nox.Session): session.env["MATURIN_PEP517_ARGS"] = "--profile=dev" session.install(".[dev]") session.run("pytest") @nox.session def bench(session: nox.Session): session.env["MATURIN_PEP517_ARGS"] = "--profile=dev" session.install(".[dev]") session.run("pytest", "--benchmark-enable")
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/word-count/Cargo.toml
[package] name = "word-count" version = "0.1.0" edition = "2021" [lib] name = "word_count" crate-type = ["cdylib"] [dependencies] pyo3 = { path = "../..", features = ["extension-module"] } rayon = "1.0.2" [workspace]
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/word-count/MANIFEST.in
include pyproject.toml Cargo.toml recursive-include src *
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/word-count/README.md
# word-count Demonstrates searching for a file in plain python, with rust singlethreaded and with rust multithreaded. ## Build ```shell pip install . ``` ## Usage ```python from word_count import search_py, search, search_sequential search_py("foo bar", "foo") search("foo bar", "foo") search_sequential("foo bar", "foo") ``` ## Testing To test install nox globally and run ```shell nox ``` ## Benchmark To test install nox globally and run ```shell nox -s bench ``` ## Copying this example Use [`cargo-generate`](https://crates.io/crates/cargo-generate): ```bash $ cargo install cargo-generate $ cargo generate --git https://github.com/PyO3/pyo3 examples/word-count ``` (`cargo generate` will take a little while to clone the PyO3 repo first; be patient when waiting for the command to run.)
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/word-count/pyproject.toml
[build-system] requires = ["maturin>=1,<2"] build-backend = "maturin" [project] name = "word-count" version = "0.1.0" classifiers = [ "License :: OSI Approved :: MIT License", "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Programming Language :: Python", "Programming Language :: Rust", "Operating System :: POSIX", "Operating System :: MacOS :: MacOS X", ] [project.optional-dependencies] dev = ["pytest", "pytest-benchmark"] [tool.pytest.ini_options] addopts = "--benchmark-disable"
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/word-count/cargo-generate.toml
[template] ignore = [".nox"] [hooks] pre = [".template/pre-script.rhai"]
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/word-count
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/word-count/word_count/__init__.py
from .word_count import search, search_sequential, search_sequential_allow_threads __all__ = [ "search_py", "search", "search_sequential", "search_sequential_allow_threads", ] def search_py(contents: str, needle: str) -> int: total = 0 for line in contents.splitlines(): for word in line.split(" "): if word == needle: total += 1 return total
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/word-count
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/word-count/tests/test_word_count.py
from concurrent.futures import ThreadPoolExecutor import pytest import word_count @pytest.fixture(scope="session") def contents() -> str: text = """ The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those! """ return text * 1000 def test_word_count_rust_parallel(benchmark, contents): count = benchmark(word_count.search, contents, "is") assert count == 10000 def test_word_count_rust_sequential(benchmark, contents): count = benchmark(word_count.search_sequential, contents, "is") assert count == 10000 def test_word_count_python_sequential(benchmark, contents): count = benchmark(word_count.search_py, contents, "is") assert count == 10000 def run_rust_sequential_twice( executor: ThreadPoolExecutor, contents: str, needle: str ) -> int: future_1 = executor.submit( word_count.search_sequential_allow_threads, contents, needle ) future_2 = executor.submit( word_count.search_sequential_allow_threads, contents, needle ) result_1 = future_1.result() result_2 = future_2.result() return result_1 + result_2 def test_word_count_rust_sequential_twice_with_threads(benchmark, contents): executor = ThreadPoolExecutor(max_workers=2) count = benchmark(run_rust_sequential_twice, executor, contents, "is") assert count == 20000
0
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/word-count
lc_public_repos/langsmith-sdk/vendor/pyo3/examples/word-count/src/lib.rs
use pyo3::prelude::*; use rayon::prelude::*; /// Searches for the word, parallelized by rayon #[pyfunction] fn search(contents: &str, needle: &str) -> usize { contents .par_lines() .map(|line| count_line(line, needle)) .sum() } /// Searches for a word in a classic sequential fashion #[pyfunction] fn search_sequential(contents: &str, needle: &str) -> usize { contents.lines().map(|line| count_line(line, needle)).sum() } #[pyfunction] fn search_sequential_allow_threads(py: Python<'_>, contents: &str, needle: &str) -> usize { py.allow_threads(|| search_sequential(contents, needle)) } /// Count the occurrences of needle in line, case insensitive fn count_line(line: &str, needle: &str) -> usize { let mut total = 0; for word in line.split(' ') { if word == needle { total += 1; } } total } #[pymodule] fn word_count(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(search, m)?)?; m.add_function(wrap_pyfunction!(search_sequential, m)?)?; m.add_function(wrap_pyfunction!(search_sequential_allow_threads, m)?)?; Ok(()) }