Commit Graph

40 Commits

Author SHA1 Message Date
Thomas Weißschuh a9155c6f97 ta: increase size of names printed
30 characters are not a lot.
Also when the name is calculated from the allocation site the line
number will be the at the end of the name, so truncating it is
especially inconvenient.
2022-09-11 20:24:42 -07:00
wm4 027ae815ec ta: add ta_get_parent()
Sometimes useful for debugging. Also fix a random typo elsewhere.
2020-04-26 23:38:54 +02:00
wm4 729843b85e ta: change debug ifdeffery
TA_MEMORY_DEBUGGING always defined. But allow defining it from the
compiler command line (-D), because maybe that's useful for someone?
2020-04-26 23:37:29 +02:00
wm4 28f2d7454d ta: minor simplification for talloc_steal
Since commit f6615f00ee, it can't fail anymore.
2020-04-13 15:56:27 +02:00
wm4 55f16bad76 ta: remove a macro indirection
No idea what purpose this was supposed to serve.
2020-04-13 15:56:27 +02:00
wm4 835137a0e5 player, ta: remove use of an old macro
I thought that would make a nice idiom, but it ended up being useless or
clunky.
2020-04-13 15:56:27 +02:00
wm4 8fc2bc1422 ta: fix logging of unfreed child allocations
Broken since commit f6615f00ee. This traversed the data
structure incorrectly, and caused a stack overflow due to infinite
recursion.
2020-02-29 20:12:31 +01:00
wm4 0ec036bfd8 ta: remove two pointless wrappers 2020-02-23 19:48:25 +01:00
wm4 758082a1f2 ta: minor simplification
Due to the ta_header.parent invariant, the "h->parent->child==h" check
is always true.
2020-02-23 19:45:25 +01:00
wm4 bc3678da65 ta: change API; ta_set_parent() and ta_set_destructor() never fail
The previous change ensured that these cannot fail anymore (much like in
original talloc). Change the APIs to not return a success value anymore,
to "cement" this.
2020-02-23 17:45:05 +01:00
wm4 f6615f00ee ta: remove seperate internal "ext" header
The ta_ext_header was allocated on demand for allocations which have
child-allocations or destructors. In theory, it saved 2 words for every
TA leaf allocation. It had the very API-visible problem that setting a
parent or destructor could fail. (Although in most cases, the failure
was part of an allocation call anyway. Also, mpv code generally used the
early-failure variants, so it didn't matter.)

I think this was a bit too complex. These 2 words don't really matter;
if you have memory allocations where you are worried about overhead,
then these simply shouldn't use TA. Also, we never added new features to
TA that would have needed more "optional" header fields, which would
have justified the use of such a separately allocated header struct.

This uses quite straight-forward data structures. The only strange thing
is that ta_header.parent is NULL for most child allocations. That is
because we don't want to iterate over all children when the parent is
reallocated (yes, that is allowed, yes mpv makes use of it).

The new code has a few more special cases, because the list sentinel
concept isn't used anymore. Using it would have made the code more
unnatural/complex, because ta_ext_header doesn't exist anymore.
2020-02-23 17:36:27 +01:00
wm4 a9586625d1 ta: remove ta_find_parent()
Some mpv code once needed this, but it was removed in 2015.
2020-02-23 14:32:15 +01:00
wm4 4564a22d13 ta: add another funny macro 2019-12-28 21:32:15 +01:00
wm4 65337c032f ta: document funny macros 2019-12-28 21:32:15 +01:00
wm4 36dd2348a1 ta: destroy/free children in reverse order
This matters when talloc allocations set destructors. Before this
commit, destructors were called in the same order as they were added to
the parent allocations. Now it happens in reverse order.

I think this makes more sense. It's reasonable to assume that an
allocation that was added later may depend on any of the previous
allocations, so later additions should be destroyed first. (Of course
other orders are entirely possible too.)

Hopefully this doesn't fix or break anything, but I can't be sure (about
either of those). It's risky. (Then why do it?)

The destructor of a parent allocation is called before its children. It
makes sense and must stay this way, because in most cases, the
destructor wants to access the children.

This is a reason why I don't really like talloc (it wasn't my idea to
use talloc, is my excuse). Quite possible that destructors should be
removed from talloc entirely. Actually, this project should probably be
rewritten in Rust (or a better language), but that would be even more of
a pain; also, I think this is just the right level of suffering and
punishment.
2019-09-19 20:37:05 +02:00
wm4 6827901230 ta: introduce talloc_dup() and use it in some places
It was actually already implemented as ta_dup_ptrtype(), but that seems
like a clunky name. Also we still use the talloc_ names throughout the
source, and I'd rather use an old name instead of a mixing inconsistent
naming conventions.
2018-01-18 01:42:36 -08:00
Niklas Haas 4e34615872 vo_gpu: vulkan: refactor vk_cmdpool
1. No more static arrays (deps / callbacks / queues / cmds)
2. Allows safely recording multiple commands at the same time
3. Uses resources optimally by never over-allocating commands
2017-12-25 00:47:53 +01:00
wm4 bbfafb5614 Fix use of ISC license
The license text refers a "above copyright notice", so I guess it'd be
good to actually provide such a notice.

Add the license to some files that were missing it (since in theory, our
Copyright file says that such files are LGPL by default).

Remove the questionable remarks about the license in the client API.
2017-04-15 16:20:00 +02:00
wm4 6931fef4ad ta_talloc: add missing include statement
Some array functions call memmove().
2017-04-01 20:37:16 +02:00
wm4 d230194f62 ta: remove TA_FREEP NULL check
The NULL check triggers a gcc warning when passing the address of a
variable to it. I was about to silence the warning with some equivalent
code (that just happens to shut up gcc), but then I decided to remove
the NULL check as I don't see a reason why we should allow this. We
don't use it in the existing code anyway (all callers do something like
TA_FREEP(&structptr->member), which is always non-NULL).

