📄 perlapi.pod
字号:
=item hv_iterkeyX<hv_iterkey>Returns the key from the current position of the hash iterator. SeeC<hv_iterinit>. char* hv_iterkey(HE* entry, I32* retlen)=for hackersFound in file hv.c=item hv_iterkeysvX<hv_iterkeysv>Returns the key as an C<SV*> from the current position of the hashiterator. The return value will always be a mortal copy of the key. Alsosee C<hv_iterinit>. SV* hv_iterkeysv(HE* entry)=for hackersFound in file hv.c=item hv_iternextX<hv_iternext>Returns entries from a hash iterator. See C<hv_iterinit>.You may call C<hv_delete> or C<hv_delete_ent> on the hash entry that theiterator currently points to, without losing your place or invalidating youriterator. Note that in this case the current entry is deleted from the hashwith your iterator holding the last reference to it. Your iterator is flaggedto free the entry on the next call to C<hv_iternext>, so you must not discardyour iterator immediately else the entry will leak - call C<hv_iternext> totrigger the resource deallocation. HE* hv_iternext(HV* tb)=for hackersFound in file hv.c=item hv_iternextsvX<hv_iternextsv>Performs an C<hv_iternext>, C<hv_iterkey>, and C<hv_iterval> in oneoperation. SV* hv_iternextsv(HV* hv, char** key, I32* retlen)=for hackersFound in file hv.c=item hv_iternext_flagsX<hv_iternext_flags>Returns entries from a hash iterator. See C<hv_iterinit> and C<hv_iternext>.The C<flags> value will normally be zero; if HV_ITERNEXT_WANTPLACEHOLDERS isset the placeholders keys (for restricted hashes) will be returned in additionto normal keys. By default placeholders are automatically skipped over.Currently a placeholder is implemented with a value that isC<&Perl_sv_placeholder>. Note that the implementation of placeholders andrestricted hashes may change, and the implementation currently isinsufficiently abstracted for any change to be tidy.NOTE: this function is experimental and may change or beremoved without notice. HE* hv_iternext_flags(HV* tb, I32 flags)=for hackersFound in file hv.c=item hv_itervalX<hv_iterval>Returns the value from the current position of the hash iterator. SeeC<hv_iterkey>. SV* hv_iterval(HV* tb, HE* entry)=for hackersFound in file hv.c=item hv_magicX<hv_magic>Adds magic to a hash. See C<sv_magic>. void hv_magic(HV* hv, GV* gv, int how)=for hackersFound in file hv.c=item hv_scalarX<hv_scalar>Evaluates the hash in scalar context and returns the result. Handles magic when the hash is tied. SV* hv_scalar(HV* hv)=for hackersFound in file hv.c=item hv_storeX<hv_store>Stores an SV in a hash. The hash key is specified as C<key> and C<klen> isthe length of the key. The C<hash> parameter is the precomputed hashvalue; if it is zero then Perl will compute it. The return value will beNULL if the operation failed or if the value did not need to be actuallystored within the hash (as in the case of tied hashes). Otherwise it canbe dereferenced to get the original C<SV*>. Note that the caller isresponsible for suitably incrementing the reference count of C<val> beforethe call, and decrementing it if the function returned NULL. Effectivelya successful hv_store takes ownership of one reference to C<val>. This isusually what you want; a newly created SV has a reference count of one, soif all your code does is create SVs then store them in a hash, hv_storewill own the only reference to the new SV, and your code doesn't need to doanything further to tidy up. hv_store is not implemented as a call tohv_store_ent, and does not create a temporary SV for the key, so if yourkey data is not already in SV form then use hv_store in preference tohv_store_ent.See L<perlguts/"Understanding the Magic of Tied Hashes and Arrays"> for moreinformation on how to use this function on tied hashes. SV** hv_store(HV* tb, const char* key, I32 klen, SV* val, U32 hash)=for hackersFound in file hv.c=item hv_storesX<hv_stores>Like C<hv_store>, but takes a literal string instead of a string/length pairand omits the hash parameter. SV** hv_stores(HV* tb, const char* key, NULLOK SV* val)=for hackersFound in file handy.h=item hv_store_entX<hv_store_ent>Stores C<val> in a hash. The hash key is specified as C<key>. The C<hash>parameter is the precomputed hash value; if it is zero then Perl willcompute it. The return value is the new hash entry so created. It will beNULL if the operation failed or if the value did not need to be actuallystored within the hash (as in the case of tied hashes). Otherwise thecontents of the return value can be accessed using the C<He?> macrosdescribed here. Note that the caller is responsible for suitablyincrementing the reference count of C<val> before the call, anddecrementing it if the function returned NULL. Effectively a successfulhv_store_ent takes ownership of one reference to C<val>. This isusually what you want; a newly created SV has a reference count of one, soif all your code does is create SVs then store them in a hash, hv_storewill own the only reference to the new SV, and your code doesn't need to doanything further to tidy up. Note that hv_store_ent only reads the C<key>;unlike C<val> it does not take ownership of it, so maintaining the correctreference count on C<key> is entirely the caller's responsibility. hv_storeis not implemented as a call to hv_store_ent, and does not create a temporarySV for the key, so if your key data is not already in SV form then usehv_store in preference to hv_store_ent.See L<perlguts/"Understanding the Magic of Tied Hashes and Arrays"> for moreinformation on how to use this function on tied hashes. HE* hv_store_ent(HV* tb, SV* key, SV* val, U32 hash)=for hackersFound in file hv.c=item hv_undefX<hv_undef>Undefines the hash. void hv_undef(HV* tb)=for hackersFound in file hv.c=item newHVX<newHV>Creates a new HV. The reference count is set to 1. HV* newHV()=for hackersFound in file hv.c=back=head1 Magical Functions=over 8=item mg_clearX<mg_clear>Clear something magical that the SV represents. See C<sv_magic>. int mg_clear(SV* sv)=for hackersFound in file mg.c=item mg_copyX<mg_copy>Copies the magic from one SV to another. See C<sv_magic>. int mg_copy(SV* sv, SV* nsv, const char* key, I32 klen)=for hackersFound in file mg.c=item mg_findX<mg_find>Finds the magic pointer for type matching the SV. See C<sv_magic>. MAGIC* mg_find(const SV* sv, int type)=for hackersFound in file mg.c=item mg_freeX<mg_free>Free any magic storage used by the SV. See C<sv_magic>. int mg_free(SV* sv)=for hackersFound in file mg.c=item mg_getX<mg_get>Do magic after a value is retrieved from the SV. See C<sv_magic>. int mg_get(SV* sv)=for hackersFound in file mg.c=item mg_lengthX<mg_length>Report on the SV's length. See C<sv_magic>. U32 mg_length(SV* sv)=for hackersFound in file mg.c=item mg_magicalX<mg_magical>Turns on the magical status of an SV. See C<sv_magic>. void mg_magical(SV* sv)=for hackersFound in file mg.c=item mg_setX<mg_set>Do magic after a value is assigned to the SV. See C<sv_magic>. int mg_set(SV* sv)=for hackersFound in file mg.c=item SvGETMAGICX<SvGETMAGIC>Invokes C<mg_get> on an SV if it has 'get' magic. This macro evaluates itsargument more than once. void SvGETMAGIC(SV* sv)=for hackersFound in file sv.h=item SvLOCKX<SvLOCK>Arranges for a mutual exclusion lock to be obtained on sv if a suitable modulehas been loaded. void SvLOCK(SV* sv)=for hackersFound in file sv.h=item SvSETMAGICX<SvSETMAGIC>Invokes C<mg_set> on an SV if it has 'set' magic. This macro evaluates itsargument more than once. void SvSETMAGIC(SV* sv)=for hackersFound in file sv.h=item SvSetMagicSVX<SvSetMagicSV>Like C<SvSetSV>, but does any set magic required afterwards. void SvSetMagicSV(SV* dsb, SV* ssv)=for hackersFound in file sv.h=item SvSetMagicSV_nostealX<SvSetMagicSV_nosteal>Like C<SvSetSV_nosteal>, but does any set magic required afterwards. void SvSetMagicSV_nosteal(SV* dsv, SV* ssv)=for hackersFound in file sv.h=item SvSetSVX<SvSetSV>Calls C<sv_setsv> if dsv is not the same as ssv. May evaluate argumentsmore than once. void SvSetSV(SV* dsb, SV* ssv)=for hackersFound in file sv.h=item SvSetSV_nostealX<SvSetSV_nosteal>Calls a non-destructive version of C<sv_setsv> if dsv is not the same asssv. May evaluate arguments more than once. void SvSetSV_nosteal(SV* dsv, SV* ssv)=for hackersFound in file sv.h=item SvSHAREX<SvSHARE>Arranges for sv to be shared between threads if a suitable modulehas been loaded. void SvSHARE(SV* sv)=for hackersFound in file sv.h=item SvUNLOCKX<SvUNLOCK>Releases a mutual exclusion lock on sv if a suitable modulehas been loaded. void SvUNLOCK(SV* sv)=for hackersFound in file sv.h=back=head1 Memory Management=over 8=item CopyX<Copy>The XSUB-writer's interface to the C C<memcpy> function. The C<src> is thesource, C<dest> is the destination, C<nitems> is the number of items, and C<type> isthe type. May fail on overlapping copies. See also C<Move>. void Copy(void* src, void* dest, int nitems, type)=for hackersFound in file handy.h=item CopyDX<CopyD>Like C<Copy> but returns dest. Useful for encouraging compilers to tail-calloptimise. void * CopyD(void* src, void* dest, int nitems, type)=for hackersFound in file handy.h=item MoveX<Move>The XSUB-writer's interface to the C C<memmove> function. The C<src> is thesource, C<dest> is the destination, C<nitems> is the number of items, and C<type> isthe type. Can do overlapping moves. See also C<Copy>. void Move(void* src, void* dest, int nitems, type)=for hackersFound in file handy.h=item MoveDX<MoveD>Like C<Move> but returns dest. Useful for encouraging compilers to tail-calloptimise. void * MoveD(void* src, void* dest, int nitems, type)=for hackersFound in file handy.h=item NewxX<Newx>The XSUB-writer's interface to the C C<malloc> function.In 5.9.3, Newx() and friends replace the older New() API, and dropsthe first parameter, I<x>, a debug aid which allowed callers to identifythemselves. This aid has been superseded by a new build option,PERL_MEM_LOG (see L<perlhack/PERL_MEM_LOG>). The older API is stillthere for use in XS modules supporting older perls. void Newx(void* ptr, int nitems, type)=for hackersFound in file handy.h=item NewxcX<Newxc>The XSUB-writer's interface to the C C<malloc> function, withcast. See also C<Newx>. void Newxc(void* ptr, int nitems, type, cast)=for hackersFound in file handy.h=item NewxzX<Newxz>The XSUB-writer's interface to the C C<malloc> function. The allocatedmemory is zeroed with C<memzero>. See also C<Newx>. void Newxz(void* ptr, int nitems, type)=for hackersFound in file handy.h=item PoisonX<Poison>PoisonWith(0xEF) for catching access to freed memory. void Poison(void* dest, int nitems, type)=for hackersFound in file handy.h=item PoisonFreeX<PoisonFree>PoisonWith(0xEF) for catching access to freed memory. void PoisonFree(void* dest, int nitems, type)=for hackersFound in file handy.h=item PoisonNewX<PoisonNew>PoisonWith(0xAB) for catching access to allocated but uninitialized memory. void PoisonNew(void* dest, int nitems, type)=for hackersFound in file handy.h=item PoisonWithX<PoisonWith>Fill up memory with a byte pattern (a byte repeated over and overagain) that hopefully catches attempts to access uninitialized memory. void PoisonWith(void* dest, int nitems, type, U8 byte)=for hackersFound in file handy.h=item RenewX<Renew>The XSUB-writer's interface to the C C<realloc> function. void Renew(void* ptr, int nitems, type)=for hackersFound in file handy.h=item RenewcX<Renewc>The XSUB-writer's interface to the C C<realloc> function, withcast. void Renewc(void* ptr, int nitems, type, cast)=for hackersFound in file handy.h=item SafefreeX<Safefree>The XSUB-writer's interface to the C C<free> function. void Safefree(void* ptr)=for hackersFound in file handy.h=item savepvX<savepv>Perl's version of C<strdup()>. Returns a pointer to a newly allocatedstring which is a duplicate of C<pv>. The size of the string isdetermined by C<strlen()>. The memory allocated for the new string canbe freed with the C<Safefree()> function. char* savepv(const char* pv)=for hackersFound in file util.c=item savepvnX<savepvn>Perl's version of what C<strndup()> would be if it existed. Returns apointer to a newly allocated string which is a duplicate of the firstC<len> bytes from C<pv>, plus a trailing NUL byte. The memory allocated forthe new string can be freed with the C<Safefree()> function. char* savepvn(const char* pv, I32 len)=for hackersFound in file util.c=item savepvsX<savepvs>Like C<savepvn>, but takes a literal string instead of a string/length pair. char* savepvs(const char* s)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -