Commit Graph

395 Commits

Author SHA1 Message Date
Campbell Barton
bc1ffdce5b Cleanup: spelling in comments 2023-08-18 08:56:12 +10:00
Campbell Barton
e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Campbell Barton
311fa9768d Cleanup: spelling in comments 2023-08-12 16:29:51 +10:00
Bastien Montagne
bcc0b9f73f Tweaks to previous commit affecting debug reports of our guarded allocator.
Somehow missed these tweaks (from @LazyDodo) in own recent 2e79ca3205
commit, sorry for the noise.
2023-08-10 17:56:36 +02:00
Bastien Montagne
2e79ca3205 Fix #110971: Replace our own barely-working backtrace on memleaks feature with ASAN utils.
Instead of storing the backtrace in all memory blocks, and trying to get
meaningful info out of this list of pointers when printing leaked ones,
just use `__asan_describe_address` when ASAN is enabled.

This also work on Windows, in addition to linux and (presumably) OSX,
but does require to build with ASAN enabled.

The previous code was not working very well anymore, for some reason the
call to `backtrace_symbols` seems to fail to give any meaningful
information nowadays on most of Blender code. And it was only
implemented for linux and OSX.

Based on an idea from @LazyDodo, many thanks!

Pull Request: https://projects.blender.org/blender/blender/pulls/111006
2023-08-10 17:54:56 +02:00
Bastien Montagne
c5feb0cada MEM_guarded_alloc: Fix LSAN not reporting memory leaks.
The fact that the guarded-allocated memory blocks are all linked to the
static `membase` listbase is enough for LSAN to not detect them as
leaks.

So this commit adds a new (private) callback to clear the memlist, which
is only used in the destructor of the `MemLeakDetector` class.

Many thanks to @Sergey for identifying the root issue here.

Pull Request: https://projects.blender.org/blender/blender/pulls/110995
2023-08-10 15:05:53 +02:00
Campbell Barton
ed01e16aa6 Cleanup: quiet uninitialized warnings 2023-07-29 13:47:57 +10:00
Jacques Lucke
d1aeb1c3b4 Cleanup: add static assert for detect bad usage of MEM_SAFE_FREE
Without this, there is not compilation error when doing e.g.:
```
int a;
MEM_SAFE_FREE(a);
```
2023-07-28 13:50:02 +02:00
Jacques Lucke
3e6025c1b1 Cleanup: move some files to c++
Also see #103343.

Pull Request: https://projects.blender.org/blender/blender/pulls/110529
2023-07-27 13:10:42 +02:00
Ray Molenkamp
57ad866d81 Cleanup: CMake: Modernize bf_guardedalloc dependencies
Pretty straightforward

- Removes any guardedalloc paths from INC
- Adds a dependency though LIB

Pull Request: https://projects.blender.org/blender/blender/pulls/109925
2023-07-10 18:44:19 +02:00
Ray Molenkamp
f0ee4c3ffe Cleanup: Cmake: use alias target for bf_intern_atomic
This introduces an alias target `bf::intern::atomic` for
`bf_intern_atomic`. This has the following benefits:

- Any target name with `::` in it will be recognized as an actual
target by cmake, rather than a library name it may not know about.
and will be validated by cmake to exist. Which means if you make
a typo in the LIB section, CMake will error out telling you it
doesn't know about this specific target rather than passing it on
to the build system, where you'll either get build or linker errors
because of said typo.

- Given there is quite a cleanup still to do in the build system,
it won't always be obvious which targets have been updated to
modern targets and which still need to be done. Having a namespaced
target name is a good indicator there.

Pull Request: https://projects.blender.org/blender/blender/pulls/109784
2023-07-07 15:37:02 +02:00
Ray molenkamp
2dac20e35f CMake/Cleanup: Use bf_intern_atomic target
Use the bf_intern_atomic target rather than adding a relative path
to it in the INC section.

