libk  Diff

Differences From Artifact [70c3679214]:

To Artifact [5d74e5db6e]:


3
4
5
6
7
8
9
10
11
12


13






14
15
16
17
18

19
20

21
/* heapo.fn.c - kmheapo() "allocate heap object"
 * ~ lexi hale <lexi@hale.su>
 * kmheapo() allocates a region in heap memory
 * and returns a kmptr struct referencing that
 * newly allocated region.
 */

kmcond kmheapo(kmptr* where, sz size) {
	void* ptr;
	kmcond e = kmheapa(&ptr, size);


	if (e != kmcond_ok) return e;






	kmptr p = {
		.kind = (ptr != null ? kmkind_heap : kmkind_fail),
		.ref = ptr,
		.shred = false,
	};

	*where = p;
	return kmcond_ok;

}







|
<
|
>
>
|
>
>
>
>
>
>

|
|


>
|
|
>

3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* heapo.fn.c - kmheapo() "allocate heap object"
 * ~ lexi hale <lexi@hale.su>
 * kmheapo() allocates a region in heap memory
 * and returns a kmptr struct referencing that
 * newly allocated region.
 */

kmres kmheapo(sz size) {

	kmres e = kmheapa(size);
	kmres reply;

	if (e.cond != kmcond_ok) {
		reply.cond = e.cond;
		reply.ptr.ref = (void*)0;
		reply.ptr.kind = kmkind_broken;
		return reply;
	}

	kmptr p = {
		.kind = (e.raw != null ? kmkind_heap : kmkind_broken),
		.ref = e.raw,
		.shred = false,
	};

	reply.ptr = p;
	reply.cond = kmcond_ok;
	return reply;
}