Rf_errorcall - translate to Pascal

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Rf_errorcall - translate to Pascal

Hans-Peter Suter
Hello!

I (try to) convert the external R header files to Pascal (Delphi). At
one place I stumbled over a macro that uses a method that is not
declared in a LGPL header file:

In Rinternals.h:
   #define error_return(msg) { Rf_error(msg); return R_NilValue; }
   #define errorcall_return(cl,msg){ Rf_errorcall(cl, msg); return R_NilValue; }
                                                  ~~~~~~~~
In Error.h:
    void Rf_error(const char *, ...);
    [Rf_errorcall is not declared here, would be something like:
     void Rf_errorcall(SEXP, const char *,...)]

Is this by purpose or would it be possible to pull the Rf_errorcall
declaration to the error.h file? It's not that I need the Rf_errorcall
function, it's more that I am a bit pedantic and like to translate the
complete thing (based on LGPL (which is more convenient in the Delphi
world) - well you might not care about this).

How is this handled in general, I mean, there might be other spots
like this. Is it appropriate to ask such questions here?

--
Regards,
Hans-Peter

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Rf_errorcall - translate to Pascal

Duncan Murdoch
On 2/16/2006 3:55 AM, Hans-Peter wrote:

> Hello!
>
> I (try to) convert the external R header files to Pascal (Delphi). At
> one place I stumbled over a macro that uses a method that is not
> declared in a LGPL header file:
>
> In Rinternals.h:
>    #define error_return(msg) { Rf_error(msg); return R_NilValue; }
>    #define errorcall_return(cl,msg){ Rf_errorcall(cl, msg); return R_NilValue; }
>                                                   ~~~~~~~~
> In Error.h:
>     void Rf_error(const char *, ...);
>     [Rf_errorcall is not declared here, would be something like:
>      void Rf_errorcall(SEXP, const char *,...)]
>
> Is this by purpose or would it be possible to pull the Rf_errorcall
> declaration to the error.h file? It's not that I need the Rf_errorcall
> function, it's more that I am a bit pedantic and like to translate the
> complete thing (based on LGPL (which is more convenient in the Delphi
> world) - well you might not care about this).

Just to be clear:  this is a licensing issue, not a technical issue.
Error.h is licensed under the LGPL, but Defn.h (where Rf_errorcall is
declared) is under the more restrictive GPL.

> How is this handled in general, I mean, there might be other spots
> like this. Is it appropriate to ask such questions here?

I think this is a reasonable forum.

My feeling would be that this is probably an oversight; the public API
for R should be self-contained.  But I don't know if the fix is to
change errorcall_return or to move the Rf_errorcall declaration.
Generally things are not put in the public API if there's a feeling that
we'd like to change them; we are much more conservative about API changes.

I think it would be helpful to know the scope of the problem.  Could you
collect together a complete list of examples like this?

Duncan Murdoch

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Rf_errorcall - translate to Pascal

Hans-Peter Suter
In reply to this post by Hans-Peter Suter
2006/2/16, Hans-Peter <[hidden email]>:
>     [Rf_errorcall is not declared here, would be something like:
>      void Rf_errorcall(SEXP, const char *,...)]
>
> ... would it be possible to pull the Rf_errorcall
> declaration to the error.h file?

error.h doesn't look like a good place as the SEXP type is not known
there. Sorry, I am quite unfluent with this c headers...

As a sidenote: in Defn.h are two macrogroups:

  /* Promise Access Macros */
  /* Hashing Macros */

which aren't declared in Rinternals.h. This is different from e.g. the groups:

  /* General Cons Cell Attributes */
  /* Primitive Access Macros */
  ...

--
Regards,
Hans-Peter

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Rf_errorcall - translate to Pascal

Rainer M Krug
In reply to this post by Hans-Peter Suter
Hans-Peter wrote:
> Hello!
>
> I (try to) convert the external R header files to Pascal (Delphi). At
> one place I stumbled over a macro that uses a method that is not
.
.
.
Sounds interesting - Could you keep me updated about your progress? I
would be interested in the header files to use them in the analysis of
simulations from Delphi.

Rainer


--
--
Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT)

Department of Conservation Ecology
University of Stellenbosch
Matieland 7602
South Africa

