Stateless callbacks in toxcore's public API #40

Closed
iphydf opened this Issue Aug 17, 2016 · 4 comments

Comments

Projects
None yet
4 participants
@iphydf
Member

iphydf commented Aug 17, 2016

What are we doing?

We are moving towards stateless callbacks. This means that when registering a
callback, you no longer pass a user data pointer. Instead, you pass a user data
pointer to tox_iterate. This pointer is threaded through the code, passed to
each callback. The callback can modify the data pointed at. An extra indirection
will be needed if the pointer itself can change.

Why?

Currently, callbacks are registered with a user data pointer. This means the
library has N pointers for N different callbacks. These pointers need to be
managed by the client code. Managing the lifetime of the pointee can be
difficult. In C++, it takes special effort to ensure that the lifetime of user
data extends at least beyond the lifetime of the Tox instance. For other
languages, the situation is much worse. Java and other garbage collected
languages may move objects in memory, so the pointers are not stable. Tox4j goes
through a lot of effort to make the Java/Scala user experience a pleasant one by
keeping a global array of Tox+userdata on the C++ side, and communicating via
protobufs. A Haskell FFI would have to do similarly complex tricks.

Stateless callbacks ensure that a user data pointer only needs to live during a
single function call. This means that the user code (or language runtime) can
move the data around at will, as long as it sets the new location in the
callback.

How?

We are doing this change one callback at a time. After each callback, we ensure
that everything still works as expected. This means the toxcore change will
require 15 Pull Requests.

@iphydf iphydf self-assigned this Aug 17, 2016

iphydf added a commit to iphydf/c-toxcore that referenced this issue Aug 17, 2016

iphydf added a commit to iphydf/c-toxcore that referenced this issue Aug 17, 2016

iphydf added a commit to iphydf/c-toxcore that referenced this issue Aug 17, 2016

iphydf added a commit to iphydf/c-toxcore that referenced this issue Aug 17, 2016

iphydf added a commit to iphydf/c-toxcore that referenced this issue Aug 18, 2016

iphydf added a commit to iphydf/c-toxcore that referenced this issue Aug 18, 2016

This was referenced Aug 21, 2016

@iphydf iphydf referenced this issue Sep 4, 2016

Closed

DHT addon #93

iphydf added a commit to iphydf/c-toxcore that referenced this issue Sep 6, 2016

iphydf added a commit to iphydf/c-toxcore that referenced this issue Sep 6, 2016

@iphydf

This comment has been minimized.

Show comment
Hide comment
@iphydf

iphydf Sep 10, 2016

Member

All planned toxcore callbacks are now stateless. Still left to do are the toxav callbacks. @mannol and/or @cleverca22, who wants to take them on?

Member

iphydf commented Sep 10, 2016

All planned toxcore callbacks are now stateless. Still left to do are the toxav callbacks. @mannol and/or @cleverca22, who wants to take them on?

@iphydf iphydf referenced this issue in abbat/pytoxcore Sep 29, 2016

Closed

Prepare for stateless callbacks #11

@GrayHatter GrayHatter added this to the v0.0.3 milestone Oct 24, 2016

@alexeysvrv

This comment has been minimized.

Show comment
Hide comment
@alexeysvrv

alexeysvrv Oct 29, 2016

Stateless is done?

Stateless is done?

@nurupo

This comment has been minimized.

Show comment
Hide comment
@nurupo

nurupo Oct 29, 2016

Member

Only in toxcore, stateless in toxav was reverted because it introduced a bug. See #203.

Member

nurupo commented Oct 29, 2016

Only in toxcore, stateless in toxav was reverted because it introduced a bug. See #203.

@iphydf iphydf changed the title from Stateless callbacks to Stateless callbacks in toxcore's public API Nov 2, 2016

@iphydf

This comment has been minimized.

Show comment
Hide comment
@iphydf

iphydf Nov 2, 2016

Member

Closing this, as the toxcore callbacks are done. We are tracking toxav progress in #203.

Member

iphydf commented Nov 2, 2016

Closing this, as the toxcore callbacks are done. We are tracking toxav progress in #203.

@iphydf iphydf closed this Nov 2, 2016

zugz pushed a commit to zugz/c-toxcore that referenced this issue Jan 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment