Without seeing plausible code that uses this I'm not convinced that the ref counting scheme is useful.
I see several "simpler" options:
1. never pass "ownership" to the client and require them to save anything they want. That could simply be:
void* mir_platform_message_take_data(message, &size) and
int* mir_platform_message_take_fds(message, &nfds)
Without seeing plausible code that uses this I'm not convinced that the ref counting scheme is useful.
I see several "simpler" options:
1. never pass "ownership" to the client and require them to save anything they want. That could simply be: message_ take_data( message, &size) and message_ take_fds( message, &nfds)
void* mir_platform_
int* mir_platform_
...
free(data);
for (int* fd = fds; fd != fds+nfds; ++fd) close(*fd);
free(fds);
2. always pass "ownership" and require mir_platform_ message_ release( message) to be called
3. Have the callback return a bool indicating whether ownership has been taken. (Which, at least, gives a compile error if no decision is taken.)
But I'm ready to be told that all the above are simplistic and ref counting is a requirement.