Commit Graph

39 Commits (361eebc6f3e07bb09e726c0a6724991a4dab9de2)

Author SHA1 Message Date
tt2468 23cda97a54 libobs/callback: Make proc_handler_t threadsafe
Add mutexes to protect against multi-threaded memory access
violations.
2021-10-14 04:28:04 -07:00
jpark37 8075e8bb65 libobs/callback: Fix pthread mutex leaks 2021-08-23 22:31:00 -07:00
Exeldro 93205e5729 libobs/callback: Fix signal_handler_disconnect_global 2021-07-04 04:32:45 -07:00
jp9000 f53df7da64 clang-format: Apply formatting
Code submissions have continually suffered from formatting
inconsistencies that constantly have to be addressed.  Using
clang-format simplifies this by making code formatting more consistent,
and allows automation of the code formatting so that maintainers can
focus more on the code itself instead of code formatting.
2019-06-23 23:49:10 -07:00
jp9000 3a05cf6ab0 libobs/callback: Add signal reference counting
Adds a simple signal reference counting function
(signal_handler_connect_ref) that makes it so that signals keep the
handler around until the all the signal itself is disconnected.  This
prevents potential crashes where a signal might try to disconnect after
a handler has already been destroyed (typically in C++ with
OBSSignalHandler helper objects, where destruction isn't guaranteed to
be predictable).

This also modifies OBSSignalHandler to use the reference-counting
connections.
2018-06-03 15:04:03 -07:00
jp9000 e3d19c5b16 libobs/callback: Add calldata_create and calldata_destroy
These functions aren't particularly useful in C/C++, but these functions
are necessary to allow creating/destroying a calldata_t object via
script.
2018-01-18 08:53:19 -08:00
jp9000 c8a0f661fb libobs/callback: Add global callback to signal handler
A global callback allows capturing all signals from a signal handler
rather than just a specific signal.
2018-01-03 17:04:02 -08:00
jp9000 b8bb60c83b libobs/callback: Add signal_handler_remove_current func
Convenience function that allows removing the current signal handler
callback within the callback without having to use
signal_handler_disconnect with all of its required parameters.
2018-01-03 17:04:02 -08:00
Ryan Foster be98cee2a0 Fix various typos across multiple modules 2017-04-25 22:39:42 -04:00
Richard Stanway 8b640fae24
Fix various null pointer issues detected by Coverity 2017-02-25 16:45:45 +01:00
jp9000 92bbb8e8b1 libobs/callback: Allow ability to use calldata_t with stack
Allows the ability to use fixed stack memory to construct a calldata_t
structure rather than having to allocate each time.  This is fine to do
for certain signals where the calldata never goes above a specific size.
If by some chance the size is insufficient, it will output a log
message.
2016-01-25 17:29:08 -08:00
jp9000 d1f225e2e8 libobs/callback: Set default return values to 0/NULL
These functions created stack variables but never actually initialized
them.  If the calldata variable is invalid, the return values will be
the uninitialized stack value.
2015-12-15 01:11:10 -08:00
Richard Stanway 90a45a0ca0 libobs: Don't call signal handlers that got removed
It's possible for one signal handler to disconnect another during signal_handler_signal, which could result in crashes when the disconnected signal handler is called with a potentially freed data pointer due to other cleanup.
2015-10-13 01:08:51 +02:00
Palana c680b3e115 libobs/calldata: Fix unaligned loads/stores
Found via UBSan, actual errors (addresses not pruned for illustrative purposes):

"runtime error: store to misaligned address 0x7f9a9178e84c for type
'size_t' (aka 'unsigned long'), which requires 8 byte alignment"

"runtime error: load of misaligned address 0x7f9a9140f2cf for type
'size_t' (aka 'unsigned long'), which requires 8 byte alignment"
2015-05-31 04:45:54 +02:00
jp9000 41fad2d1a4 (API Change) Use const params where applicable
This Fixes a minor flaw with the API where data had to always be mutable
to be usable by the API.

Functions that do not modify the fundamental underlying data of a
structure should be marked as constant, both for safety and to signify
that the parameter is input only and will not be modified by the
function using it.
2014-09-26 17:23:07 -07:00
jp9000 c9df41c1e2 (API Change) Remove pointers from all typedefs
Typedef pointers are unsafe.  If you do:
typedef struct bla *bla_t;
then you cannot use it as a constant, such as: const bla_t, because
that constant will be to the pointer itself rather than to the
underlying data.  I admit this was a fundamental mistake that must
be corrected.

All typedefs that were pointer types will now have their pointers
removed from the type itself, and the pointers will be used when they
are actually used as variables/parameters/returns instead.

This does not break ABI though, which is pretty nice.
2014-09-25 21:48:11 -07:00
jp9000 50ec8b0d55 (API Change) libobs/callback: Unsquish names
Renamed:                  To:
-------------------------------------------------
calldata_getdata          calldata_get_data
calldata_getint           calldata_get_int
calldata_getfloat         calldata_get_float
calldata_getbool          calldata_get_bool
calldata_getptr           calldata_get_ptr
calldata_getstring        calldata_get_string
calldata_setdata          calldata_set_data
calldata_setint           calldata_set_int
calldata_setfloat         calldata_set_float
calldata_setbool          calldata_set_bool
calldata_setptr           calldata_set_ptr
calldata_setstring        calldata_set_string
2014-08-09 11:57:38 -07:00
Timo R 85fd6863e2 Fix missing initialization
Found by compiling with gcc 4.8, which shows a warning for use in the
inlined function called in that function.

