partial_unref(partial_T *pt)
{
    if (pt != NULL)
    {
	int	done = FALSE;

	if (--pt->pt_refcount <= 0)
	    partial_free(pt);

	// If the reference count goes down to one, the funcstack may be the
	// only reference and can be freed if no other partials reference it.
	else if (pt->pt_refcount == 1)
	{
	    // careful: if the funcstack is freed it may contain this partial
	    // and it gets freed as well
	    if (pt->pt_funcstack != NULL)
		done = funcstack_check_refcount(pt->pt_funcstack);

	    if (!done)
	    {
		int	depth;

		for (depth = 0; depth < MAX_LOOP_DEPTH; ++depth)
		    if (pt->pt_loopvars[depth] != NULL
			    && loopvars_check_refcount(pt->pt_loopvars[depth]))
		    break;
	    }
	}
    }
}
partial_unref(partial_T *pt)
{
    if (pt != NULL)
    {
	int	done = FALSE;

	if (--pt->pt_refcount <= 0)
	    partial_free(pt);

	 
	 
	else if (pt->pt_refcount == 1)
	{
	     
	     
	    if (pt->pt_funcstack != NULL)
		done = funcstack_check_refcount(pt->pt_funcstack);

	    if (!done)
	    {
		int	depth;

		for (depth = 0; depth < MAX_LOOP_DEPTH; ++depth)
		    if (pt->pt_loopvars[depth] != NULL
			    && loopvars_check_refcount(pt->pt_loopvars[depth]))
		    break;
	    }
	}
    }
}