Also fix some of the macro argument "quoting".
2017-01-08 07:32:44 +01:00
James Ross-Gowan 40b626fd9b build: fix compilation with mingw-w64/Clang
This fixes the build in mingw-w64/Clang on MSYS2. It also disables the
use of gnu_printf in Clang, which was what was causing most of the
warnings. The Clang-compiled mpv binary appears to work, but there are
no guarantees yet, since until now mpv has only been tested with
mingw-w64/GCC on Windows.

Fixes #3800
2016-11-17 23:34:20 +11:00
wm4 969c011522 ta: add a helper macro 2016-08-20 14:41:12 +02:00
wm4 b18a598444 ta: remove old and redundant macro 2016-05-17 10:53:14 +02:00
Kevin Mitchell 872d0838a4 ta: add TA_FREEP macro
This sets the pointer to NULL after talloc_freeing it. This emulates the
av_freep function for ta_talloc, but with a macro instead.
2016-03-30 05:48:01 -07:00
Jan Ekström ff0112e08d Initial Android support
* Adds an 'android' feature, which is automatically detected.
* Android has a broken strnlen, so a wrapper is added from FreeBSD.
2016-02-10 21:29:36 +01:00
wm4 56c4cdf369 ta: add another array helper macro
Stupid C.
2015-06-01 01:35:56 +02:00
wm4 16a5c6c535 ta: memcpy(ptr, NULL, 0) is undefined 2015-03-23 18:03:45 +01:00
Ben Boeckel 2bbad06bfc ta: rename MP_TALLOC_ELEMS to MP_TALLOC_AVAIL
The macro actually returns the *available* space in the array, not how
much is actually filled in.
2015-01-27 18:09:36 +01:00
wm4 85fb2af369 Remove some superfluous NULL checks
In all of these situations, NULL is logically not allowed, making the
checks redundant.

Coverity complained about accessing the pointers before checking them
for NULL later.
2014-11-21 05:18:09 +01:00
wm4 be0896c173 ta/README: fix typos 2014-10-13 18:56:42 +02:00
Kevin Mitchell b11fdeab9e talloc README: more human readible api reference 2014-04-13 18:03:01 +02:00
wm4 82648ff229 ta: fix comment
If this function could return the input value (i.e. the == case was
correct), then macros like MP_GROW_ARRAY would have been incorrect. The
implementation was correct though, so there's no bug.
2014-02-23 16:51:00 +01:00
wm4 7dae316d50 ta: clarify a corner case 2014-02-23 16:50:51 +01:00
wm4 2cad237f8b ta: check overflow in array realloc macros 2014-01-02 23:54:59 +01:00
wm4 b4aa39a817 ta: fix compilation with NDEBUG 2013-12-19 21:27:02 +01:00
wm4 73a5417950 Merge mp_talloc.h into ta/ta_talloc.h 2013-12-17 02:18:16 +01:00
wm4 801ff8319f ta: fix typo in comment 2013-11-20 18:13:05 +01:00
wm4 81c602c7d2 ta: re-add MinGW cargo culting
Not really cargo cult, but an unexplainable, needless difference that
just exists to annoy us.

Fixes that gcc on MinGW treats format specifiers in MSVC mode. Just why?
Why?
2013-11-02 15:20:53 +01:00
wm4 03ec49be8f ta: track location debug info in 2 more cases
Was overlooked.
2013-10-30 22:19:32 +01:00
wm4 0933f12d28 Replace talloc
There are multiple reasons to do this. One big reason is the license:
talloc is LGPLv3+, which forces mpv to be licensed as GPLv3+.

Another one is that our talloc copy contains modifications, which makes
it essentially incompatible with upstream talloc (in particular, our
version aborts on out of memory conditions - well, it wasn't my idea).
Updating from upstream is also a bit involved - the talloc source is
not really organized in a way to allow copying it into projects (and
this isn't an intended use-case).

Finally, talloc is kind of big and bloated. The replacement halves the
amount of code - mainly because we didn't use all talloc features. It's
even more extreme if you compare upstream talloc (~4700 lines) and the
new allocator without talloc compat (~900 lines).

The replacement provides all features we need. It also doesn't clash
with talloc. (The talloc compatibility wrapper uses macros to avoid
introducing linker-level symbols which could clash with libtalloc.)

It also tries to lower the overhead (only 4 words opposed to 10 words
in talloc for leaf nodes in release mode). Debugging features like leak
reporting can be enabled at compile time and add somewhat more overhead.
Though I'm not sure whether the overhead reduction was actually
successful: allocations with children need an "extra" header, which adds
plenty of overhead, and it turns out that almost half of all allocations
have children. Maybe the implementation could be simplified and the
extra header removed - even then, overhead would be lower than talloc's.

Currently, debugging features can be entirely deactivated by defining
NDEBUG - I'm not sure if anything defines this directly yet, though.

Unlike in talloc, the leak reporting stuff is thread-safe. (That's also
why it's far less elegant, and requires extra list pointers.)

Comes with a compatibility layer, so no changes to mpv source code
are needed. The idea is that we will pretend to be using talloc for
a while, so that we can revert to our old talloc implementation at
any time for debugging purposes.

Some inspiration was taken from Mesa's ralloc:

    http://cgit.freedesktop.org/mesa/mesa/tree/src/glsl/ralloc.h

This is another talloc replacement, but lacks some features we need
(getting size of an allocation, debugging features, being able to
access children in the dtor).

There's some information in ta/README what will happen next and how the
transition is expected to progress.
2013-10-13 01:36:09 +02:00