Pull Request: https://projects.blender.org/blender/blender/pulls/109424
2023-06-28 19:12:55 +02:00
Campbell Barton
d27be2b95d Cleanup: remove sprintf use in guarded allocator
Also remove vsprintf in exr_printf (commented out).
2023-06-27 15:31:21 +10:00
Jeroen Bakker
0c154b6c61 Cleanup: Make format 2023-06-15 08:25:49 +02:00
Campbell Barton
65f99397ec License headers: use SPDX-FileCopyrightText in all sources 2023-06-15 13:35:34 +10:00
Campbell Barton
49594c37ae License headers: use SPDX-FileCopyrightText for CMake files 2023-06-14 23:36:23 +10:00
Brecht Van Lommel
835252fd1c Merge branch 'blender-v3.6-release' into main 2023-06-13 19:48:48 +02:00
Brad Smith
c1d353c17b Build: fix NetBSD error in guardedalloc
Pull Request: https://projects.blender.org/blender/blender/pulls/108831
2023-06-13 19:46:11 +02:00
Campbell Barton
e27bcb6e3e Cleanup: remove redundant struct qualifier 2023-06-04 19:27:38 +10:00
Brad Smith
670da740ba Build: fix OpenBSD error in guardedalloc
Pull Request: https://projects.blender.org/blender/blender/pulls/108252
2023-05-30 13:55:37 +02:00
Brad Smith
a50768616f Build: fix OpenBSD error in guardedalloc
Pull Request: https://projects.blender.org/blender/blender/pulls/108252
2023-05-25 15:21:48 +02:00
Brad Smith
322dab936f Build: fixes for OpenBSD
Pull Request: https://projects.blender.org/blender/blender/pulls/107666
2023-05-09 13:19:16 +02:00
Sergey Sharybin
a12a8a71bb Remove "All Rights Reserved" from Blender Foundation copyright code
The goal is to solve confusion of the "All rights reserved" for licensing
code under an open-source license.

The phrase "All rights reserved" comes from a historical convention that
required this phrase for the copyright protection to apply. This convention
is no longer relevant.

However, even though the phrase has no meaning in establishing the copyright
it has not lost meaning in terms of licensing.

This change makes it so code under the Blender Foundation copyright does
not use "all rights reserved". This is also how the GPL license itself
states how to apply it to the source code:

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software ...

This change does not change copyright notice in cases when the copyright
is dual (BF and an author), or just an author of the code. It also does
mot change copyright which is inherited from NaN Holding BV as it needs
some further investigation about what is the proper way to handle it.
2023-03-30 10:51:59 +02:00
Sergey Sharybin
d32d787f5f Clang-Format: Allow empty functions to be single-line
For example

```
OIIOOutputDriver::~OIIOOutputDriver()
{
}
```

becomes

```
OIIOOutputDriver::~OIIOOutputDriver() {}
```

Saves quite some vertical space, which is especially handy for
constructors.

Pull Request: https://projects.blender.org/blender/blender/pulls/105594
2023-03-29 16:50:54 +02:00
Campbell Barton
e39b358a2f Guarded allocator: print memory-in-use as a size_t, not uint
There is no reason to cast to a smaller value which could overflow.
2023-03-23 14:20:14 +11:00
Germano Cavalcante
f27d6b9640 MSVC: lower C4100 warning level from 4 to 3
The C4100 warning is related to unused formal parameters in functions.

Enabling it better aligns with "-Wunused-parameter" option in other
compilers.

While suppressing it with `__pragma(warning(suppress:4100))` is not the
same as using `__attribute__((__unused__))` in GCC or Clang, it is
still preferable to use it over completely hiding the warning.

This ensures consistent warning behavior across compilers and improves
code quality by addressing unused function parameters.

(Note that some warnings in Windows-specific code have already been
silenced in 7fcb262dfd2f48a73f9cf794944ff677c36e3783)

