Skip to content

Commit

Permalink
Clean up NEW_AVSVALUE defines
Browse files Browse the repository at this point in the history
NEW_AVSVALUE has been unconditionally enabled on all platforms for
some time now, so just treat it as normal code.  A few comments
still refer to the value, but as other comments explicitly state
what NEW_AVSVALUE was for originally, that context is probably
enough.
  • Loading branch information
qyot27 committed Dec 1, 2021
1 parent f54cc70 commit 2103827
Show file tree
Hide file tree
Showing 17 changed files with 3 additions and 129 deletions.
7 changes: 0 additions & 7 deletions avs_core/core/FilterConstructor.cpp
Expand Up @@ -8,16 +8,11 @@ FilterConstructor::FilterConstructor(IScriptEnvironment2 * env, IScriptEnvironme
#if 1
ArgStorage(std::move(*argStorage)),
CtorArgs(std::move(*ctorArgs))
#else
#ifndef NEW_AVSVALUE
ArgStorage(std::move(*argStorage)),
CtorArgs(std::move(*ctorArgs))
#else
// no need to move, subarrays could not be returned
ArgStorage(*argStorage),
CtorArgs(*ctorArgs)
#endif
#endif
{
}

Expand All @@ -30,7 +25,6 @@ AVSValue FilterConstructor::InstantiateFilter() const
AVSValue retval = Func->apply(funcArgs, Func->user_data,
Func->isAvs25 ? (IScriptEnvironment *)Env25 : Env);
// pass back proper ScriptEnvironment, because a 2.5 plugin e.g. GRunT can back-Invoke ScriptClip
#ifdef NEW_AVSVALUE
if (Func->isAvs25)
{
// After instantiate a v2.5 "baked code" filter
Expand Down Expand Up @@ -61,6 +55,5 @@ AVSValue FilterConstructor::InstantiateFilter() const
// e.g. VirtualDub consecutively press "script reload"s. Memory will leak even 50-80Mbytes so after a while
// memory gets full.
}
#endif
return retval;
}
9 changes: 0 additions & 9 deletions avs_core/core/FilterGraph.cpp
Expand Up @@ -19,22 +19,13 @@

static AVSValue DeepCopyValue(std::vector<std::unique_ptr<AVSValue[]>>& arrays, const AVSValue& src) {
if (src.IsArray()) {
#ifdef NEW_AVSVALUE
AVSValue* copy = new AVSValue[src.ArraySize()];
for (int i = 0; i < src.ArraySize(); ++i) {
copy[i] = src[i]; // NEW_AVSVALUE is already doing deep copy
// copy[i] = DeepCopyValue(arrays, src[i]);
}
arrays.emplace_back(std::unique_ptr<AVSValue[]>(copy));
return AVSValue(copy, src.ArraySize());
#else
AVSValue* copy = new AVSValue[src.ArraySize()];
for (int i = 0; i < src.ArraySize(); ++i) {
copy[i] = DeepCopyValue(arrays, src[i]);
}
arrays.emplace_back(std::unique_ptr<AVSValue[]>(copy));
return AVSValue(copy, src.ArraySize());
#endif
}
return src;
}
Expand Down
8 changes: 0 additions & 8 deletions avs_core/core/PluginManager.cpp
Expand Up @@ -120,9 +120,7 @@ static bool IsParameterTypeSpecifier(char c) {
switch (c) {
case 'b': case 'i': case 'f': case 's': case 'c': case '.':
case 'n':
#ifdef NEW_AVSVALUE
case 'a': // Arrays as function parameters
#endif
return true;
default:
return false;
Expand Down Expand Up @@ -293,9 +291,7 @@ bool AVSFunction::SingleTypeMatch(char type, const AVSValue& arg, bool strict) {
case 's': return arg.IsString();
case 'c': return arg.IsClip();
case 'n': return arg.IsFunction();
#ifdef NEW_AVSVALUE
case 'a': return arg.IsArray(); // PF 161028 AVS+ script arrays
#endif
default: return false;
}
}
Expand Down Expand Up @@ -366,15 +362,13 @@ bool AVSFunction::TypeMatch(const char* param_types, const AVSValue* args, size_
switch (*param_types) {
case 'b': case 'i': case 'f': case 's': case 'c':
case 'n':
#ifdef NEW_AVSVALUE
case 'a':
// PF 2016: 'a' is special letter for script arrays, but if possible we are using .* and .+ (legacy Avisynth style) instead
// Note (2021): 'a' is still not used
// cons: no z or nz (+ or *) possibility
// no type check (array of int)
// cannot be used in plugins which are intended to work for Avisynth 2.6 Classic. ("a" is invalid in function signature -> plugin load error)
// pros: clean syntax, accept _only_ arrays when required, no comma-delimited-list-to-array option (like in old Avisynth syntax)
#endif
// array arguments are not necessarily "flattened" when TypeMatch is called.
if (param_types[1] == '+' // parameter indicates an array-type args[i]
&& args[i].IsArray() // allow single e.g. 'c' parameter in place of a 'c+' requirement
Expand All @@ -401,7 +395,6 @@ bool AVSFunction::TypeMatch(const char* param_types, const AVSValue* args, size_
++i;
break;
case '+': case '*':
#ifdef NEW_AVSVALUE
// check array content type if required
if (args[i].IsArray() && param_types[-1] != '.') {
// A script can provide an array argument in an direct array-type variable.
Expand All @@ -416,7 +409,6 @@ bool AVSFunction::TypeMatch(const char* param_types, const AVSValue* args, size_
++i;
}
else
#endif
// Legacy Avisynth array check.
// Array of arguments of known types last until an argument of another type is found.
// This is the reason why an .+ or .* (array of anything) must only appear at the end
Expand Down
15 changes: 0 additions & 15 deletions avs_core/core/avisynth.cpp
Expand Up @@ -1609,9 +1609,6 @@ class ThreadScriptEnvironment : public InternalEnvironment
AVSValue __stdcall Invoke25(const char* name,
const AVSValue args, const char* const* arg_names)
{
#ifndef NEW_AVSVALUE
return Invoke(name, args, arg_names);
#else
AVSValue result;
// MarkArrayAsC: signing for destructor: don't free array elements.
// Reason: CPP 2.5 plugins have "baked code" in their avisynth.h and do not know
Expand All @@ -1628,7 +1625,6 @@ class ThreadScriptEnvironment : public InternalEnvironment
throw NotFound();

return result;
#endif
}


Expand Down Expand Up @@ -4031,9 +4027,7 @@ bool ScriptEnvironment::PlanarChromaAlignment(IScriptEnvironment::PlanarChromaAl
static size_t Flatten(const AVSValue& src, AVSValue* dst, size_t index, int level, const char* const* arg_names = NULL) {
// level is starting from zero
if (src.IsArray()
#ifdef NEW_AVSVALUE
&& level == 0
#endif
) { // flatten for the first arg level
const int array_size = src.ArraySize();
for (int i=0; i<array_size; ++i) {
Expand Down Expand Up @@ -4481,12 +4475,6 @@ bool ScriptEnvironment::Invoke_(AVSValue *result, const AVSValue& implicit_last,
// from the unnamed section we don't throw error for the first time
ThrowError("Script error: the named argument \"%s\" was passed more than once (twice as named or first unnamed then named) to %s", arg_names[i], name);
}
#ifndef NEW_AVSVALUE
//PF 161028 AVS+ arrays as named arguments
else if (args[i].IsArray()) {
ThrowError("Script error: can't pass an array as a named argument");
}
#endif
else if (args[i].Defined() && args[i].IsArray() && ((q[2] == '*' || q[2] == '+')) && !AVSFunction::SingleTypeMatchArray(q[1], args[i], false))
{
// e.g. passing colors=[235, 128, "Hello"] to [colors]f+
Expand Down Expand Up @@ -4564,9 +4552,6 @@ bool ScriptEnvironment::Invoke_(AVSValue *result, const AVSValue& implicit_last,
for (int i = argbase; i < (int)args2.size(); ++i)
{
auto& argx = args2[i];
#ifndef NEW_AVSVALUE
assert(!argx.IsArray()); // todo: we can have arrays 161106
#endif
// todo PF 161112 new arrays: recursive look into arrays whether they contain clips
if (argx.IsClip())
{
Expand Down
7 changes: 1 addition & 6 deletions avs_core/core/avisynth_c.cpp
Expand Up @@ -903,22 +903,17 @@ extern "C"
void AVSC_CC avs_copy_value(AVS_Value * dest, AVS_Value src)
{
// true: don't copy array elements recursively
#ifdef NEW_AVSVALUE
new(dest) AVSValue(*(const AVSValue*)&src, true);
#else
new(dest) AVSValue(*(const AVSValue*)&src);
#endif
}

extern "C"
void AVSC_CC avs_release_value(AVS_Value v)
{
#ifdef NEW_AVSVALUE
if (((AVSValue*)&v)->IsArray()) {
// signing for destructor: don't free array elements
((AVSValue*)&v)->MarkArrayAsC();
}
#endif

((AVSValue*)&v)->~AVSValue();
}

Expand Down
36 changes: 0 additions & 36 deletions avs_core/core/interface.cpp
Expand Up @@ -728,9 +728,6 @@ void AVSValue::CONSTRUCTOR8(const AVSValue* a, int size)
{
type = 'a';
array_size = (short)size;
#ifndef NEW_AVSVALUE
array = a;
#else
if (a == nullptr || size == 0) {
array = nullptr;
}
Expand All @@ -740,30 +737,17 @@ void AVSValue::CONSTRUCTOR8(const AVSValue* a, int size)
const_cast<AVSValue *>(array)[i].Assign(&a[i], true); // init from source
}
}
#endif
}

AVSValue::AVSValue(const AVSValue& v) { CONSTRUCTOR9(v); }
void AVSValue::CONSTRUCTOR9(const AVSValue& v) { Assign(&v, true); }

#ifdef NEW_AVSVALUE
AVSValue::AVSValue(const AVSValue& v, bool c_arrays) { CONSTRUCTOR10(v, c_arrays); }
void AVSValue::CONSTRUCTOR10(const AVSValue& v, bool c_arrays) { Assign2(&v, true, c_arrays); }
#endif

AVSValue::AVSValue(const PFunction& n) { CONSTRUCTOR11(n); }
void AVSValue::CONSTRUCTOR11(const PFunction& n) { type = 'n'; array_size = 0; function = n.GetPointerWithAddRef(); }

#ifndef NEW_AVSVALUE
AVSValue::~AVSValue() { DESTRUCTOR(); }
void AVSValue::DESTRUCTOR()
{
if (IsClip() && clip)
clip->Release();
if (IsFunction() && function)
function->Release();
}
#else
AVSValue::~AVSValue() { DESTRUCTOR(); }
void AVSValue::DESTRUCTOR()
{
Expand All @@ -785,8 +769,6 @@ void AVSValue::MarkArrayAsC()
array_size = -array_size;
}

#endif

AVSValue& AVSValue::operator=(const AVSValue& v) { return OPERATOR_ASSIGN(v); }
AVSValue& AVSValue::OPERATOR_ASSIGN(const AVSValue& v) { Assign(&v, false); return *this; }

Expand Down Expand Up @@ -851,23 +833,6 @@ const AVSValue& AVSValue::OPERATOR_INDEX(int index) const {
return (IsArray() && index>=0 && index<array_size) ? array[index] : *this;
}

#ifndef NEW_AVSVALUE
void AVSValue::Assign(const AVSValue* src, bool init) {
if (src->IsClip() && src->clip)
src->clip->AddRef();
if (!init && IsClip() && clip)
clip->Release();

if (src->IsFunction() && src->function)
src->function->AddRef();
if (!init && IsFunction() && function)
function->Release();

this->type = src->type;
this->array_size = src->array_size;
this->clip = src->clip; // "clip" is the largest member of the union, making sure we copy everything
}
#else
// this Assign copies array elements for new AVSVALUE handling
// For C interface, we use Assign2 through CONSTRUCTOR10
void AVSValue::Assign(const AVSValue* src, bool init) {
Expand Down Expand Up @@ -946,7 +911,6 @@ void AVSValue::Assign2(const AVSValue* src, bool init, bool c_arrays) {
if (shouldReleaseFunction)
((IFunction *)prev_pointer_to_release)->Release();
}
#endif

// end class AVSValue

Expand Down
4 changes: 0 additions & 4 deletions avs_core/core/parser/expression.h
Expand Up @@ -38,9 +38,7 @@
#include <avisynth.h>
#include "../function.h"

#ifdef NEW_AVSVALUE
#include <vector>
#endif
#include <atomic>

/********************************************************************
Expand Down Expand Up @@ -109,9 +107,7 @@ class ExpRootBlock : public Expression
class ExpConstant : public Expression
{
public:
#ifdef NEW_AVSVALUE
ExpConstant(std::vector<AVSValue>* v) : val(v->data(), (int)(v->size())) {} // array of AVSValue*
#endif
ExpConstant(AVSValue v) : val(v) {}
ExpConstant(int i) : val(i) {}
ExpConstant(float f) : val(f) {}
Expand Down
5 changes: 0 additions & 5 deletions avs_core/core/parser/script.cpp
Expand Up @@ -299,7 +299,6 @@ extern const AVSFunction Script_functions[] = {
{ "VarExist", BUILTIN_FUNC_PREFIX, "s", VarExist }, // 180606-


#ifdef NEW_AVSVALUE
// Creates script array from zero or more anything.
// Direct array constant syntax e.g. x = [arg1,arg2,...] is translated to x = Array(arg1,arg2,...)
{ "Array", BUILTIN_FUNC_PREFIX, ".*", ArrayCreate },
Expand All @@ -316,7 +315,6 @@ extern const AVSFunction Script_functions[] = {
/*
{ "IsArrayOf", BUILTIN_FUNC_PREFIX, ".s", IsArrayOf },
*/
#endif
{ 0 }
};

Expand Down Expand Up @@ -2163,8 +2161,6 @@ AVSValue VarExist(AVSValue args, void*, IScriptEnvironment* env)
}


#ifdef NEW_AVSVALUE

AVSValue ArrayCreate(AVSValue args, void*, IScriptEnvironment* env)
{
return args[0];
Expand Down Expand Up @@ -2286,4 +2282,3 @@ AVSValue ArrayDel(AVSValue args, void*, IScriptEnvironment* env)
return AVSValue(new_val.data(), orig_size - 1);
}

#endif
2 changes: 0 additions & 2 deletions avs_core/core/parser/script.h
Expand Up @@ -287,13 +287,11 @@ AVSValue IsFloatUvZeroBased(AVSValue args, void*, IScriptEnvironment* env); // a
AVSValue BuildPixelType(AVSValue args, void*, IScriptEnvironment* env); // avs+ 180517
AVSValue VarExist(AVSValue args, void*, IScriptEnvironment* env); // avs+ 180606

#ifdef NEW_AVSVALUE
AVSValue ArrayCreate(AVSValue args, void*, IScriptEnvironment* env);
AVSValue IsArray(AVSValue args, void*, IScriptEnvironment* env);
AVSValue ArrayGet(AVSValue args, void*, IScriptEnvironment* env);
AVSValue ArraySize(AVSValue args, void*, IScriptEnvironment* env);
AVSValue ArrayIns(AVSValue args, void*, IScriptEnvironment* env);
AVSValue ArrayDel(AVSValue args, void*, IScriptEnvironment* env);
#endif

#endif // __Script_H__
10 changes: 0 additions & 10 deletions avs_core/core/parser/scriptparser.cpp
Expand Up @@ -161,7 +161,6 @@ PExpression ScriptParser::ParseFunctionDefinition(void)
else if (tokenizer.IsIdentifier("string")) type = 's';
else if (tokenizer.IsIdentifier("clip")) type = 'c';
else if (tokenizer.IsIdentifier("func")) type = 'n';
#ifdef NEW_AVSVALUE
// AVS+ 161028 array type in user defined functions
else if (tokenizer.IsIdentifier("array") || tokenizer.IsIdentifier("val_array")) {
array_kind = '*'; type = '.';
Expand Down Expand Up @@ -207,7 +206,6 @@ PExpression ScriptParser::ParseFunctionDefinition(void)
else if (tokenizer.IsIdentifier("func_array_nz")) {
array_kind = '+'; type = 'n';
}
#endif
else env->ThrowError("Script error: expected \"val\", \"bool\", \"int\", \"float\", \"string\", \"array\", or \"clip\" (or their \"_array\" or \"_array_nz\" versions");
tokenizer.NextToken();
}
Expand Down Expand Up @@ -661,13 +659,6 @@ PExpression ScriptParser::ParseUnary(void) {

PExpression ScriptParser::ParseOOP(void)
{
#ifndef NEW_AVSVALUE
PExpression left = ParseFunction(nullptr);
while (tokenizer.IsOperator('.')) {
tokenizer.NextToken();
left = ParseFunction(left);
}
#else
// check if need convert [] brackets to function calls: Array() and ArrayGet()
// no context and [: e.g. x = [23,2] --> x = Array(23,2)
PExpression left;
Expand All @@ -687,7 +678,6 @@ PExpression ScriptParser::ParseOOP(void)
else
left = ParseFunction(left);
}
#endif
return left;
}

Expand Down
2 changes: 0 additions & 2 deletions avs_core/filters/conditional/conditional.cpp
Expand Up @@ -84,9 +84,7 @@ extern const AVSFunction Conditional_filters[] = {
{ "propSet", BUILTIN_FUNC_PREFIX, "csi[mode]i", SetProperty::Create, (void*)10 },
{ "propSet", BUILTIN_FUNC_PREFIX, "csf[mode]i", SetProperty::Create, (void*)11 },
{ "propSet", BUILTIN_FUNC_PREFIX, "css[mode]i", SetProperty::Create, (void*)12 },
#ifdef NEW_AVSVALUE
{ "propSet", BUILTIN_FUNC_PREFIX, "csa", SetProperty::Create, (void*)13 }, // no mode parameter, full entry refresh
#endif
{ "propSet", BUILTIN_FUNC_PREFIX, "csc[mode]i", SetProperty::Create, (void*)14 },

{ "propDelete", BUILTIN_FUNC_PREFIX, "cs", DeleteProperty::Create },
Expand Down

0 comments on commit 2103827

Please sign in to comment.