email:    [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Rf_errorcall - translate to Pascal

Brian Ripley
In reply to this post by Hans-Peter Suter
On Thu, 16 Feb 2006, Hans-Peter wrote:

> 2006/2/16, Hans-Peter <[hidden email]>:
>>     [Rf_errorcall is not declared here, would be something like:
>>      void Rf_errorcall(SEXP, const char *,...)]
>>
>> ... would it be possible to pull the Rf_errorcall
>> declaration to the error.h file?
>
> error.h doesn't look like a good place as the SEXP type is not known
> there. Sorry, I am quite unfluent with this c headers...

Yes, and their names are case-sensitive too.  So it is intentional that
errorcall is not in R_Ext/Error.h.  Since it is needed for writing
front-ends and now mentioned in Writing R Extensions it should probably be
in Rinternals.h.  But note that is basically the only way that a non-core
programmer is going to be writing code that gets passed 'call' objects.

> As a sidenote: in Defn.h are two macrogroups:
>
>  /* Promise Access Macros */
>  /* Hashing Macros */
>
> which aren't declared in Rinternals.h. This is different from e.g. the groups:
>
>  /* General Cons Cell Attributes */
>  /* Primitive Access Macros */
>  ...

This is intentional.  Both Defn.h and Rinternals.h have these in a section
protected by

#ifdef USE_RINTERNALS
#endif

and that section should not be regarded as public.  There _are_
(mis-titled) sections

/* Promise Access Macros */
/* Hashing Macros */

in Rinternals.h, and those are the function equivalents defined for
external use.

All that is public is what is documented in `Writing R Extensions': other
things are in the header files but you should not assume that they will
even be exported in future versions of R.

--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Rf_errorcall - translate to Pascal

Hans-Peter Suter
Hello!

Thanks for your answers!

---
2006/2/16, Duncan Murdoch <[hidden email]>:
> I think it would be helpful to know the scope of the problem.  Could you
> collect together a complete list of examples like this?

yes, I will do that. Until now it's only the one function mentioned
and the 2 macro groups.
Btw: your Delphi notes were great to get me started !!!

---
2006/2/16, Rainer M Krug <[hidden email]>:
> Hans-Peter wrote:
> > I (try to) convert the external R header files to Pascal (Delphi). At
> Sounds interesting - Could you keep me updated about your progress? I
> would be interested in the header files to use them in the analysis of
> simulations from Delphi.

Sure, but I cannot promise anything. I did the same for Matlab but
it's much more difficult with R.

---
2006/2/16, Prof Brian Ripley <[hidden email]>:
> Yes, and their names are case-sensitive too.  So it is intentional that
> errorcall is not in R_Ext/Error.h.  Since it is needed for writing
> front-ends and now mentioned in Writing R Extensions it should probably be
> in Rinternals.h.

that would be great!

>But note that is basically the only way that a non-core
> programmer is going to be writing code that gets passed 'call' objects.

ok, thanks

> > As a sidenote: in Defn.h are two macrogroups:
> This is intentional.  Both Defn.h and Rinternals.h have these in a section
> protected by
> #ifdef USE_RINTERNALS
> #endif
> and that section should not be regarded as public.

I know that USE_RINTERNALS is ...internal and can change. But I had to
translate it nevertheless, because I need at least the type definition
"SEXP". And e.g. in chapter "4.8.2 Calling .External" there are code
samples with the macros CADR, TYPEOF, CHAR, STRING_ELT, ... which
AFAIK can run in Pascal only if they are redefined as pascal
functions. Regarding the possible changes I have to think about DUnit
tests to catch them.

>There _are_ (mis-titled) sections
> /* Promise Access Macros */
> /* Hashing Macros */
> in Rinternals.h, and those are the function equivalents defined for
> external use.

Sorry, I don't understand. Eg. in Rinternals.h the first entry in /*
Promise Access Macros */ is:   SEXP (PRCODE)(SEXP x);
                 ~~~~~~~
Do you now mean, that the macro PRCODE is defined for external use?
On the other hand, it's nowhere in the "writing R extensions
documentation". But it's e.g. used in the library methods (in the
function: methods-List_dispatch.c).

If its meant for external use, then AFAIK the only way to use this
macro in Pascal code is to translate it as a function, like e.g.:

  function rhPrcode( _x: pSexp ): pSexp;
    begin
      result:= _x.promsxp.expr;
    end;

<license related>
And now it's a bit unnice, that "_x.promsxp.expr" is defined in Defn.h
[as: ((x)->u.promsxp.expr)] and not in Rinternal.h. With almost all
other macros, e.g. FORMALS this is different, they are defined in
Rinternal.h [e.g.: ((x)->u.closxp.formals)]. In this macro case I
think its also for strict license interpretations irrelevant, because
SEXPREC and promsxp_struct are fully declared in Rinternal.h. But it's
not nice and maybe I just skip it.
</license related>


--
Regards,
Hans-Peter

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Rf_errorcall - translate to Pascal

Brian Ripley
On Thu, 16 Feb 2006, Hans-Peter wrote:

> Hello!
>
> Thanks for your answers!
>
> ---
> 2006/2/16, Duncan Murdoch <[hidden email]>:
>> I think it would be helpful to know the scope of the problem.  Could you
>> collect together a complete list of examples like this?
>
> yes, I will do that. Until now it's only the one function mentioned
> and the 2 macro groups.
> Btw: your Delphi notes were great to get me started !!!
>
> ---
> 2006/2/16, Rainer M Krug <[hidden email]>:
>> Hans-Peter wrote:
>>> I (try to) convert the external R header files to Pascal (Delphi). At
>> Sounds interesting - Could you keep me updated about your progress? I
>> would be interested in the header files to use them in the analysis of
>> simulations from Delphi.
>
> Sure, but I cannot promise anything. I did the same for Matlab but
> it's much more difficult with R.
>
> ---
> 2006/2/16, Prof Brian Ripley <[hidden email]>:
>> Yes, and their names are case-sensitive too.  So it is intentional that
>> errorcall is not in R_Ext/Error.h.  Since it is needed for writing
>> front-ends and now mentioned in Writing R Extensions it should probably be
>> in Rinternals.h.
>
> that would be great!
>
>> But note that is basically the only way that a non-core
>> programmer is going to be writing code that gets passed 'call' objects.
>
> ok, thanks
>
>>> As a sidenote: in Defn.h are two macrogroups:
>> This is intentional.  Both Defn.h and Rinternals.h have these in a section
>> protected by
>> #ifdef USE_RINTERNALS
>> #endif
>> and that section should not be regarded as public.
>
> I know that USE_RINTERNALS is ...internal and can change.

It is for use only inside R itself: see the comments in Defn.h.

> But I had to translate it nevertheless, because I need at least the type
> definition "SEXP".

Which is not inside #ifdef USE_RINTERNALS.

> And e.g. in chapter "4.8.2 Calling .External" there are code
> samples with the macros CADR, TYPEOF, CHAR, STRING_ELT, ... which

Those are not macros, but function calls.

> AFAIK can run in Pascal only if they are redefined as pascal
> functions. Regarding the possible changes I have to think about DUnit
> tests to catch them.
>
>> There _are_ (mis-titled) sections
>> /* Promise Access Macros */
>> /* Hashing Macros */
>> in Rinternals.h, and those are the function equivalents defined for
>> external use.
>
> Sorry, I don't understand. Eg. in Rinternals.h the first entry in /*
> Promise Access Macros */ is:   SEXP (PRCODE)(SEXP x);

That's not a macro (macros in C start #define).  It is a definition of a
function call.  And R.dll exports a function entry point PRCODE.

> Do you now mean, that the macro PRCODE is defined for external use?
> On the other hand, it's nowhere in the "writing R extensions
> documentation". But it's e.g. used in the library methods (in the
> function: methods-List_dispatch.c).

It is not part of the API, and the methods package imports the PRCODE
function.  It does not use the PRCODE macro.  However, do note that the
standard packages which ship with R are regarded as part of R and have
privileges other packages do not have.  (One is to use Defn.h.)

I realize you may be unfamiliar with C terminology, but you do definitely
seem to be misreadling Rinternals.h.

--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Rf_errorcall - translate to Pascal

Hans-Peter Suter
2006/2/16, Prof Brian Ripley <[hidden email]>:
> I realize you may be unfamiliar with C terminology, but you do definitely
> seem to be misreadling Rinternals.h.

Thanks for your helpful comments, I think I have understood now.

I won't use the internal structures (but it's nevertheless nice to be
able to and I've seen in the debugger the correct information is
there).

--
Regards,
Hans-Peter

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Rf_errorcall - translate to Pascal

Brian Ripley
I've made some changes in R-devel, so errorcall is now defined there and
it is clear what is a macro and what is a function and which are both.

I looked in the 'primitive access' functions/macros.  It is clear that all
these could be used for was to access the internal table of builtins, and
that is no longer exported (and was never intended to be used outside base
R), so I've moved those back to Defn.h.

On Thu, 16 Feb 2006, Hans-Peter wrote:

> 2006/2/16, Prof Brian Ripley <[hidden email]>:
>> I realize you may be unfamiliar with C terminology, but you do definitely
>> seem to be misreadling Rinternals.h.
>
> Thanks for your helpful comments, I think I have understood now.
>
> I won't use the internal structures (but it's nevertheless nice to be
> able to and I've seen in the debugger the correct information is
> there).
>
> --
> Regards,
> Hans-Peter
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel