Hello Monks,
I am working on a perl5 adapter for the gRPC api, using perlxs (
https://github.com/joyrex2001/grpc-perl). In this implementation I am passing xs-objects as input to other xs-objects. The problem I have it that when I use these objects, the reference count is not increased, and the objects are de-scoped to early.
As an example, consider the following setup:
Grpc::XS::Call T_PTROBJ
Grpc::XS::Channel T_PTROBJ
Grpc::XS::Timeval T_PTROBJ
In the call constructor, I pass both a Channel and Timeval instance, see:
Grpc::XS::Call
new(const char *class, Grpc::XS::Channel channel, \
const char* method, Grpc::XS::Timeval deadline, ... )
PREINIT:
CallCTX* ctx = (CallCTX *)malloc( sizeof(CallCTX) );
ctx->wrapped = NULL;
CODE:
## some code removed ##
ctx->wrapped = grpc_channel_create_call(
channel->wrapped, NULL, GRPC_PROPAGATE_DEFAULTS,
completion_queue, method, host_override,
deadline->wrapped, NULL);
RETVAL = ctx;
OUTPUT: RETVAL
When the constructor is called, the timeval object is already out-of-scope, and gets dereferenced by perl. However, this is actually not correct, since it's only out of scope in perl, not in my xs scope.
I think the best way forward would be to increase the refcount of the object so the object is not destoyed yet, any tips how to do that? Or maybe there is another approach?
Gr., Vincent
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.