Commit Graph

15 Commits

Author SHA1 Message Date
Jason Rhinelander b0edf998f8
Fix python binding segfault
This fixes a segfault in the reply handling code, where the destructor
of a `py::function` wasn't necessarily happening with the GIL held,
which could make Python segfault.

The solution that was here to address this didn't work because it was
relying on std::optionals, but it is possible (and apparently sometimes
happens) that the std::function this lambda gets stuffed into gets moved
(or maybe copied?), which then results in *two* lambda destructions: we
were correctly dealing with the one that eventually gets called by
clearing things properly when it gets called, but the temporary
destructor also fires, and that is the one that broke.

This changes it to instead leak bare pointers into the lambda and then
recapture them inside when we get called; since we are guaranteed to be
called exactly once, this recaptures them without losing them but
doesn't incur destruction of a py::function deep in oxenmq (outside of
GIL scope).
2023-09-27 16:06:08 -03:00
Jason Rhinelander 6e50822bc9
Expose setting auth level on outgoing connection
This is necessary to allow a remote to issue authenticated commands back
to us.
2023-03-08 17:31:49 -04:00
Jason Rhinelander f62fa4916f
Remove base32z encoding
We have pyoxenc for that instead.
2022-08-04 13:31:22 -03:00
Jason Rhinelander 4bf412905a
Rename is_reply -> is_request
The property is retrieving whether a reply is expected, not whether the
message itself is a reply.
2022-06-09 18:29:29 -03:00
Jason Rhinelander 296f61a7c0
macos compilation fix
macos clang won't apply the implicit `operator std::string()` from
py::bytes here for some unknown reason.
2022-01-11 11:16:47 -04:00
Jason Rhinelander 4136c29d06
Make Message property accessors copy
The default references, which breaks because Message gets reused, so
storing `.conn` gives you something that changes the next time a worker
gets a message.
2021-12-03 13:08:11 -04:00
Jason Rhinelander f1160d0a25
Make allow_connection properly optional 2021-12-03 13:07:49 -04:00
Jason Rhinelander 4020ab8a49
Make ConnectionIDs hashable 2021-12-03 13:07:35 -04:00
Jason Rhinelander a678fcf0ce
Remove include for older pybind compatibility 2021-12-02 15:39:54 -04:00
Jason Rhinelander 530280ac60
Fix allow function argument decoding error
Avoids a utf-8 decoding error when accepting a connection with an allow
function by properly wrapping the function in a version that passes
pubkey as a `bytes`.
2021-12-02 15:14:54 -04:00
Jason Rhinelander b12c754895 Fixes and address warnings
- timeout in the syncronous connect_remote wasn't being passed through
- callback and syncronous connect_remote had some deviation in args;
  unified them to both take keyword-only timeout and
  ephemeral_routing_id, and to take timeout as a timedelta with a
  default (rather than an optional in the callback-based one).
- removed unused "noopt".  I forget what it was for, but it didn't end
  up being used.
2021-10-22 19:12:57 -03:00
Jason Rhinelander 5ceed8a416 Various fixes for bugs revealed in testing
- make extract data parts always flatten to arbitrary depth.  We were
  only flattening once (and only sometimes), but arbitrary flattening is
  nicer (as long as we don't ultimately encouter anything that isn't
  str/bytes).
- fix Message.data()/.dataview() pre-loading nulls into the list.  The
  py::list constructor argument here is pre-fill, not a reservation.
- fix add_command: it was broken because when the wrapped callback gets
  invoked it tries casting the Message via copying, but that breaks
  (Message isn't copyable).  Fix it by adding a wrapper that does a
  referencing cast to a Python object.
- Add missing docs for add_command
- Doc typo fixes
- Remove OxenMQ default and loglevel constructors, and make the
  remaining constructor take everything by keyword arguments.  (Default
  constructor remains equivalent, and the log-level constructor now has
  to have the log level named).
- Fix OxenMQ keyword constructor: invoking it was failing because the
  annotation default on sn_lookup wasn't properly castable to the
  required types (it should be py::none() rather than nullptr).  Also
  fix the defaults for pubkey/privkey to be py::bytes() (the empty
  string worked fine, but using bytes makes it show up as bytes defaults
  in the generated signature doc string).
- Further document connect_inproc with a description of why you might
  want it.
- Fix send not actually including the message data parts
- Work around segfault in the reply callback: because we have lambdas
  with python object captures, we'd segfault in the proxy thread when it
  frees them after calling them because that freeing invokes python
  destructor but it doesn't hold the gil.  Fixed by making the lambda
  consume its own callbacks (which is fine because oxenmq will invoke
  the callback exactly once).
- Fix request_future invocation which raised an error on invocation:
  straight lambdas aren't castable to python objects, so stuff the
  lambda inside std::functions, which are.
2021-10-22 16:28:21 -03:00
Jason Rhinelander a62f6c4769 Formatting 2021-10-22 16:08:57 -03:00
Jason Rhinelander 0e1283784e Remove unwanted headers
- pybind11/gil.h is only in recent pybind (but is implicitly included by
  the main pybind11.h header)
- detail/common shouldn't be included
2021-10-21 23:47:58 -03:00
Jason Rhinelander a98722a7da pyoxenmq overhaul
- Wrap much more of the OxenMQ
- Add extensive pydoc to everything
- Switch setup.py to pybind's built-in tools
2021-10-21 22:23:02 -03:00