xo-umbrella2/xo-pyutil/include/xo/pyutil/pyutil.hpp
Roland Conybeare 2b87e58d1e git subrepo clone git@github.com:Rconybea/xo-pyutil.git xo-pyutil
subrepo:
  subdir:   "xo-pyutil"
  merged:   "dfd5229b"
upstream:
  origin:   "git@github.com:Rconybea/xo-pyutil.git"
  branch:   "main"
  commit:   "dfd5229b"
git-subrepo:
  version:  "0.4.9"
  origin:   "???"
  commit:   "???"
2026-06-06 22:31:02 -04:00

30 lines
965 B
C++

/* @file pyutil.hpp
*
* utility stuff to be used across multiple pybind11 .cpp files
*/
#pragma once
#include "xo/refcnt/Refcounted.hpp"
#include "xo/refcnt/Unowned.hpp"
#include <pybind11/pybind11.h>
/* xo::ref::intrusive_ptr<T> is an intrusively-reference-counted pointer.
* always safe to create one from a T* p
* (since refcount is directly accessible from p)
*
* Need declaration like this before any pybind11 bindings
* that expose an object of types like
* (a) intrusive_ptr<T> or
* (b) T * / T const * / T & / T const & to python.
* If this were not done, pybind11 would by default use unique_ptr<intrusive_ptr<T>>
* (ok but inefficient) or unique_ptr<T> (fatal!)
*/
PYBIND11_DECLARE_HOLDER_TYPE(T, xo::ref::intrusive_ptr<T>, true);
/* xo::ref::unowned_ptr<T> is an unmanaged pointer.
* use this for immortal objects that pybind11 must not delete.
*/
PYBIND11_DECLARE_HOLDER_TYPE(T, xo::ref::unowned_ptr<T>, true);
/* end pyutil.hpp */