libk  Diff

Differences From Artifact [70c3679214]:

To Artifact [5d74e5db6e]:


     3      3   /* heapo.fn.c - kmheapo() "allocate heap object"
     4      4    * ~ lexi hale <lexi@hale.su>
     5      5    * kmheapo() allocates a region in heap memory
     6      6    * and returns a kmptr struct referencing that
     7      7    * newly allocated region.
     8      8    */
     9      9   
    10         -kmcond kmheapo(kmptr* where, sz size) {
    11         -	void* ptr;
    12         -	kmcond e = kmheapa(&ptr, size);
    13         -	if (e != kmcond_ok) return e;
           10  +kmres kmheapo(sz size) {
           11  +	kmres e = kmheapa(size);
           12  +	kmres reply;
           13  +
           14  +	if (e.cond != kmcond_ok) {
           15  +		reply.cond = e.cond;
           16  +		reply.ptr.ref = (void*)0;
           17  +		reply.ptr.kind = kmkind_broken;
           18  +		return reply;
           19  +	}
           20  +
    14     21   	kmptr p = {
    15         -		.kind = (ptr != null ? kmkind_heap : kmkind_fail),
    16         -		.ref = ptr,
           22  +		.kind = (e.raw != null ? kmkind_heap : kmkind_broken),
           23  +		.ref = e.raw,
    17     24   		.shred = false,
    18     25   	};
    19         -	*where = p;
    20         -	return kmcond_ok;
           26  +
           27  +	reply.ptr = p;
           28  +	reply.cond = kmcond_ok;
           29  +	return reply;
    21     30   }