Fixing Auto vivify Bug's. [2.0.7 ~ 2.1]

Wrote new code? Fixed a bug? Want to discuss technical stuff? Feel free to post it here.

Moderator: Moderators

Message
Author
User avatar
kLabMouse
Administrator
Administrator
Posts: 1301
Joined: 24 Apr 2008, 12:02

Fixing Auto vivify Bug's. [2.0.7 ~ 2.1]

#1 Post by kLabMouse »

As all active dev's know... We have too much auto vivification bug's around.

There is 2 solutions to finally fix them all:
1) Use the native perl feature described in Synopsis_09->Autovivification Document. It need alot of auditing code inside Kore itself. To make this task more easy there exist a little package Tie::Trace (Bug still, I donno how it will work with Blessing and Overloading)
2) We can Rewrite whole Actors and Environmental objects system to more OpenKore 3.0 model where you can't easly add or delete Actors and all actions and modifications done by their API with a lot of Validations and gettery-settery method's.


Well. The first solution is not very good at Plugins point. They still can cause core errors.
The second solution need alot of coding, and will break all existing plugins.

We are open for your Suggestions on this problem.

User avatar
kLabMouse
Administrator
Administrator
Posts: 1301
Joined: 24 Apr 2008, 12:02

Re: Fixing Auto vivify Bug's. [2.0.7 ~ 2.1]

#2 Post by kLabMouse »

Oh. forgot. there is additional package to handle our problem Tie::Hash::Vivify.
But it's still version 0.01.

Scarya
Moderators
Moderators
Posts: 136
Joined: 26 May 2008, 12:25
Noob?: No

Re: Fixing Auto vivify Bug's. [2.0.7 ~ 2.1]

#3 Post by Scarya »

I prefer using getter and setter as they are common in oop and we can validate better. It will be a lot of work rewritting all the plugins, but I think it's better.
Btw. I think with implementation of getter/setter it's easier to develope new plugins...
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the universe trying to produce bigger and better idiots.
So far, the universe is winning.

Richard Cook

Wiki

User avatar
kLabMouse
Administrator
Administrator
Posts: 1301
Joined: 24 Apr 2008, 12:02

Re: Fixing Auto vivify Bug's. [2.0.7 ~ 2.1]

#4 Post by kLabMouse »

Found 2 more things.
1st:
You can lock the hash using one of the functions from Hash::Util (a core module).

Code: Select all

use Hash::Util qw( lock_keys unlock_keys );
my $some_ref = { akey => { deeper => 1 } };
lock_keys %$some_ref;
print "too deep" if $some_ref->{deep}{shit} == 1;
Now the last statement will throw an exception:

Code: Select all

Attempt to access disallowed key 'deep' in a restricted hash
The downside is, of course, that you'll have to be very careful when
checking for keys in the hash to avoid exceptions, i.e. use a lof of "if exists ..." to check for keys before you access them.

If you need to add keys to the hash again later you can unlock it:

Code: Select all

unlock_keys %$some_ref;
$some_ref->{foo} = 'bar'; # no exception
2nd:
also found this little CPAN package autovivification

Also found this little trick to fully trace all the nasty things.
Just add

Code: Select all

use warnings NONFATAL => 'all', FATAL => 'uninitialized';
to all packages, to finally trace all non good coded places.

User avatar
kLabMouse
Administrator
Administrator
Posts: 1301
Joined: 24 Apr 2008, 12:02

Re: Fixing Auto vivify Bug's. [2.0.7 ~ 2.1]

#5 Post by kLabMouse »

Most of AutoVivify is now fetched in the first place by Tie::ActorHash.
Fixed by EternalHarvest in r7229

It will not prevent us from thus reports, but at least now we can see where they happen to be called.
Thanks =)

Post Reply