Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Development

Development::Development Forum for development topics and for those interested in EQEMu development. (Not a support forum)

Reply
 
Thread Tools Display Modes
  #1  
Old 12-31-2012, 03:30 AM
c0ncrete's Avatar
c0ncrete
Dragon
 
Join Date: Dec 2009
Posts: 719
Default perlxs and hash refs

this seems to work (i get a hashref with the correct data), but since i'm having a hard time making sense of the perlxs documentation and there doesn't seem to be any code in the server source that returns a reference to a hash in this manner (using eval doesn't count!), i was wondering if i've made any grievous errors here that would cause memory leaks or any other undesirable issues.

Code:
XS(XS_Mob_Loc); /* prototype to pass -Wmissing-prototypes */
XS(XS_Mob_Loc)
{
    dXSARGS;
    if (items != 1)
        Perl_croak(aTHX_ "Usage: Mob::Loc(THIS)");
    {
        Mob * THIS;
        dXSTARG;

        if (sv_derived_from(ST(0), "Mob")) {
            IV tmp = SvIV((SV*)SvRV(ST(0)));
            THIS = INT2PTR(Mob *,tmp);
        }
        else
            Perl_croak(aTHX_ "THIS is not of type Mob");
        if(THIS == NULL)
            Perl_croak(aTHX_ "THIS is NULL, avoiding crash.");

        HV * loc_hash = (HV *)sv_2mortal((SV *)newHV());

        hv_store(loc_hash, "x", 1, newSVnv(THIS->GetX()), 0);
        hv_store(loc_hash, "y", 1, newSVnv(THIS->GetY()), 0);
        hv_store(loc_hash, "z", 1, newSVnv(THIS->GetZ()), 0);
        hv_store(loc_hash, "h", 1, newSVnv(THIS->GetHeading()), 0);

        ST(0) = newRV_noinc((SV *)loc_hash);
    }
    XSRETURN(1);
}
Reply With Quote
  #2  
Old 12-31-2012, 03:34 PM
KLS
Administrator
 
Join Date: Sep 2006
Posts: 1,348
Default

Seems like you handled mortality which is the most obvious problem that can arise with regards to memory.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 06:15 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3