Pull Request: https://projects.blender.org/blender/blender/pulls/105534
2023-03-09 16:05:48 +01:00
Germano Cavalcante
a755e6e63f Revert "MSVC: lower C4100 warning level from 4 to 3"
This reverts commit db4e7616f3590c04484fe8a015b6a02b7a1ede44.

Caused many issues when compiling mantaflow.
2023-02-14 15:36:35 -03:00
Germano Cavalcante
db4e7616f3 MSVC: lower C4100 warning level from 4 to 3
This better aligns with OSX/Linux warnings.

Although `__pragma(warning(suppress:4100))` is not the same as
`__attribute__((__unused__))` in gcc (which only affects the attribute
instead of the line), it still seems to be better to use it than to
hide the warning entirely.
2023-02-14 14:38:18 -03:00
Julian Eisel
4126284e46 Allocator: Fail building when trying to MEM_delete a void pointer
`MEM_delete()` is designed for type safe destruction and freeing, void
pointers make that impossible.
Was reviewing a patch that was trying to free a C-style custom data
pointer this way. Apparently MSVC compiles this just fine, other
compilers error out. Make sure this is a build error on all platforms
with a useful message.
2023-02-14 12:48:26 +01:00
Campbell Barton
66dee44088 CMake: quiet references to undeclared variable warnings
These warnings can reveal errors in logic, so quiet them by checking
if the features are enabled before using variables or by assigning
empty strings in some cases.

- Check CMAKE_THREAD_LIBS_INIT is set before use as CMake docs
  note that this may be left unset if it's not needed.
- Remove BOOST/OPENVDB/VULKAN references when disable.
- Define INC_SYS even when empty.
- Remove PNG_INC from freetype (not defined anywhere).
2023-01-19 17:10:42 +11:00
Jacques Lucke
ae7163007d Allocator: improve protection against false sharing
On Apple Silicon, the cache line size is 128 bytes.
2023-01-06 13:04:49 +01:00
Campbell Barton
14fc02f91d Cleanup: spelling in comments 2023-01-06 14:00:36 +11:00
Jacques Lucke
862d08bb97 Fix: use-after-free when threadlocal is destructed after static variable
This issue was introduced in rB78f28b55d39288926634d0cc.

The fix is to use a `std::shared_ptr` to ensure that the `Global` will live
long enough until all `Local` objects are destructed.
2023-01-05 14:38:34 +01:00
Jacques Lucke
78f28b55d3 Allocator: improve multi-threaded allocation performance
Both, the guarded and lockfree allocator, are keeping track of current
and peak memory usage. Even the lockfree allocator used to use a
global atomic variable for the memory usage. When multiple threads
use the allocator at the same time, this variable is highly contended.
This can result in significant slowdowns as presented in D16862.

While specific cases could always be optimized by reducing the number
of allocations, having this synchronization point in functions used by
almost every part of Blender is not great.

The solution is use thread-local memory counters which are only added
together when the memory usage is actually requested. For more details
see in-code comments and D16862.

Differential Revision: https://developer.blender.org/D16862
2023-01-04 14:55:46 +01:00
Sergey Sharybin
09b9e1e95e Fix T102225: Crash opening menus
Seems to be introduced by 99e5024e97f.

The crash is caused by the difference in the expected alignment
of the `uiPopupMenu` which is 16 bytes and the actual alignment
returned by the `MEM_mallocN()` which is 8 bytes due to the memory
head.

Now made it so that `MEM_new()` can be used for types with any
alignment.

