Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to the same stage as the cpp plugin /1 #5

Merged
merged 19 commits into from Sep 2, 2023
Merged

Update to the same stage as the cpp plugin /1 #5

merged 19 commits into from Sep 2, 2023

Conversation

Asd-g
Copy link

@Asd-g Asd-g commented Aug 27, 2023

Another attempt (#4).

@qyot27
Copy link
Owner

qyot27 commented Aug 29, 2023

The InterlockedIncrement/Decrement calls are defined in avs/posix.h, so those don't actually need to be branched for _WIN32. They aren't the exact same used functions as the branched version, though.

It's actually somewhat relevant as well, because even though both versions segfault, the one using the avs/posix-provided
defines actually initiates the indexing and creates an .ffindex file. The branched version fails before the indexer is
called.

branched backtrace:

BFD: error: /usr/lib/debug/.build-id/76/d31ea2e96570c93280ca7bce291ce412c3f7a5.debug(.debug_info) is too large (0x15ef4c bytes)
warning: Can't read data for section '.debug_info' in file '/usr/lib/debug/.build-id/76/d31ea2e96570c93280ca7bce291ce412c3f7a5.debug'
warning: Section .debug_aranges in /usr/lib/debug/.build-id/76/d31ea2e96570c93280ca7bce291ce412c3f7a5.debug entry at offset 0 debug_info_offset 0 does not exists, ignoring .debug_aranges.

Thread 1 "ffmpeg" received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in  ()
#1  0x00007fffd947b1bb in avisynth_c_plugin_init (env=0x7fffffffac80)
    at ../src/avisynth_c/avisynth.c:454
#2  0x00007ffff63d8200 in PluginManager::TryAsAvsC(PluginFile&, AVSValue*)
    (this=0x5555587e87f0, plugin=..., result=0x7fffffffaef0)
    at /home/qyot27/AviSynthPlus/avs_core/core/PluginManager.cpp:1270
#3  0x00007ffff63d6eef in PluginManager::LoadPlugin(PluginFile&, bool, AVSValue*)
    (this=0x5555587e87f0, plugin=..., throwOnError=true, result=0x7fffffffaef0)
    at /home/qyot27/AviSynthPlus/avs_core/core/PluginManager.cpp:970
#4  0x00007ffff63d6cc0 in PluginManager::LoadPlugin(char const*, bool, AVSValue*)
    (this=0x5555587e87f0, path=0x5555587f0208 "/usr/local/lib/libffms2.so", throwOnError=true, result=0x7fffffffaef0)
    at /home/qyot27/AviSynthPlus/avs_core/core/PluginManager.cpp:892
#5  0x00007ffff63f817e in ScriptEnvironment::LoadPlugin(char const*, bool, AVSValue*)
    (this=0x5555587e7bc0, filePath=0x5555587f0208 "/usr/local/lib/libffms2.so", throwOnError=true, result=0x7fffffffaef0)
    at /home/qyot27/AviSynthPlus/avs_core/core/avisynth.cpp:3019
#6  0x00007ffff6409ba1 in ThreadScriptEnvironment::LoadPlugin(char const*, bool, AVSValue*)
    (this=0x5555587e83a0, filePath=0x5555587f0208 "/usr/local/lib/libffms2.so", throwOnError=true, result=0x7fffffffaef0)
    at /home/qyot27/AviSynthPlus/avs_core/core/avisynth.cpp:1862
#7  0x00007ffff63d832a in LoadPlugin(AVSValue, void*, IScriptEnvironment*)
    (args=..., env=0x5555587e83a0)
--Type <RET> for more, q to quit, c to continue without paging--
    at /home/qyot27/AviSynthPlus/avs_core/core/PluginManager.cpp:1300
#8  0x00007ffff63c1683 in FilterConstructor::InstantiateFilter() const
    (this=0x5555587e9220)
    at /home/qyot27/AviSynthPlus/avs_core/core/FilterConstructor.cpp:26
#9  0x00007ffff63fdd85 in ScriptEnvironment::Invoke_(AVSValue*, AVSValue const&, char const*, Function const*, AVSValue const&, char const* const*, InternalEnvironment*, bool)
    (this=0x5555587e7bc0, result=0x7fffffffb310, implicit_last=..., name=0x5555587f01f8 "LoadPlugin", f=0x7ffff6c36520 <Plugin_functions>, args=..., arg_names=0x5555587fa350, env_thread=0x5555587e83a0, is_runtime=false)
    at /home/qyot27/AviSynthPlus/avs_core/core/avisynth.cpp:4724
#10 0x00007ffff6409620 in ThreadScriptEnvironment::Invoke_(AVSValue*, AVSValue const&, char const*, Function const*, AVSValue const&, char const* const*)
    (this=0x5555587e83a0, result=0x7fffffffb310, implicit_last=..., name=0x5555587f01f8 "LoadPlugin", f=0x0, args=..., arg_names=0x5555587fa350)
    at /home/qyot27/AviSynthPlus/avs_core/core/avisynth.cpp:1779
#11 0x00007ffff647591e in ExpFunctionCall::Evaluate(IScriptEnvironment*)
    (this=0x5555587fa2f0, env=0x5555587e83a0)
    at /home/qyot27/AviSynthPlus/avs_core/core/parser/expression.cpp:573
#12 0x00007ffff647207d in ExpExceptionTranslator::Evaluate(IScriptEnvironment*)
    (this=0x5555587fa370, env=0x5555587e83a0)
    at /home/qyot27/AviSynthPlus/avs_core/core/parser/expression.cpp:79
#13 0x00007ffff647241b in ExpLine::Evaluate(IScriptEnvironment*)
    (this=0x5555587fa370, env=0x5555587e83a0)
    at /home/qyot27/AviSynthPlus/avs_core/core/parser/expression.cpp:122
--Type <RET> for more, q to quit, c to continue without paging--
#14 0x00007ffff6471fd4 in ExpSequence::Evaluate(IScriptEnvironment*)
    (this=0x5555587fa3a0, env=0x5555587e83a0)
    at /home/qyot27/AviSynthPlus/avs_core/core/parser/expression.cpp:72
#15 0x00007ffff6471f7b in ExpSequence::Evaluate(IScriptEnvironment*)
    (this=0x5555587fa520, env=0x5555587e83a0)
    at /home/qyot27/AviSynthPlus/avs_core/core/parser/expression.cpp:70
#16 0x00007ffff6471e6b in ExpRootBlock::Evaluate(IScriptEnvironment*)
    (this=0x5555587f7120, env=0x5555587e83a0)
    at /home/qyot27/AviSynthPlus/avs_core/core/parser/expression.cpp:59
#17 0x00007ffff6478edc in Eval(AVSValue, void*, IScriptEnvironment*)
    (args=..., env=0x5555587e83a0)
    at /home/qyot27/AviSynthPlus/avs_core/core/parser/script.cpp:459
#18 0x00007ffff63c1683 in FilterConstructor::InstantiateFilter() const
    (this=0x5555587e8970)
    at /home/qyot27/AviSynthPlus/avs_core/core/FilterConstructor.cpp:26
#19 0x00007ffff63fdcf7 in ScriptEnvironment::Invoke_(AVSValue*, AVSValue const&, char const*, Function const*, AVSValue const&, char const* const*, InternalEnvironment*, bool)
    (this=0x5555587e7bc0, result=0x7fffffffbad0, implicit_last=..., name=0x7ffff6b2da55 "Eval", f=0x7ffff6c58e48 <Script_functions+6664>, args=..., arg_names=0x0, env_thread=0x5555587e83a0, is_runtime=false)
    at /home/qyot27/AviSynthPlus/avs_core/core/avisynth.cpp:4708
#20 0x00007ffff6408f81 in ThreadScriptEnvironment::Invoke(char const*, AVSValue, char const* const*) (this=0x5555587e83a0, name=0x7ffff6b2da55 "Eval", args=..., arg_names=0x0)
    at /home/qyot27/AviSynthPlus/avs_core/core/avisynth.cpp:1695
--Type <RET> for more, q to quit, c to continue without paging--
#21 0x00007ffff6479fdc in Import(AVSValue, void*, IScriptEnvironment*)
    (args=..., env=0x5555587e83a0)
    at /home/qyot27/AviSynthPlus/avs_core/core/parser/script.cpp:640
#22 0x00007ffff63c1683 in FilterConstructor::InstantiateFilter() const
    (this=0x5555587e8a10)
    at /home/qyot27/AviSynthPlus/avs_core/core/FilterConstructor.cpp:26
#23 0x00007ffff63fdcf7 in ScriptEnvironment::Invoke_(AVSValue*, AVSValue const&, char const*, Function const*, AVSValue const&, char const* const*, InternalEnvironment*, bool)
    (this=0x5555587e7bc0, result=0x7fffffffcfc0, implicit_last=..., name=0x555556cc60b8 "Import", f=0x7ffff6c58ef0 <Script_functions+6832>, args=..., arg_names=0x0, env_thread=0x5555587e83a0, is_runtime=false)
    at /home/qyot27/AviSynthPlus/avs_core/core/avisynth.cpp:4708
#24 0x00007ffff6408f81 in ThreadScriptEnvironment::Invoke(char const*, AVSValue, char const* const*) (this=0x5555587e83a0, name=0x555556cc60b8 "Import", args=..., arg_names=0x0)
    at /home/qyot27/AviSynthPlus/avs_core/core/avisynth.cpp:1695
#25 0x00007ffff643341a in avs_invoke(AVS_ScriptEnvironment*, char const*, AVS_Value, char const**) (p=0x5555587e7ba0, name=0x555556cc60b8 "Import", args=..., arg_names=0x0)
    at /home/qyot27/AviSynthPlus/avs_core/core/avisynth_c.cpp:1091
#26 0x0000555555b81926 in avisynth_open_file (s=0x5555587b8510)
    at src/libavformat/avisynth.c:867
#27 0x0000555555b82195 in avisynth_read_header (s=0x5555587b8510)
    at src/libavformat/avisynth.c:1089
#28 0x0000555555b9d44f in avformat_open_input
    (ps=0x7fffffffd1a8, filename=0x7fffffffde9b "../../test.avs", fmt=0x0, options=0x5555--Type <RET> for more, q to quit, c to continue without paging--
587b83c8) at src/libavformat/demux.c:316
#29 0x000055555568a40c in ifile_open
    (o=0x7fffffffd310, filename=0x7fffffffde9b "../../test.avs")
    at src/fftools/ffmpeg_demux.c:1499
#30 0x00005555556af1be in open_files
    (l=0x5555587b8378, inout=0x555556c36032 "input", open_file=0x55555568985e <ifile_open>) at src/fftools/ffmpeg_opt.c:1284
#31 0x00005555556af370 in ffmpeg_parse_options (argc=3, argv=0x7fffffffda68)
    at src/fftools/ffmpeg_opt.c:1324
#32 0x00005555556bdad8 in main (argc=3, argv=0x7fffffffda68)
    at src/fftools/ffmpeg.c:1340
(gdb) 

avs/posix-provided backtrace:

BFD: error: /usr/lib/debug/.build-id/76/d31ea2e96570c93280ca7bce291ce412c3f7a5.debug(.debug_info) is too large (0x15ef4c bytes)
warning: Can't read data for section '.debug_info' in file '/usr/lib/debug/.build-id/76/d31ea2e96570c93280ca7bce291ce412c3f7a5.debug'
warning: Section .debug_aranges in /usr/lib/debug/.build-id/76/d31ea2e96570c93280ca7bce291ce412c3f7a5.debug entry at offset 0 debug_info_offset 0 does not exists, ignoring .debug_aranges.

Thread 1 "ffmpeg" received signal SIGSEGV, Segmentation fault.
__strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:76
76      ../sysdeps/x86_64/multiarch/strlen-avx2.S: No such file or directory.
(gdb) bt
#0  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:76
#1  0x00007ffff64049b0 in StringDump::SaveString(char const*, int, bool)
    (this=0x5555587e7bf8, s=0x58861880 <error: Cannot access memory at address 0x58861880>, len=-1, escape=false) at /home/qyot27/AviSynthPlus/avs_core/core/vartable.h:155
#2  0x00007ffff6405049 in VarStringFrame::SaveString(char const*, int, bool)
    (this=0x5555587e7bc0, s=0x58861880 <error: Cannot access memory at address 0x58861880>, len=-1, escape=false) at /home/qyot27/AviSynthPlus/avs_core/core/vartable.h:248
#3  0x00007ffff640520a in ConcurrentVarStringFrame::SaveString(char const*, int, bool)
    (this=0x5555587e7bc0, s=0x58861880 <error: Cannot access memory at address 0x58861880>, len=-1, escape=false) at /home/qyot27/AviSynthPlus/avs_core/core/vartable.h:279
#4  0x00007ffff6405af8 in VarTable::SaveString(char const*, int, bool)
    (this=0x5555587e83d0, s=0x58861880 <error: Cannot access memory at address 0x58861880>, len=-1, escape=false) at /home/qyot27/AviSynthPlus/avs_core/core/vartable.h:385
#5  0x00007ffff6407fc6 in ThreadScriptEnvironment::SaveString(char const*, int)
    (this=0x5555587e83a0, s=0x58861880 <error: Cannot access memory at address 0x58861880>, length=-1) at /home/qyot27/AviSynthPlus/avs_core/core/avisynth.cpp:1482
#6  0x00007ffff643377a in avs_set_var(AVS_ScriptEnvironment*, char const*, AVS_Value)
    (p=0x5555588562a8, name=0x58861880 <error: Cannot access memory at address 0x58861880>, val=...) at /home/qyot27/AviSynthPlus/avs_core/core/avisynth_c.cpp:1127
#7  0x00007fffd547eac3 in get_frame (fi=0x5555588562b8, n=0)
    at ../src/avisynth_c/ff_vidsource.c:139
#8  0x00007ffff64322a1 in C_VideoFilter::GetFrame(int, IScriptEnvironment*)
    (this=0x555558856280, n=0, env=0x5555587e83a0)
    at /home/qyot27/AviSynthPlus/avs_core/core/avisynth_c.cpp:761
--Type <RET> for more, q to quit, c to continue without paging--
#9  0x00007ffff64353c1 in Cache::GetFrame(int, IScriptEnvironment*)
    (this=0x555558923700, n=0, env_=0x5555587e83a0)
    at /home/qyot27/AviSynthPlus/avs_core/core/cache.cpp:274
#10 0x00007ffff6436e0a in CacheGuard::GetFrame(int, IScriptEnvironment*)
    (this=0x5555588640d0, n=0, env=0x5555587e83a0)
    at /home/qyot27/AviSynthPlus/avs_core/core/cache.cpp:685
#11 0x00007ffff650a173 in AudioDub::GetFrame(int, IScriptEnvironment*)
    (this=0x5555589402a0, n=0, env=0x5555587e83a0)
    at /home/qyot27/AviSynthPlus/avs_core/filters/edit.cpp:866
#12 0x00007ffff63d2870 in MTGuard::GetFrame(int, IScriptEnvironment*)
    (this=0x555558950180, n=0, env=0x5555587e83a0)
    at /home/qyot27/AviSynthPlus/avs_core/core/MTGuard.cpp:187
#13 0x00007ffff64353c1 in Cache::GetFrame(int, IScriptEnvironment*)
    (this=0x555558854ac0, n=0, env_=0x5555587e83a0)
    at /home/qyot27/AviSynthPlus/avs_core/core/cache.cpp:274
#14 0x00007ffff6436e0a in CacheGuard::GetFrame(int, IScriptEnvironment*)
    (this=0x555558852aa0, n=0, env=0x5555587e83a0)
    at /home/qyot27/AviSynthPlus/avs_core/core/cache.cpp:685
#15 0x00007ffff6432880 in avs_get_frame(AVS_Clip*, int) (p=0x5555587fa6a0, n=0)
    at /home/qyot27/AviSynthPlus/avs_core/core/avisynth_c.cpp:866
#16 0x0000555555b80cc8 in avisynth_create_stream_video
    (s=0x5555587b8510, st=0x55555893fa00) at src/libavformat/avisynth.c:533
#17 0x0000555555b817c4 in avisynth_create_stream (s=0x5555587b8510)
    at src/libavformat/avisynth.c:839
--Type <RET> for more, q to quit, c to continue without paging--
#18 0x0000555555b81aba in avisynth_open_file (s=0x5555587b8510)
    at src/libavformat/avisynth.c:916
#19 0x0000555555b82195 in avisynth_read_header (s=0x5555587b8510)
    at src/libavformat/avisynth.c:1089
#20 0x0000555555b9d44f in avformat_open_input
    (ps=0x7fffffffd1a8, filename=0x7fffffffde96 "../../test.avs", fmt=0x0, options=0x5555587b83c8) at src/libavformat/demux.c:316
#21 0x000055555568a40c in ifile_open
    (o=0x7fffffffd310, filename=0x7fffffffde96 "../../test.avs")
    at src/fftools/ffmpeg_demux.c:1499
#22 0x00005555556af1be in open_files
    (l=0x5555587b8378, inout=0x555556c36032 "input", open_file=0x55555568985e <ifile_open>) at src/fftools/ffmpeg_opt.c:1284
#23 0x00005555556af370 in ffmpeg_parse_options (argc=3, argv=0x7fffffffda68)
    at src/fftools/ffmpeg_opt.c:1324
#24 0x00005555556bdad8 in main (argc=3, argv=0x7fffffffda68)
    at src/fftools/ffmpeg.c:1340
(gdb) 

@Asd-g
Copy link
Author

Asd-g commented Aug 30, 2023

__atomic_add_fetch is the modern version of __sync_add_and_fetch.

The issue was the ffms_avs_sprintf. I replaced it with the avs equivalent version avs_sprintf.

@qyot27
Copy link
Owner

qyot27 commented Aug 31, 2023

Should avs_lib.c@137 actually be:

        avs_close( &ffms_avs_lib.library );

because ffms_avs_lib.library has already been NULLed in the line right above it? Or would that actually stop it from being correctly freed/closed?

I only say this because it was causing mpv to segfault on script exit (either through quitting early or by reaching EOF). Change it to refer to the pointer, no more segfault.

Set memory to NULL after and not before it's released.
Fix clang-cl warning.
Use avs posix.h for handling _stricmp, strcasecmp.
@Asd-g
Copy link
Author

Asd-g commented Aug 31, 2023

avs_close( &ffms_avs_lib.library ); should be called for correctly closing the opened object.

However setting the memory to NULL before avs_close/free is not good - this can lead to undefined behavior in the case of dlclose or free by specs does nothing on null pointer (I didn't check if the memory is actually freed, for example here).

Edit: utf8 parameter does nothing. It could be removed?

@qyot27
Copy link
Owner

qyot27 commented Aug 31, 2023

Yeah, utf8 was removed from the C++ plugin back in 2015-2017. No reason to keep it around on the C plugin side either.

@qyot27 qyot27 merged commit 241aed9 into qyot27:c_plugin Sep 2, 2023
@qyot27
Copy link
Owner

qyot27 commented Sep 2, 2023

The only thing I can point out at this stage is that the include for avs/posix.h is what needed to be branched per-OS (see the way it's used in AviSynth+ itself), but that can't be done in avs_common.h without causing implicit declaration and undefined reference errors.

As there's a couple of commits I have to add on top here, I'll just include that change in there as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants