You have:
#define FUNC_MAX_ARGS (INDEX_MAX_KEYS+1)
This is WRONG, I'm pretty sure --- FUNC_MAX_ARGS should be the same
as the length of oidvector.
User-declared functions can definitely only have as many args as there
are slots in oidvector, because that's all the room there is to declare
them in pg_proc.
You may have gotten confused because fmgr.c allowed 9 args to be passed,
even though there's no way to declare such a function; I think this was
a hack to support some special system usage --- possibly selectivity
estimators had 9 args at one time. (They don't now, so the 9th-arg
support was dead code as far as I can tell.) But if we are going to
increase the default MAX_ARGS above 8 then the issue goes away anyway,
and there's no need for fmgr.c to support more args than can normally
be declared.
regards, tom lane