/
Rinternals.h
1699 lines (1532 loc) · 55.9 KB
/
Rinternals.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* R : A Computer Language for Statistical Data Analysis
* Copyright (C) 1999--2018 The R Core Team.
* Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka
*
* This header file is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This file is part of R. R is distributed under the terms of the
* GNU General Public License, either Version 2, June 1991 or Version 3,
* June 2007. See doc/COPYRIGHTS for details of the copyright status of R.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, a copy is available at
* https://www.R-project.org/Licenses/
*/
/* This file is installed and available to packages, but only a small
part of the contents is within the API. See chapter 6 of 'Writing
R Extensions'.
*/
#ifndef R_INTERNALS_H_
#define R_INTERNALS_H_
#ifdef __cplusplus
# include <cstdio>
# include <climits>
# include <cstddef>
extern "C" {
#else
# include <stdio.h>
# include <limits.h> /* for INT_MAX */
# include <stddef.h> /* for ptrdiff_t, which is required by C99 */
#endif
#include <R_ext/Arith.h>
#include <R_ext/Boolean.h>
#include <R_ext/Complex.h>
#include <R_ext/Error.h> // includes NORET macro
#include <R_ext/Memory.h>
#include <R_ext/Utils.h>
#include <R_ext/Print.h>
#include <R_ext/Rdynload.h> // for DL_FUNC
#include <R_ext/libextern.h>
typedef unsigned char Rbyte;
/* type for length of (standard, not long) vectors etc */
typedef int R_len_t;
#define R_LEN_T_MAX INT_MAX
/* both config.h and Rconfig.h set SIZEOF_SIZE_T, but Rconfig.h is
skipped if config.h has already been included. */
#ifndef R_CONFIG_H
# include <Rconfig.h>
#endif
#if ( SIZEOF_SIZE_T > 4 )
# define LONG_VECTOR_SUPPORT
#endif
#ifdef LONG_VECTOR_SUPPORT
typedef ptrdiff_t R_xlen_t;
# define R_XLEN_T_MAX 4503599627370496
# define R_SHORT_LEN_MAX 2147483647
#else
typedef int R_xlen_t;
# define R_XLEN_T_MAX R_LEN_T_MAX
#endif
#ifndef TESTING_WRITE_BARRIER
# define INLINE_PROTECT
#endif
/* Fundamental Data Types: These are largely Lisp
* influenced structures, with the exception of LGLSXP,
* INTSXP, REALSXP, CPLXSXP and STRSXP which are the
* element types for S-like data objects.
*
* --> TypeTable[] in ../main/util.c for typeof()
*/
/* UUID identifying the internals version -- packages using compiled
code should be re-installed when this changes */
#define R_INTERNALS_UUID "2fdf6c18-697a-4ba7-b8ef-11c0d92f1327"
/* These exact numeric values are seldom used, but they are, e.g., in
* ../main/subassign.c, and they are serialized.
*/
#ifndef enum_SEXPTYPE
/* NOT YET using enum:
* 1) The SEXPREC struct below has 'SEXPTYPE type : 5'
* (making FUNSXP and CLOSXP equivalent in there),
* giving (-Wall only ?) warnings all over the place
* 2) Many switch(type) { case ... } statements need a final `default:'
* added in order to avoid warnings like [e.g. l.170 of ../main/util.c]
* "enumeration value `FUNSXP' not handled in switch"
*/
typedef unsigned int SEXPTYPE;
#define NILSXP 0 /* nil = NULL */
#define SYMSXP 1 /* symbols */
#define LISTSXP 2 /* lists of dotted pairs */
#define CLOSXP 3 /* closures */
#define ENVSXP 4 /* environments */
#define PROMSXP 5 /* promises: [un]evaluated closure arguments */
#define LANGSXP 6 /* language constructs (special lists) */
#define SPECIALSXP 7 /* special forms */
#define BUILTINSXP 8 /* builtin non-special forms */
#define CHARSXP 9 /* "scalar" string type (internal only)*/
#define LGLSXP 10 /* logical vectors */
/* 11 and 12 were factors and ordered factors in the 1990s */
#define INTSXP 13 /* integer vectors */
#define REALSXP 14 /* real variables */
#define CPLXSXP 15 /* complex variables */
#define STRSXP 16 /* string vectors */
#define DOTSXP 17 /* dot-dot-dot object */
#define ANYSXP 18 /* make "any" args work.
Used in specifying types for symbol
registration to mean anything is okay */
#define VECSXP 19 /* generic vectors */
#define EXPRSXP 20 /* expressions vectors */
#define BCODESXP 21 /* byte code */
#define EXTPTRSXP 22 /* external pointer */
#define WEAKREFSXP 23 /* weak reference */
#define RAWSXP 24 /* raw bytes */
#define S4SXP 25 /* S4, non-vector */
/* used for detecting PROTECT issues in memory.c */
#define NEWSXP 30 /* fresh node created in new page */
#define FREESXP 31 /* node released by GC */
#define FUNSXP 99 /* Closure or Builtin or Special */
#else /* NOT YET */
/*------ enum_SEXPTYPE ----- */
typedef enum {
NILSXP = 0, /* nil = NULL */
SYMSXP = 1, /* symbols */
LISTSXP = 2, /* lists of dotted pairs */
CLOSXP = 3, /* closures */
ENVSXP = 4, /* environments */
PROMSXP = 5, /* promises: [un]evaluated closure arguments */
LANGSXP = 6, /* language constructs (special lists) */
SPECIALSXP = 7, /* special forms */
BUILTINSXP = 8, /* builtin non-special forms */
CHARSXP = 9, /* "scalar" string type (internal only)*/
LGLSXP = 10, /* logical vectors */
INTSXP = 13, /* integer vectors */
REALSXP = 14, /* real variables */
CPLXSXP = 15, /* complex variables */
STRSXP = 16, /* string vectors */
DOTSXP = 17, /* dot-dot-dot object */
ANYSXP = 18, /* make "any" args work */
VECSXP = 19, /* generic vectors */
EXPRSXP = 20, /* expressions vectors */
BCODESXP = 21, /* byte code */
EXTPTRSXP = 22, /* external pointer */
WEAKREFSXP = 23, /* weak reference */
RAWSXP = 24, /* raw bytes */
S4SXP = 25, /* S4 non-vector */
NEWSXP = 30, /* fresh node creaed in new page */
FREESXP = 31, /* node released by GC */
FUNSXP = 99 /* Closure or Builtin */
} SEXPTYPE;
#endif
/* These are also used with the write barrier on, in attrib.c and util.c */
#define TYPE_BITS 5
#define MAX_NUM_SEXPTYPE (1<<TYPE_BITS)
typedef struct SEXPREC *SEXP;
/* Define SWITH_TO_REFCNT to use reference counting instead of the
'NAMED' mechanism. */
//#define SWITCH_TO_REFCNT
#if defined(SWITCH_TO_REFCNT) && ! defined(COMPUTE_REFCNT_VALUES)
# define COMPUTE_REFCNT_VALUES
#endif
#if defined(SWITCH_TO_REFCNT) && ! defined(ADJUST_ENVIR_REFCNTS)
# define ADJUST_ENVIR_REFCNTS
#endif
// ======================= USE_RINTERNALS section
#ifdef USE_RINTERNALS
/* This is intended for use only within R itself.
* It defines internal structures that are otherwise only accessible
* via SEXP, and macros to replace many (but not all) of accessor functions
* (which are always defined).
*/
#define NAMED_BITS 16
/* Flags */
struct sxpinfo_struct {
SEXPTYPE type : TYPE_BITS;
/* ==> (FUNSXP == 99) %% 2^5 == 3 == CLOSXP
* -> warning: `type' is narrower than values
* of its type
* when SEXPTYPE was an enum */
unsigned int scalar: 1;
unsigned int obj : 1;
unsigned int alt : 1;
unsigned int gp : 16;
unsigned int mark : 1;
unsigned int debug : 1;
unsigned int trace : 1; /* functions and memory tracing */
unsigned int spare : 1; /* used on closures and when REFCNT is defined */
unsigned int gcgen : 1; /* old generation number */
unsigned int gccls : 3; /* node class */
unsigned int named : NAMED_BITS;
unsigned int extra : 32 - NAMED_BITS;
}; /* Tot: 64 */
struct vecsxp_struct {
R_xlen_t length;
R_xlen_t truelength;
};
struct primsxp_struct {
int offset;
};
struct symsxp_struct {
struct SEXPREC *pname;
struct SEXPREC *value;
struct SEXPREC *internal;
};
struct listsxp_struct {
struct SEXPREC *carval;
struct SEXPREC *cdrval;
struct SEXPREC *tagval;
};
struct envsxp_struct {
struct SEXPREC *frame;
struct SEXPREC *enclos;
struct SEXPREC *hashtab;
};
struct closxp_struct {
struct SEXPREC *formals;
struct SEXPREC *body;
struct SEXPREC *env;
};
struct promsxp_struct {
struct SEXPREC *value;
struct SEXPREC *expr;
struct SEXPREC *env;
};
/* Every node must start with a set of sxpinfo flags and an attribute
field. Under the generational collector these are followed by the
fields used to maintain the collector's linked list structures. */
#ifdef SWITCH_TO_REFCNT
# define REFCNTMAX ((1 << NAMED_BITS) - 1)
#endif
#define SEXPREC_HEADER \
struct sxpinfo_struct sxpinfo; \
struct SEXPREC *attrib; \
struct SEXPREC *gengc_next_node, *gengc_prev_node
/* The standard node structure consists of a header followed by the
node data. */
typedef struct SEXPREC {
SEXPREC_HEADER;
union {
struct primsxp_struct primsxp;
struct symsxp_struct symsxp;
struct listsxp_struct listsxp;
struct envsxp_struct envsxp;
struct closxp_struct closxp;
struct promsxp_struct promsxp;
} u;
} SEXPREC;
/* The generational collector uses a reduced version of SEXPREC as a
header in vector nodes. The layout MUST be kept consistent with
the SEXPREC definition. The standard SEXPREC takes up 7 words
and the reduced version takes 6 words on most 64-bit systems. On most
32-bit systems, SEXPREC takes 8 words and the reduced version 7 words. */
typedef struct VECTOR_SEXPREC {
SEXPREC_HEADER;
struct vecsxp_struct vecsxp;
} VECTOR_SEXPREC, *VECSEXP;
typedef union { VECTOR_SEXPREC s; double align; } SEXPREC_ALIGN;
/* General Cons Cell Attributes */
#define ATTRIB(x) ((x)->attrib)
#define OBJECT(x) ((x)->sxpinfo.obj)
#define MARK(x) ((x)->sxpinfo.mark)
#define TYPEOF(x) ((x)->sxpinfo.type)
#define NAMED(x) ((x)->sxpinfo.named)
#define RTRACE(x) ((x)->sxpinfo.trace)
#define LEVELS(x) ((x)->sxpinfo.gp)
#define SET_OBJECT(x,v) (((x)->sxpinfo.obj)=(v))
#define SET_TYPEOF(x,v) (((x)->sxpinfo.type)=(v))
#define SET_NAMED(x,v) (((x)->sxpinfo.named)=(v))
#define SET_RTRACE(x,v) (((x)->sxpinfo.trace)=(v))
#define SETLEVELS(x,v) (((x)->sxpinfo.gp)=((unsigned short)v))
#define ALTREP(x) ((x)->sxpinfo.alt)
#define SETALTREP(x, v) (((x)->sxpinfo.alt) = (v))
#define SETSCALAR(x, v) (((x)->sxpinfo.scalar) = (v))
#if defined(COMPUTE_REFCNT_VALUES)
# define REFCNT(x) ((x)->sxpinfo.named)
# define TRACKREFS(x) (TYPEOF(x) == CLOSXP ? TRUE : ! (x)->sxpinfo.spare)
#else
# define REFCNT(x) 0
# define TRACKREFS(x) FALSE
#endif
#if defined(COMPUTE_REFCNT_VALUES)
# define SET_REFCNT(x,v) (REFCNT(x) = (v))
# if defined(EXTRA_REFCNT_FIELDS)
# define SET_TRACKREFS(x,v) (TRACKREFS(x) = (v))
# else
# define SET_TRACKREFS(x,v) ((x)->sxpinfo.spare = ! (v))
# endif
# define DECREMENT_REFCNT(x) do { \
SEXP drc__x__ = (x); \
if (REFCNT(drc__x__) > 0 && REFCNT(drc__x__) < REFCNTMAX) \
SET_REFCNT(drc__x__, REFCNT(drc__x__) - 1); \
} while (0)
# define INCREMENT_REFCNT(x) do { \
SEXP irc__x__ = (x); \
if (REFCNT(irc__x__) < REFCNTMAX) \
SET_REFCNT(irc__x__, REFCNT(irc__x__) + 1); \
} while (0)
#else
# define SET_REFCNT(x,v) do {} while(0)
# define SET_TRACKREFS(x,v) do {} while(0)
# define DECREMENT_REFCNT(x) do {} while(0)
# define INCREMENT_REFCNT(x) do {} while(0)
#endif
#define ENABLE_REFCNT(x) SET_TRACKREFS(x, TRUE)
#define DISABLE_REFCNT(x) SET_TRACKREFS(x, FALSE)
#ifdef SWITCH_TO_REFCNT
# undef NAMED
# undef SET_NAMED
# define NAMED(x) REFCNT(x)
# define SET_NAMED(x, v) do {} while (0)
#endif
#define ENSURE_NAMEDMAX(v) do { \
SEXP __enm_v__ = (v); \
if (NAMED(__enm_v__) < NAMEDMAX) \
SET_NAMED( __enm_v__, NAMEDMAX); \
} while (0)
#define ENSURE_NAMED(v) do { if (NAMED(v) == 0) SET_NAMED(v, 1); } while (0)
#define SETTER_CLEAR_NAMED(x) do { \
SEXP __x__ = (x); \
if (NAMED(__x__) == 1) SET_NAMED(__x__, 0); \
} while (0)
#define RAISE_NAMED(x, n) do { \
SEXP __x__ = (x); \
int __n__ = (n); \
if (NAMED(__x__) < __n__) \
SET_NAMED(__x__, __n__); \
} while (0)
/* S4 object bit, set by R_do_new_object for all new() calls */
#define S4_OBJECT_MASK ((unsigned short)(1<<4))
#define IS_S4_OBJECT(x) ((x)->sxpinfo.gp & S4_OBJECT_MASK)
#define SET_S4_OBJECT(x) (((x)->sxpinfo.gp) |= S4_OBJECT_MASK)
#define UNSET_S4_OBJECT(x) (((x)->sxpinfo.gp) &= ~S4_OBJECT_MASK)
/* JIT optimization support */
#define NOJIT_MASK ((unsigned short)(1<<5))
#define NOJIT(x) ((x)->sxpinfo.gp & NOJIT_MASK)
#define SET_NOJIT(x) (((x)->sxpinfo.gp) |= NOJIT_MASK)
#define MAYBEJIT_MASK ((unsigned short)(1<<6))
#define MAYBEJIT(x) ((x)->sxpinfo.gp & MAYBEJIT_MASK)
#define SET_MAYBEJIT(x) (((x)->sxpinfo.gp) |= MAYBEJIT_MASK)
#define UNSET_MAYBEJIT(x) (((x)->sxpinfo.gp) &= ~MAYBEJIT_MASK)
/* Growable vector support */
#define GROWABLE_MASK ((unsigned short)(1<<5))
#define GROWABLE_BIT_SET(x) ((x)->sxpinfo.gp & GROWABLE_MASK)
#define SET_GROWABLE_BIT(x) (((x)->sxpinfo.gp) |= GROWABLE_MASK)
#define IS_GROWABLE(x) (GROWABLE_BIT_SET(x) && XLENGTH(x) < XTRUELENGTH(x))
/* Vector Access Macros */
#ifdef LONG_VECTOR_SUPPORT
# define IS_LONG_VEC(x) (XLENGTH(x) > R_SHORT_LEN_MAX)
#else
# define IS_LONG_VEC(x) 0
#endif
#define STDVEC_LENGTH(x) (((VECSEXP) (x))->vecsxp.length)
#define STDVEC_TRUELENGTH(x) (((VECSEXP) (x))->vecsxp.truelength)
#define SET_STDVEC_TRUELENGTH(x, v) (STDVEC_TRUELENGTH(x)=(v))
#define SET_TRUELENGTH(x,v) do { \
SEXP sl__x__ = (x); \
R_xlen_t sl__v__ = (v); \
if (ALTREP(x)) error("can't set ALTREP truelength"); \
SET_STDVEC_TRUELENGTH(sl__x__, sl__v__); \
} while (0)
#define IS_SCALAR(x, t) (((x)->sxpinfo.type == (t)) && (x)->sxpinfo.scalar)
#define LENGTH(x) LENGTH_EX(x, __FILE__, __LINE__)
#define TRUELENGTH(x) XTRUELENGTH(x)
/* defined as a macro since fastmatch packages tests for it */
#define XLENGTH(x) XLENGTH_EX(x)
/* THIS ABSOLUTELY MUST NOT BE USED IN PACKAGES !!! */
#define SET_STDVEC_LENGTH(x,v) do { \
SEXP __x__ = (x); \
R_xlen_t __v__ = (v); \
STDVEC_LENGTH(__x__) = __v__; \
SETSCALAR(__x__, __v__ == 1 ? 1 : 0); \
} while (0)
/* Under the generational allocator the data for vector nodes comes
immediately after the node structure, so the data address is a
known offset from the node SEXP. */
#define STDVEC_DATAPTR(x) ((void *) (((SEXPREC_ALIGN *) (x)) + 1))
#define CHAR(x) ((const char *) STDVEC_DATAPTR(x))
#define LOGICAL(x) ((int *) DATAPTR(x))
#define INTEGER(x) ((int *) DATAPTR(x))
#define RAW(x) ((Rbyte *) DATAPTR(x))
#define COMPLEX(x) ((Rcomplex *) DATAPTR(x))
#define REAL(x) ((double *) DATAPTR(x))
#define VECTOR_ELT(x,i) ((SEXP *) DATAPTR(x))[i]
#define STRING_PTR(x) ((SEXP *) DATAPTR(x))
#define VECTOR_PTR(x) ((SEXP *) DATAPTR(x))
#define LOGICAL_RO(x) ((const int *) DATAPTR_RO(x))
#define INTEGER_RO(x) ((const int *) DATAPTR_RO(x))
#define RAW_RO(x) ((const Rbyte *) DATAPTR_RO(x))
#define COMPLEX_RO(x) ((const Rcomplex *) DATAPTR_RO(x))
#define REAL_RO(x) ((const double *) DATAPTR_RO(x))
#define STRING_PTR_RO(x)((const SEXP *) DATAPTR_RO(x))
/* List Access Macros */
/* These also work for ... objects */
#define LISTVAL(x) ((x)->u.listsxp)
#define TAG(e) ((e)->u.listsxp.tagval)
#define CAR(e) ((e)->u.listsxp.carval)
#define CDR(e) ((e)->u.listsxp.cdrval)
#define CAAR(e) CAR(CAR(e))
#define CDAR(e) CDR(CAR(e))
#define CADR(e) CAR(CDR(e))
#define CDDR(e) CDR(CDR(e))
#define CDDDR(e) CDR(CDR(CDR(e)))
#define CADDR(e) CAR(CDR(CDR(e)))
#define CADDDR(e) CAR(CDR(CDR(CDR(e))))
#define CAD4R(e) CAR(CDR(CDR(CDR(CDR(e)))))
#define MISSING_MASK 15 /* reserve 4 bits--only 2 uses now */
#define MISSING(x) ((x)->sxpinfo.gp & MISSING_MASK)/* for closure calls */
#define SET_MISSING(x,v) do { \
SEXP __x__ = (x); \
int __v__ = (v); \
int __other_flags__ = __x__->sxpinfo.gp & ~MISSING_MASK; \
__x__->sxpinfo.gp = __other_flags__ | __v__; \
} while (0)
/* Closure Access Macros */
#define FORMALS(x) ((x)->u.closxp.formals)
#define BODY(x) ((x)->u.closxp.body)
#define CLOENV(x) ((x)->u.closxp.env)
#define RDEBUG(x) ((x)->sxpinfo.debug)
#define SET_RDEBUG(x,v) (((x)->sxpinfo.debug)=(v))
#define RSTEP(x) ((x)->sxpinfo.spare)
#define SET_RSTEP(x,v) (((x)->sxpinfo.spare)=(v))
/* Symbol Access Macros */
#define PRINTNAME(x) ((x)->u.symsxp.pname)
#define SYMVALUE(x) ((x)->u.symsxp.value)
#define INTERNAL(x) ((x)->u.symsxp.internal)
#define DDVAL_MASK 1
#define DDVAL(x) ((x)->sxpinfo.gp & DDVAL_MASK) /* for ..1, ..2 etc */
#define SET_DDVAL_BIT(x) (((x)->sxpinfo.gp) |= DDVAL_MASK)
#define UNSET_DDVAL_BIT(x) (((x)->sxpinfo.gp) &= ~DDVAL_MASK)
#define SET_DDVAL(x,v) ((v) ? SET_DDVAL_BIT(x) : UNSET_DDVAL_BIT(x)) /* for ..1, ..2 etc */
/* Environment Access Macros */
#define FRAME(x) ((x)->u.envsxp.frame)
#define ENCLOS(x) ((x)->u.envsxp.enclos)
#define HASHTAB(x) ((x)->u.envsxp.hashtab)
#define ENVFLAGS(x) ((x)->sxpinfo.gp) /* for environments */
#define SET_ENVFLAGS(x,v) (((x)->sxpinfo.gp)=(v))
#else /* not USE_RINTERNALS */
// ======================= not USE_RINTERNALS section
#define CHAR(x) R_CHAR(x)
const char *(R_CHAR)(SEXP x);
/* Various tests with macro versions in the second USE_RINTERNALS section */
Rboolean (Rf_isNull)(SEXP s);
Rboolean (Rf_isSymbol)(SEXP s);
Rboolean (Rf_isLogical)(SEXP s);
Rboolean (Rf_isReal)(SEXP s);
Rboolean (Rf_isComplex)(SEXP s);
Rboolean (Rf_isExpression)(SEXP s);
Rboolean (Rf_isEnvironment)(SEXP s);
Rboolean (Rf_isString)(SEXP s);
Rboolean (Rf_isObject)(SEXP s);
#endif /* USE_RINTERNALS */
#define IS_SIMPLE_SCALAR(x, type) \
(IS_SCALAR(x, type) && ATTRIB(x) == R_NilValue)
#define SIMPLE_SCALAR_TYPE(x) \
(((x)->sxpinfo.scalar && ATTRIB(x) == R_NilValue) ? TYPEOF(x) : 0)
#define NAMEDMAX 7
#define INCREMENT_NAMED(x) do { \
SEXP __x__ = (x); \
if (NAMED(__x__) != NAMEDMAX) \
SET_NAMED(__x__, NAMED(__x__) + 1); \
} while (0)
#define DECREMENT_NAMED(x) do { \
SEXP __x__ = (x); \
int __n__ = NAMED(__x__); \
if (__n__ > 0 && __n__ < NAMEDMAX) \
SET_NAMED(__x__, __n__ - 1); \
} while (0)
#define INCREMENT_LINKS(x) do { \
SEXP il__x__ = (x); \
INCREMENT_NAMED(il__x__); \
INCREMENT_REFCNT(il__x__); \
} while (0)
#define DECREMENT_LINKS(x) do { \
SEXP dl__x__ = (x); \
DECREMENT_NAMED(dl__x__); \
DECREMENT_REFCNT(dl__x__); \
} while (0)
/* Macros for some common idioms. */
#ifdef SWITCH_TO_REFCNT
# define MAYBE_SHARED(x) (REFCNT(x) > 1)
# define NO_REFERENCES(x) (REFCNT(x) == 0)
# ifdef USE_RINTERNALS
# define MARK_NOT_MUTABLE(x) SET_REFCNT(x, REFCNTMAX)
# endif
#else
# define MAYBE_SHARED(x) (NAMED(x) > 1)
# define NO_REFERENCES(x) (NAMED(x) == 0)
# ifdef USE_RINTERNALS
# define MARK_NOT_MUTABLE(x) SET_NAMED(x, NAMEDMAX)
# endif
#endif
#define MAYBE_REFERENCED(x) (! NO_REFERENCES(x))
#define NOT_SHARED(x) (! MAYBE_SHARED(x))
/* ALTREP sorting support */
enum {SORTED_DECR_NA_1ST = -2,
SORTED_DECR = -1,
UNKNOWN_SORTEDNESS = INT_MIN, /*INT_MIN is NA_INTEGER! */
SORTED_INCR = 1,
SORTED_INCR_NA_1ST = 2,
KNOWN_UNSORTED = 0};
#define KNOWN_SORTED(sorted) (sorted == SORTED_DECR || \
sorted == SORTED_INCR || \
sorted == SORTED_DECR_NA_1ST || \
sorted == SORTED_INCR_NA_1ST)
#define KNOWN_NA_1ST(sorted) (sorted == SORTED_INCR_NA_1ST || \
sorted == SORTED_DECR_NA_1ST)
#define KNOWN_INCR(sorted) (sorted == SORTED_INCR || \
sorted == SORTED_INCR_NA_1ST)
#define KNOWN_DECR(sorted) (sorted == SORTED_DECR || \
sorted == SORTED_DECR_NA_1ST)
/* Complex assignment support */
/* temporary definition that will need to be refined to distinguish
getter from setter calls */
#define IS_GETTER_CALL(call) (CADR(call) == R_TmpvalSymbol)
/* Accessor functions. Many are declared using () to avoid the macro
definitions in the USE_RINTERNALS section.
The function STRING_ELT is used as an argument to arrayAssign even
if the macro version is in use.
*/
/* General Cons Cell Attributes */
SEXP (ATTRIB)(SEXP x);
int (OBJECT)(SEXP x);
int (MARK)(SEXP x);
int (TYPEOF)(SEXP x);
int (NAMED)(SEXP x);
int (REFCNT)(SEXP x);
int (TRACKREFS)(SEXP x);
void (SET_OBJECT)(SEXP x, int v);
void (SET_TYPEOF)(SEXP x, int v);
void (SET_NAMED)(SEXP x, int v);
void SET_ATTRIB(SEXP x, SEXP v);
void DUPLICATE_ATTRIB(SEXP to, SEXP from);
void SHALLOW_DUPLICATE_ATTRIB(SEXP to, SEXP from);
void (ENSURE_NAMEDMAX)(SEXP x);
void (ENSURE_NAMED)(SEXP x);
void (SETTER_CLEAR_NAMED)(SEXP x);
void (RAISE_NAMED)(SEXP x, int n);
void (DECREMENT_REFCNT)(SEXP x);
void (INCREMENT_REFCNT)(SEXP x);
void (DISABLE_REFCNT)(SEXP x);
void (ENABLE_REFCNT)(SEXP x);
void (MARK_NOT_MUTABLE)(SEXP x);
/* S4 object testing */
int (IS_S4_OBJECT)(SEXP x);
void (SET_S4_OBJECT)(SEXP x);
void (UNSET_S4_OBJECT)(SEXP x);
/* JIT optimization support */
int (NOJIT)(SEXP x);
int (MAYBEJIT)(SEXP x);
void (SET_NOJIT)(SEXP x);
void (SET_MAYBEJIT)(SEXP x);
void (UNSET_MAYBEJIT)(SEXP x);
/* Growable vector support */
int (IS_GROWABLE)(SEXP x);
void (SET_GROWABLE_BIT)(SEXP x);
/* Vector Access Functions */
int (LENGTH)(SEXP x);
R_xlen_t (XLENGTH)(SEXP x);
R_xlen_t (TRUELENGTH)(SEXP x);
void (SETLENGTH)(SEXP x, R_xlen_t v);
void (SET_TRUELENGTH)(SEXP x, R_xlen_t v);
int (IS_LONG_VEC)(SEXP x);
int (LEVELS)(SEXP x);
int (SETLEVELS)(SEXP x, int v);
#ifdef TESTING_WRITE_BARRIER
R_xlen_t (STDVEC_LENGTH)(SEXP);
R_xlen_t (STDVEC_TRUELENGTH)(SEXP);
void (SETALTREP)(SEXP, int);
#endif
int *(LOGICAL)(SEXP x);
int *(INTEGER)(SEXP x);
Rbyte *(RAW)(SEXP x);
double *(REAL)(SEXP x);
Rcomplex *(COMPLEX)(SEXP x);
const int *(LOGICAL_RO)(SEXP x);
const int *(INTEGER_RO)(SEXP x);
const Rbyte *(RAW_RO)(SEXP x);
const double *(REAL_RO)(SEXP x);
const Rcomplex *(COMPLEX_RO)(SEXP x);
//SEXP (STRING_ELT)(SEXP x, R_xlen_t i);
SEXP (VECTOR_ELT)(SEXP x, R_xlen_t i);
void SET_STRING_ELT(SEXP x, R_xlen_t i, SEXP v);
SEXP SET_VECTOR_ELT(SEXP x, R_xlen_t i, SEXP v);
SEXP *(STRING_PTR)(SEXP x);
const SEXP *(STRING_PTR_RO)(SEXP x);
SEXP * NORET (VECTOR_PTR)(SEXP x);
/* ALTREP support */
void *(STDVEC_DATAPTR)(SEXP x);
int (IS_SCALAR)(SEXP x, int type);
int (ALTREP)(SEXP x);
SEXP ALTREP_DUPLICATE_EX(SEXP x, Rboolean deep);
SEXP ALTREP_COERCE(SEXP x, int type);
Rboolean ALTREP_INSPECT(SEXP, int, int, int, void (*)(SEXP, int, int, int));
SEXP ALTREP_SERIALIZED_CLASS(SEXP);
SEXP ALTREP_SERIALIZED_STATE(SEXP);
SEXP ALTREP_UNSERIALIZE_EX(SEXP, SEXP, SEXP, int, int);
R_xlen_t ALTREP_LENGTH(SEXP x);
R_xlen_t ALTREP_TRUELENGTH(SEXP x);
void *ALTVEC_DATAPTR(SEXP x);
const void *ALTVEC_DATAPTR_RO(SEXP x);
const void *ALTVEC_DATAPTR_OR_NULL(SEXP x);
SEXP ALTVEC_EXTRACT_SUBSET(SEXP x, SEXP indx, SEXP call);
/* data access */
int ALTINTEGER_ELT(SEXP x, R_xlen_t i);
void ALTINTEGER_SET_ELT(SEXP x, R_xlen_t i, int v);
int ALTLOGICAL_ELT(SEXP x, R_xlen_t i);
void ALTLOGICAL_SET_ELT(SEXP x, R_xlen_t i, int v);
double ALTREAL_ELT(SEXP x, R_xlen_t i);
void ALTREAL_SET_ELT(SEXP x, R_xlen_t i, double v);
SEXP ALTSTRING_ELT(SEXP, R_xlen_t);
void ALTSTRING_SET_ELT(SEXP, R_xlen_t, SEXP);
Rcomplex ALTCOMPLEX_ELT(SEXP x, R_xlen_t i);
void ALTCOMPLEX_SET_ELT(SEXP x, R_xlen_t i, Rcomplex v);
Rbyte ALTRAW_ELT(SEXP x, R_xlen_t i);
void ALTRAW_SET_ELT(SEXP x, R_xlen_t i, Rbyte v);
R_xlen_t INTEGER_GET_REGION(SEXP sx, R_xlen_t i, R_xlen_t n, int *buf);
R_xlen_t REAL_GET_REGION(SEXP sx, R_xlen_t i, R_xlen_t n, double *buf);
R_xlen_t LOGICAL_GET_REGION(SEXP sx, R_xlen_t i, R_xlen_t n, int *buf);
R_xlen_t COMPLEX_GET_REGION(SEXP sx, R_xlen_t i, R_xlen_t n, Rcomplex *buf);
R_xlen_t RAW_GET_REGION(SEXP sx, R_xlen_t i, R_xlen_t n, Rbyte *buf);
/* metadata access */
int INTEGER_IS_SORTED(SEXP x);
int INTEGER_NO_NA(SEXP x);
int REAL_IS_SORTED(SEXP x);
int REAL_NO_NA(SEXP x);
int LOGICAL_IS_SORTED(SEXP x);
int LOGICAL_NO_NA(SEXP x);
int STRING_IS_SORTED(SEXP x);
int STRING_NO_NA(SEXP x);
/* invoking ALTREP class methods */
SEXP ALTINTEGER_SUM(SEXP x, Rboolean narm);
SEXP ALTINTEGER_MIN(SEXP x, Rboolean narm);
SEXP ALTINTEGER_MAX(SEXP x, Rboolean narm);
SEXP INTEGER_MATCH(SEXP, SEXP, int, SEXP, SEXP, Rboolean);
SEXP INTEGER_IS_NA(SEXP x);
SEXP ALTREAL_SUM(SEXP x, Rboolean narm);
SEXP ALTREAL_MIN(SEXP x, Rboolean narm);
SEXP ALTREAL_MAX(SEXP x, Rboolean narm);
SEXP REAL_MATCH(SEXP, SEXP, int, SEXP, SEXP, Rboolean);
SEXP REAL_IS_NA(SEXP x);
SEXP ALTLOGICAL_SUM(SEXP x, Rboolean narm);
/* constructors for internal ALTREP classes */
SEXP R_compact_intrange(R_xlen_t n1, R_xlen_t n2);
SEXP R_deferred_coerceToString(SEXP v, SEXP info);
SEXP R_virtrep_vec(SEXP, SEXP);
SEXP R_tryWrap(SEXP);
SEXP R_tryUnwrap(SEXP);
#ifdef LONG_VECTOR_SUPPORT
R_len_t NORET R_BadLongVector(SEXP, const char *, int);
#endif
/* checking for mis-use of multi-threading */
#ifdef TESTING_WRITE_BARRIER
# define THREADCHECK
#endif
#ifdef THREADCHECK
void R_check_thread(const char *s);
# define R_CHECK_THREAD R_check_thread(__func__)
#else
# define R_CHECK_THREAD do {} while (0)
#endif
/* List Access Functions */
/* These also work for ... objects */
#define CONS(a, b) cons((a), (b)) /* data lists */
#define LCONS(a, b) lcons((a), (b)) /* language lists */
SEXP (TAG)(SEXP e);
SEXP (CAR)(SEXP e);
SEXP (CDR)(SEXP e);
SEXP (CAAR)(SEXP e);
SEXP (CDAR)(SEXP e);
SEXP (CADR)(SEXP e);
SEXP (CDDR)(SEXP e);
SEXP (CDDDR)(SEXP e);
SEXP (CADDR)(SEXP e);
SEXP (CADDDR)(SEXP e);
SEXP (CAD4R)(SEXP e);
int (MISSING)(SEXP x);
void (SET_MISSING)(SEXP x, int v);
void SET_TAG(SEXP x, SEXP y);
SEXP SETCAR(SEXP x, SEXP y);
SEXP SETCDR(SEXP x, SEXP y);
SEXP SETCADR(SEXP x, SEXP y);
SEXP SETCADDR(SEXP x, SEXP y);
SEXP SETCADDDR(SEXP x, SEXP y);
SEXP SETCAD4R(SEXP e, SEXP y);
SEXP CONS_NR(SEXP a, SEXP b);
/* Closure Access Functions */
SEXP (FORMALS)(SEXP x);
SEXP (BODY)(SEXP x);
SEXP (CLOENV)(SEXP x);
int (RDEBUG)(SEXP x);
int (RSTEP)(SEXP x);
int (RTRACE)(SEXP x);
void (SET_RDEBUG)(SEXP x, int v);
void (SET_RSTEP)(SEXP x, int v);
void (SET_RTRACE)(SEXP x, int v);
void SET_FORMALS(SEXP x, SEXP v);
void SET_BODY(SEXP x, SEXP v);
void SET_CLOENV(SEXP x, SEXP v);
/* Symbol Access Functions */
SEXP (PRINTNAME)(SEXP x);
SEXP (SYMVALUE)(SEXP x);
SEXP (INTERNAL)(SEXP x);
int (DDVAL)(SEXP x);
void (SET_DDVAL)(SEXP x, int v);
void SET_PRINTNAME(SEXP x, SEXP v);
void SET_SYMVALUE(SEXP x, SEXP v);
void SET_INTERNAL(SEXP x, SEXP v);
/* Environment Access Functions */
SEXP (FRAME)(SEXP x);
SEXP (ENCLOS)(SEXP x);
SEXP (HASHTAB)(SEXP x);
int (ENVFLAGS)(SEXP x);
void (SET_ENVFLAGS)(SEXP x, int v);
void SET_FRAME(SEXP x, SEXP v);
void SET_ENCLOS(SEXP x, SEXP v);
void SET_HASHTAB(SEXP x, SEXP v);
/* Promise Access Functions */
/* First five have macro versions in Defn.h */
SEXP (PRCODE)(SEXP x);
SEXP (PRENV)(SEXP x);
SEXP (PRVALUE)(SEXP x);
int (PRSEEN)(SEXP x);
void (SET_PRSEEN)(SEXP x, int v);
void SET_PRENV(SEXP x, SEXP v);
void SET_PRVALUE(SEXP x, SEXP v);
void SET_PRCODE(SEXP x, SEXP v);
void SET_PRSEEN(SEXP x, int v);
/* Hashing Functions */
/* There are macro versions in Defn.h */
int (HASHASH)(SEXP x);
int (HASHVALUE)(SEXP x);
void (SET_HASHASH)(SEXP x, int v);
void (SET_HASHVALUE)(SEXP x, int v);
/* External pointer access macros */
#define EXTPTR_PTR(x) CAR(x)
#define EXTPTR_PROT(x) CDR(x)
#define EXTPTR_TAG(x) TAG(x)
/* Bytecode access macros */
#define BCODE_CODE(x) CAR(x)
#define BCODE_CONSTS(x) CDR(x)
#define BCODE_EXPR(x) TAG(x)
#define isByteCode(x) (TYPEOF(x)==BCODESXP)
/* Pointer Protection and Unprotection */
#define PROTECT(s) Rf_protect(s)
#define UNPROTECT(n) Rf_unprotect(n)
#define UNPROTECT_PTR(s) Rf_unprotect_ptr(s)
/* We sometimes need to coerce a protected value and place the new
coerced value under protection. For these cases PROTECT_WITH_INDEX
saves an index of the protection location that can be used to
replace the protected value using REPROTECT. */
typedef int PROTECT_INDEX;
#define PROTECT_WITH_INDEX(x,i) R_ProtectWithIndex(x,i)
#define REPROTECT(x,i) R_Reprotect(x,i)
/* Evaluation Environment */
LibExtern SEXP R_GlobalEnv; /* The "global" environment */
LibExtern SEXP R_EmptyEnv; /* An empty environment at the root of the
environment tree */
LibExtern SEXP R_BaseEnv; /* The base environment; formerly R_NilValue */
LibExtern SEXP R_BaseNamespace; /* The (fake) namespace for base */
LibExtern SEXP R_NamespaceRegistry;/* Registry for registered namespaces */
LibExtern SEXP R_Srcref; /* Current srcref, for debuggers */
/* Special Values */
LibExtern SEXP R_NilValue; /* The nil object */
LibExtern SEXP R_UnboundValue; /* Unbound marker */
LibExtern SEXP R_MissingArg; /* Missing argument marker */
LibExtern SEXP R_InBCInterpreter; /* To be found in BC interp. state
(marker) */
LibExtern SEXP R_CurrentExpression; /* Use current expression (marker) */
#ifdef __MAIN__
attribute_hidden
#else
extern
#endif
SEXP R_RestartToken; /* Marker for restarted function calls */
/* Symbol Table Shortcuts */
LibExtern SEXP R_AsCharacterSymbol;/* "as.character" */
LibExtern SEXP R_baseSymbol; // <-- backcompatible version of:
LibExtern SEXP R_BaseSymbol; // "base"
LibExtern SEXP R_BraceSymbol; /* "{" */
LibExtern SEXP R_Bracket2Symbol; /* "[[" */
LibExtern SEXP R_BracketSymbol; /* "[" */
LibExtern SEXP R_ClassSymbol; /* "class" */
LibExtern SEXP R_DeviceSymbol; /* ".Device" */
LibExtern SEXP R_DimNamesSymbol; /* "dimnames" */
LibExtern SEXP R_DimSymbol; /* "dim" */
LibExtern SEXP R_DollarSymbol; /* "$" */
LibExtern SEXP R_DotsSymbol; /* "..." */
LibExtern SEXP R_DoubleColonSymbol;// "::"
LibExtern SEXP R_DropSymbol; /* "drop" */
LibExtern SEXP R_LastvalueSymbol; /* ".Last.value" */
LibExtern SEXP R_LevelsSymbol; /* "levels" */
LibExtern SEXP R_ModeSymbol; /* "mode" */
LibExtern SEXP R_NaRmSymbol; /* "na.rm" */
LibExtern SEXP R_NameSymbol; /* "name" */
LibExtern SEXP R_NamesSymbol; /* "names" */
LibExtern SEXP R_NamespaceEnvSymbol;// ".__NAMESPACE__."
LibExtern SEXP R_PackageSymbol; /* "package" */
LibExtern SEXP R_PreviousSymbol; /* "previous" */
LibExtern SEXP R_QuoteSymbol; /* "quote" */
LibExtern SEXP R_RowNamesSymbol; /* "row.names" */
LibExtern SEXP R_SeedsSymbol; /* ".Random.seed" */
LibExtern SEXP R_SortListSymbol; /* "sort.list" */
LibExtern SEXP R_SourceSymbol; /* "source" */
LibExtern SEXP R_SpecSymbol; // "spec"
LibExtern SEXP R_TripleColonSymbol;// ":::"
LibExtern SEXP R_TspSymbol; /* "tsp" */
LibExtern SEXP R_dot_defined; /* ".defined" */
LibExtern SEXP R_dot_Method; /* ".Method" */
LibExtern SEXP R_dot_packageName;// ".packageName"
LibExtern SEXP R_dot_target; /* ".target" */
LibExtern SEXP R_dot_Generic; /* ".Generic" */
/* Missing Values - others from Arith.h */
#define NA_STRING R_NaString
LibExtern SEXP R_NaString; /* NA_STRING as a CHARSXP */
LibExtern SEXP R_BlankString; /* "" as a CHARSXP */
LibExtern SEXP R_BlankScalarString;/* "" as a STRSXP */
/* srcref related functions */
SEXP R_GetCurrentSrcref(int);
SEXP R_GetSrcFilename(SEXP);
/*--- FUNCTIONS ------------------------------------------------------ */
/* Type Coercions of all kinds */
SEXP Rf_asChar(SEXP);
SEXP Rf_coerceVector(SEXP, SEXPTYPE);
SEXP Rf_PairToVectorList(SEXP x);
SEXP Rf_VectorToPairList(SEXP x);
SEXP Rf_asCharacterFactor(SEXP x);
int Rf_asLogical(SEXP x);
int Rf_asLogical2(SEXP x, int checking, SEXP call, SEXP rho);
int Rf_asInteger(SEXP x);
double Rf_asReal(SEXP x);
Rcomplex Rf_asComplex(SEXP x);
#ifndef R_ALLOCATOR_TYPE
#define R_ALLOCATOR_TYPE
typedef struct R_allocator R_allocator_t;
#endif
/* Other Internally Used Functions, excluding those which are inline-able*/
char * Rf_acopy_string(const char *);
void Rf_addMissingVarsToNewEnv(SEXP, SEXP);
SEXP Rf_alloc3DArray(SEXPTYPE, int, int, int);
SEXP Rf_allocArray(SEXPTYPE, SEXP);
SEXP Rf_allocFormalsList2(SEXP sym1, SEXP sym2);
SEXP Rf_allocFormalsList3(SEXP sym1, SEXP sym2, SEXP sym3);
SEXP Rf_allocFormalsList4(SEXP sym1, SEXP sym2, SEXP sym3, SEXP sym4);
SEXP Rf_allocFormalsList5(SEXP sym1, SEXP sym2, SEXP sym3, SEXP sym4, SEXP sym5);
SEXP Rf_allocFormalsList6(SEXP sym1, SEXP sym2, SEXP sym3, SEXP sym4, SEXP sym5, SEXP sym6);
SEXP Rf_allocMatrix(SEXPTYPE, int, int);
SEXP Rf_allocList(int);
SEXP Rf_allocS4Object(void);
SEXP Rf_allocSExp(SEXPTYPE);
SEXP Rf_allocVector3(SEXPTYPE, R_xlen_t, R_allocator_t*);
R_xlen_t Rf_any_duplicated(SEXP x, Rboolean from_last);
R_xlen_t Rf_any_duplicated3(SEXP x, SEXP incomp, Rboolean from_last);
SEXP Rf_applyClosure(SEXP, SEXP, SEXP, SEXP, SEXP);
SEXP Rf_arraySubscript(int, SEXP, SEXP, SEXP (*)(SEXP,SEXP),
SEXP (*)(SEXP, int), SEXP);
SEXP Rf_classgets(SEXP, SEXP);
SEXP Rf_cons(SEXP, SEXP);
SEXP Rf_fixSubset3Args(SEXP, SEXP, SEXP, SEXP*);
void Rf_copyMatrix(SEXP, SEXP, Rboolean);
void Rf_copyListMatrix(SEXP, SEXP, Rboolean);
void Rf_copyMostAttrib(SEXP, SEXP);
void Rf_copyVector(SEXP, SEXP);
int Rf_countContexts(int, int);
SEXP Rf_CreateTag(SEXP);
void Rf_defineVar(SEXP, SEXP, SEXP);
SEXP Rf_dimgets(SEXP, SEXP);
SEXP Rf_dimnamesgets(SEXP, SEXP);
SEXP Rf_DropDims(SEXP);
SEXP Rf_duplicate(SEXP);
SEXP Rf_shallow_duplicate(SEXP);
SEXP R_duplicate_attr(SEXP);
SEXP R_shallow_duplicate_attr(SEXP);
SEXP Rf_lazy_duplicate(SEXP);
/* the next really should not be here and is also in Defn.h */
SEXP Rf_duplicated(SEXP, Rboolean);
Rboolean R_envHasNoSpecialSymbols(SEXP);