What exactly needs to be PROTECTed when writing C functions for use in R -


I thought it is very easy, basically, type any SEXP I protected Stay, but when using the linked lists and CAR / CDR etc. this little blurry is starting (for me). With this comment I :

The security of an R object automatically protects all R objects pointing to the related SSPPEC, for example a protected list All elements of this are automatically protected.

and it is from:

A SEXPREC is a compound that has the 32-bit header described above, the three points ( Attributes, previous and next node) and node data ...

LISTSXP: Indicators for a ser, CDR (usually a LISTSXP or tap) and tags (a SYMSXP or tap)

So I understand that, if I do something like this:

  SEXP s, t, u; Defense (S = Algorithm (2)); SECACR (S, Scalarological (1)); SETCADR (S, Scalarological (0)); T = CAR (S); U = CADR (S);  

Then objects are protected on the basis of the t and u points that contain the protected list s (Proportional question: Is there any way to get a protected position of an object? Can not see anything in Rinternals.h which could fit the bill) However, I start with (like stuff from src / main / unique.c ):

  // line starting from 1274 (R 3.0.2), note ` RGS` // has been preserved on the basis of a function logic SEXP attribute_hidden do_matchcall (SEXP call, SEXP session, SEX args, SEXNY) {// a bunch of lines, and then, on line 1347: Protection (B = CR (ARG)); // ...}  

It suggests that all the objects within args are not secure, but it seems very strange since then, since no one args objects may have got GCed at any point. Since CAR simply gives an indicator on an already protected object, why do we need to preserve it here?

Think about it this way: defense object is actually nothing Instead, it adds a floating GC root so that the object is considered to be alive by the collector. It is also alive in any object, because it is not due to some safety applied to C, but because they are indicated by another object - which is already considered alive - It is similar to any other normal living thing, so setting up a protected train cart not only keeps the object alive, it was released for the GC in the car, whatever could potentially release That is, that particular thing Removing the financial tree (affect successive elements security list).

So in general you are not going to have an easy way of saying whether the object is "preserved" or not, in this broad sense, because it is actually only following the rules GC Somewhere else and there is nothing special about the object. You can potentially find out through the entire defense list and see if you think, but it will be ... disabled, say For at least (say there too Uc is not even owned tree object of defense question from one of the list is that it will survive the longest). In the

do_matchcall line is actually there for a completely unrelated reason: security (RAG) is protected in only one branch - In the second branch, this is a newly created item which becomes safe, along with protecting the value from this branch, it means that the code on the PROTECT stack is guaranteed to be the same number Is that even if the branch has been taken, which at the end of the related UNPROTECT function Operation at a constant number of slots (no need to check to isolate it down).


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -