Branch: Tag:

2019-04-05

2019-04-05 18:20:43 by Henrik Grubbström (Grubba) <grubba@grubba.org>

EFUNs: lfun::_destruct() may now inhibit explicit destruction.

lfun::_destruct() returning 1 now causes the object to survive
an explicit destruct() call. Note that the object will still
be destructed if the destruct is for any other reason.

3636:    }   }    - /*! @decl void destruct(void|object o) + /*! @decl int(1bit) destruct(void|object o)    *!    *! Mark an object as destructed.    *!
3645:    *!    *! All pointers and function pointers to this object will become zero.    *! The destructed object will be freed from memory as soon as possible. +  *! +  *! @returns +  *! Returns @expr{1@} if @[o] has an @[lfun::_destruct()] that +  *! returned @expr{1@} and inhibited destruction.    */   PMOD_EXPORT void f_destruct(INT32 args)   {    struct object *o; -  +  int ret;    if(args)    {    if(TYPEOF(Pike_sp[-args]) != T_OBJECT) {    if ((TYPEOF(Pike_sp[-args]) == T_INT) &&    (!Pike_sp[-args].u.integer)) { -  pop_n_elems(args); +  pop_n_elems(args-1);    return;    }    SIMPLE_ARG_TYPE_ERROR("destruct", 1, "object");
3677:    * counter is back down to zero.    */    o->flags |= OBJECT_PENDING_DESTRUCT; +  pop_n_elems(args); +  push_int(1);    return;    }    debug_malloc_touch(o); -  destruct_object (o, DESTRUCT_EXPLICIT); +  ret = destruct_object (o, DESTRUCT_EXPLICIT);    pop_n_elems(args); -  +  push_int(ret);    destruct_objects_to_destruct();   }   
9995:    ADD_EFUN("crypt",f_crypt,    tOr(tFunc(tOr(tStr,tVoid),tStr7),tFunc(tStr tStr,tInt01)),OPT_EXTERNAL_DEPEND);    -  /* function(object|void:void) */ -  ADD_EFUN("destruct",f_destruct,tFunc(tOr(tObj,tVoid),tVoid),OPT_SIDE_EFFECT); +  /* function(object|void:int(0..1)) */ +  ADD_EFUN("destruct",f_destruct,tFunc(tOr(tObj,tVoid),tInt01),OPT_SIDE_EFFECT);       ADD_EFUN("dirname", f_dirname, tFunc(tSetvar(0, tStr), tVar(0)), 0);