Merge pull request #3989 from 9rnsr/fix13476

[REG2.065] Issue 13476 - Writing stubs for dynamically loaded functions no longer works. (circular reference)
Merge pull request #3994 from 9rnsr/fix13472

[REG2.066] Issue 13472 - trying to insert a null into an array of object segfaults the compiler
Merge pull request #4003 from 9rnsr/2.066

Cherry-picking pull request #3961 for 2.066.1