# Why get\_next is called when both get\_next and get\_next\_object are defined when printing full table entries?

**URL:** <https://dmap-community.ductus.global/t/why-get-next-is-called-when-both-get-next-and-get-next-object-are-defined-when-printing-full-table-entries/2438>\
**Category:** CDB and CDB API\
**Created:** [April 25, 2019, 11:32am UTC](https://dmap-community.ductus.global/t/why-get-next-is-called-when-both-get-next-and-get-next-object-are-defined-when-printing-full-table-entries/2438 "2019-04-25T11:32:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yateesh](https://avatars.discourse-cdn.com/v4/letter/y/74df32/32.png) [@yateesh](https://dmap-community.ductus.global/u/yateesh)\
**Post date:** [April 25, 2019, 11:32am UTC](https://dmap-community.ductus.global/t/why-get-next-is-called-when-both-get-next-and-get-next-object-are-defined-when-printing-full-table-entries/2438/1 "2019-04-25T11:32:32Z")

</div>

I executed following CLI table,

```
user@host> show arpentries arpe
IP IFNAME HWADDR PERMANENT PUBLISHED
--------------------------------------------------------------
172.16.1.1 eth0 fa:16:3e:5b:ad:2c false false
172.16.1.10 eth0 fa:16:3e:ff:c6:24 false false

[ok][2019-04-25 07:40:18]

```

Following is trace:  
`TRACE CALL data get_next(thandle=7, /arpentries/arpe, -1) --> CONFD_OK TRACE CALL data get_next_object(thandle=7, /arpentries/arpe, -1) --> CONFD_OK TRACE CALL data get_next_object(thandle=7, /arpentries/arpe, 0) --> CONFD_OK`

I have registered both get\_next and get\_next\_object  
data.get\_elem = get\_elem;  
data.get\_next = get\_next;  
data.get\_next\_object = get\_next\_object;  
strcpy(data.callpoint, arpe\_\_callpointid\_arpe);

Question is:  
Why both get\_next and get\_next\_object is being called when table is queried?

All data required to be displayed for operational CLI can be obtained from get\_next\_object.  
So why get\_next is being called?

Is there any way I can suppress first get\_next being called?

Reason for asking,  
We are doing some cleanup/allocation when we get “-1” as “next” value. Since “-1” is passed twice, double cleanup/allocation happens.

---

<div class="post-metadata">

**Author:** ![josephm](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@josephm](https://dmap-community.ductus.global/u/josephm)\
**Post date:** [April 29, 2019, 8:07am UTC](https://dmap-community.ductus.global/t/why-get-next-is-called-when-both-get-next-and-get-next-object-are-defined-when-printing-full-table-entries/2438/3 "2019-04-29T08:07:09Z")

</div>

This is most probably invoked internally for ConfD as an existence check / check whether any data is present in the list before further processing…  
IMHO you cannot disable it explicitly - maybe other callbacks like _.num\_instances()_ can be added to be invoked instead of get\_next() by ConfD if it makes your situation easier (i haven’t tested myself if it works this way).

---

<div class="post-metadata">

**Author:** ![yateesh](https://avatars.discourse-cdn.com/v4/letter/y/74df32/32.png) [@yateesh](https://dmap-community.ductus.global/u/yateesh)\
**Post date:** [April 29, 2019, 8:35pm UTC](https://dmap-community.ductus.global/t/why-get-next-is-called-when-both-get-next-and-get-next-object-are-defined-when-printing-full-table-entries/2438/4 "2019-04-29T20:35:46Z")

</div>

Thanks for reply.  
Exposing num\_instances didn’t help. Still get\_next was called.

---

<div class="post-metadata">

**Author:** ![yateesh](https://avatars.discourse-cdn.com/v4/letter/y/74df32/32.png) [@yateesh](https://dmap-community.ductus.global/u/yateesh)\
**Post date:** [April 30, 2019, 6:57am UTC](https://dmap-community.ductus.global/t/why-get-next-is-called-when-both-get-next-and-get-next-object-are-defined-when-printing-full-table-entries/2438/5 "2019-04-30T06:57:50Z")

</div>

Any other thoughts?

Is it safe to assume that get\_next will always be called before calling get\_next\_object? Based on some experiments, it looks like that.  
So that I do memory allocation only in get\_next (when next = -1) and ignore memory allocation for get\_next\_object.

---

<div class="post-metadata">

**Author:** ![mghosh](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@mghosh](https://dmap-community.ductus.global/u/mghosh)\
**Post date:** [April 30, 2019, 10:41am UTC](https://dmap-community.ductus.global/t/why-get-next-is-called-when-both-get-next-and-get-next-object-are-defined-when-printing-full-table-entries/2438/6 "2019-04-30T10:41:00Z")

</div>

We used to have the same issue. If we do not register get\_next\_object() then confd would invoke get\_next() twice with next = -1. In first next = -1 call, we used to place the malloced data in tctx-\>t\_opaque (otherwise NULL before this). And then this t\_opaque data is propagated to next get\_next() or get\_next\_object() calls. We avoided allocation there by checking if t\_opaque is already non-NULL.