Closes #155
2014-07-10 18:17:06 +02:00
jp9000 4b17bb89ed Allow signal callback deletion while signalling
I encountered a situation where I wanted to delete a callback for a
signal while inside of that signal.  However it would hard lock, and
even after that, it would mess up the loop for the callback list.

So, change the mutex of the individual signals to a recursive-style
mutex, and then if a callback of a signal is deleted while currently in
that signal, just mark it for deletion, which will happen after the
signal is complete.
2014-06-14 23:42:00 -07:00
jp9000 d891e9772c libobs: Fix signal handler lock bug
There was a return statement within a section of code that had a locked
mutex.
2014-06-03 04:41:12 -07:00
jp9000 f91b4ef98e Check for duplicate names (function parser) 2014-03-02 19:44:22 -07:00
jp9000 1eeece5b97 Simplify and improve 'list' property
When a source/output/etc has a property of a 'list' type, there was no
way to get the names associated with its values.  That, and it only
supported lists of either text, or enums (0..[value] only).

Now, you can associate translated names with those values, and use
integer, float, or string values.  Put it all in to one function as well
to simplify its usage.

I plan on using this to help get enumerations from devices/etc for
certain types of sources.  For example, if I get the properties of an
audio source, I'd like to have a list of available devices with it as
well.
2014-03-02 06:32:47 -07:00
jp9000 e9342143a7 Simplify and extend callback/signalling system
- Signals and dynamic callbacks now require declarations to be made
  before being used.  What this does is allows us to get information
  about the functions dynamically which can be relayed to the user and
  plugins for future extended usage (this should have big implications
  later for scripting in particular, hopefully).

- Reduced the number of types calldata uses from "everything I could
  think of" to simply integer, float, bool, pointer/object, string.
  Integer data is now stored as long long.  Floats are now stored as
  doubles (check em).

- Use a more consistent naming scheme for lexer error/warning macros.

- Fixed a rather nasty bug where switching to an existing scene would
  cause it to increment sourceSceneRefs, which would mean that it would
  never end up never properly removing the source when the user clicks
  removed (stayed in limbo, obs_source_remove never got called)
2014-03-01 05:54:55 -07:00
jp9000 268e4e7811 Add more checks for NULL pointers 2014-02-23 22:39:33 -07:00
jp9000 966b943d5b Remove majority of warnings
There were a *lot* of warnings, managed to remove most of them.

Also, put warning flags before C_FLAGS and CXX_FLAGS, rather than after,
as -Wall -Wextra was overwriting flags that came before it.
2014-02-14 15:13:36 -07:00
jp9000 9879eead83 Fix a couple of warnings 2014-02-09 08:53:19 -08:00
jp9000 968f5fed32 Added some return-style functions to calldata.h
When using signal callbacks, there is rarely a need to check to see if
the callback paramters are actually validl; in those cases, if they are
invalid, then the signal is being used incorrectly.  The calldata_get*
functions are meant to be used more for when using dynamic function
calls rather than when using signals.  The calldata_get* functions made
it so that you have to declare your varaibles, and then call that
function to assign that value to those variables, which was slightly
annoying to constantly have to do over and over.

  Therefore I created a few extra functions for returning the value
without having to check for validity.  Although you would think this
would be an issue for maintaining, keep in mind that these functions
return base types.  Admittedly, these functions are merely for
convenience.
2014-01-04 13:28:27 -07:00
Palana 7ca68a9d04 fix function pointer types in dynamic procedure handler 2014-01-03 02:58:17 +01:00
Palana ec5cdf1b17 fix incompatible types warning in signal system 2014-01-01 03:33:16 +01:00
jp9000 78eb116cc8 add 'static' to inline functions in callback/calldata.h 2013-12-30 11:09:32 -07:00
jp9000 72633e40a3 also include bmem.h in the header, minor oversight 2013-12-30 10:14:28 -07:00
jp9000 cec94b042e implement scene adding callbacks, make a few API tweaks 2013-12-28 05:33:16 -07:00
jp9000 261b9d7056 fix a few bugs with callback system, add some test signals 2013-12-27 05:08:58 -07:00
jp9000 6edcd456fe implement signal/procedure handling into libobs and individual sources 2013-12-26 23:10:15 -07:00
jp9000 3b48f79442 fix one minor bug with the disconnct function 2013-12-26 04:33:16 -07:00
jp9000 233694ad04 add one minor error message to signal handler 2013-12-26 04:28:09 -07:00
jp9000 6ac6256ac5 fill in rest of signal/callback/proc 2013-12-26 04:26:17 -07:00
jp9000 a136748bd3 don't hide calldata structure, no reason to, and forced an unnecessary allocation which is bad 2013-12-26 02:02:24 -07:00
jp9000 e9ded173f1 add my signal/callback interface from another project, also update license of utility files to ISC 1.3 2013-12-25 22:40:33 -07:00