Differential Revision: https://developer.blender.org/D16375
2022-11-03 14:32:04 +01:00
Campbell Barton
889b3385b5 Cleanup: spelling in comments 2022-11-02 10:18:19 +11:00
Campbell Barton
b9e4d930b3 Cleanup: use 'u' prefixed unsigned types 2022-10-12 10:39:12 +11:00
Campbell Barton
3961d3493b Cleanup: use 'u' prefixed integer types for brevity in C code
This also simplifies using function style casts when moving to C++.
2022-09-26 11:33:22 +10:00
Campbell Barton
15f3cf7f8f Cleanup: replace C-style casts with functional casts for numeric types
Some changes missed from f68cfd6bb078482c4a779a6e26a56e2734edb5b8.
2022-09-26 09:53:49 +10:00
Campbell Barton
f68cfd6bb0 Cleanup: replace C-style casts with functional casts for numeric types 2022-09-25 20:17:08 +10:00
Brecht Van Lommel
0ffd288fab Build: fix gtest build flags affecting actual library
Switch to target_ functions to avoid this.
2022-09-18 11:26:34 +02:00
Campbell Barton
c29d63aa5e Cleanup: spelling in comments 2022-08-30 16:22:49 +10:00
Brecht Van Lommel
ff27457240 Allocator: add MEM_cnew_array
This is a more C++ friendly version MEM_calloc_arrayN, like MEM_cnew is for
MEM_callocN. For cases where data structures are still C and Vector or Array
don't work.
2022-08-29 19:45:58 +02:00
listout
f197b1a1f1 CMake: support building with musl libc
Instead of using macros like GLIBC we can use the CMake build
systems internal functions to check if some header or functions are
present on the running system's libc.

Add ./build_files/cmake/have_features.cmake to add checks for
platform features which can be used to set defines for source
files that require them.

Reviewed By: campbellbarton

Ref D15696
2022-08-18 08:12:56 +10:00
Julian Eisel
28e0cc424d Guarded allocator: Function to rename block for debugging
We have plenty of sorta generic functions, that allocate memory with
some generic name for debugging. When such a function is called and the
memory leaks, it may be unclear which call to it allocated the unfreed
memory (and thus which execution path leads to the leak).

The added function is only available if `NDEBUG` is not defined.

Differential Revision: https://developer.blender.org/D15605

Reviewed by: Sergey Sharybin, Bastien Montagne
2022-08-04 11:26:57 +02:00
Campbell Barton
49babc7caa Cleanup: early exit MEM_lockfree_freeN when called with NULL pointer
Simplify logic for freeing a NULL pointer. While no null-pointer
de-reference was performed, this wasn't as so obvious as the pointer
was passed to MEM_lockfree_allocN_len before checking for NULL.

NOTE: T99744 claimed the a NULL pointer free was a vulnerability,
while I can't see evidence for this - exiting early makes it clearer
the memory isn't accessed.

*Details*

- Add MEMHEAD_LEN macro, avoids redundant NULL check.
- Use "UNLIKELY(..)" hint's for error cases
  (freeing NULL pointer and checking if `leak_detector_has_run`).
2022-07-16 17:23:42 +10:00
Campbell Barton
61a7e5be18 Cleanup: '*' prefix C-comment blocks 2022-06-01 15:38:48 +10:00
Campbell Barton
c93f3b4596 Cleanup: spelling in comments 2022-05-17 15:34:02 +10:00
Sergey Sharybin
42e13ea4bf Cleanup: Deprecated field access in outliner_duplicate
Solved by introducing introducing a variant of MEM_cnew which behaves
as a copy-constructor for a trivial types.

Alternative approach would be to surround DNA structs with clang/gcc
diagnostics push/modify/pop so that implicitly defined constructors
and copy operators are allowed to access deprecated fields.

The downside of the DNA approach is that it will require some way to
easily apply diagnostics modifications to many structs, which is not
possible currently.

The newly added MEM_cnew has other good usecases, so is easiest to
use this route, at least for now.

Differential Revision: https://developer.blender.org/D14356
2022-03-16 12:38:23 +01:00
Campbell Barton
fe55789b6f File headers: manually convert files to use SPDX headers
Also add BSD-2-Clause to SPDX license list.
2022-02-11 15:15:49 +11:00