Proc-Exists

 view release on metacpan or  search on metacpan

Exists.xs  view on Meta::CPAN

		SV *pid_sv;
		int npids;
		int i;
		int exists;
		int total=0;
		int pid;

		/* make sure pids_ref is a ref pointing at an array with some elements */
		if ((!SvROK(pids_ref)) || (SvTYPE(SvRV(pids_ref)) != SVt_PVAV) || 
			 ((npids = av_len((AV *)SvRV(pids_ref))) < 0)) {
			XSRETURN_UNDEF;
		}
		pids = (AV *)SvRV(pids_ref);
	CODE:
		RETVAL=RETVAL_IS_UNSET;
		for(i=0; i<=npids; i++) {
			pid_sv = *av_fetch(pids, i, 0);

			pid = get_pid(pid_sv);

			exists = __pexists(pid);

			/* hook 1 */
			if( any && exists ) {
				RETVAL = pid; break;
			} else if( all && !exists ) {
				RETVAL = 0; break;
			} else {
				total+=exists;
			}
		}
		/* hook 2 */
		if( RETVAL==RETVAL_IS_UNSET ) {
			/* make sure 'any' mode returns undef, not 0 */
			if( any ) { XSRETURN_UNDEF; }
			RETVAL = total;
		}
	OUTPUT:
		RETVAL

### TODO: _list_pexists and _scalar_pexists are still VERY similar...
### must be some way to unify them further?
# XS implementation for list context
void
_list_pexists(pids_ref)
		SV *pids_ref
	INIT:
		AV *pids;
		SV *pid_sv;
		int npids;
		int i;
		int exists;
		int pid;

		/* make sure pids_ref is a ref pointing at an array with some elements */
		if ((!SvROK(pids_ref)) || (SvTYPE(SvRV(pids_ref)) != SVt_PVAV) || 
			 ((npids = av_len((AV *)SvRV(pids_ref))) < 0)) {
			XSRETURN_UNDEF;
		}
		pids = (AV *)SvRV(pids_ref);
	PPCODE:
		for(i=0; i<=npids; i++) {
			pid_sv = *av_fetch(pids, i, 0);

			pid = get_pid(pid_sv);

			exists = __pexists(pid);

			/* hook 1 */
			if(exists) {
				mXPUSHi(pid);
			}
		}
		/* (no hook 2) */




( run in 1.574 second using v1.01-cache-2.11-cpan-5511b514fd6 )