Fix [RT#83426] wrong weak test with globals

Do not use globals with weaken, or deal with global
destruction warnings. Changed to use proper lexicals