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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
* GObject introspection: struct definitions for the binary
* typelib format, validation
*
* Copyright (C) 2005 Matthias Clasen
* Copyright (C) 2008,2009 Red Hat, Inc.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*
* This library 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 of the License, or (at your option) any later version.
*
* This library 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 library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#pragma once
#include <gmodule.h>
#include "girepository.h"
G_BEGIN_DECLS
/**
* SECTION:gitypelib-internal
* @title: GITypelib Internals
* @short_description: Layout and accessors for typelib
* @stability: Stable
*
* The ‘typelib’ is a binary, readonly, memory-mappable database
* containing reflective information about a GObject library.
*
* What the typelib describes and the types used are the same for every
* platform so, apart the endianness of its scalar values, the typelib
* database must be considered architecture-independent.
*
* The format of GObject typelib is strongly influenced by the Mozilla XPCOM
* format.
*
* Some of the differences to XPCOM include:
*
* - Type information is stored not quite as compactly (XPCOM stores it inline
* in function descriptions in variable-sized blobs of 1 to n bytes. We store
* 16 bits of type information for each parameter, which is enough to encode
* simple types inline. Complex (e.g. recursive) types are stored out of line
* in a separate list of types.
* - String and complex type data is stored outside of typelib entry blobs,
* references are stored as offsets relative to the start of the typelib.
* One possibility is to store the strings and types in a pools at the end
* of the typelib.
*
* The typelib has the following general format:
*
* ```
* typelib ::= header, section-index, directory, blobs, attributes, attributedata
*
* directory ::= list of entries
*
* entry ::= blob type, name, namespace, offset
* blob ::= function|callback|struct|boxed|enum|flags|object|interface|constant|union
* attribute ::= offset, key, value
* attributedata ::= string data for attributes
* ```
*
* ## Details
*
* We describe the fragments that make up the typelib in the form of C structs
* (although some fall short of being valid C structs since they contain
* multiple flexible arrays).
*
* Since: 2.80
*/
/*
TYPELIB HISTORY
-----
Version 1.1
- Add ref/unref/set-value/get-value functions to Object, to be able
to support instantiatable fundamental types which are not GObject based.
Version 1.0
- Rename class_struct to gtype_struct, add to interfaces
Changes since 0.9:
- Add padding to structures
Changes since 0.8:
- Add class struct concept to ObjectBlob
- Add is_class_struct bit to StructBlob
Changes since 0.7:
- Add dependencies
Changes since 0.6:
- rename metadata to typelib, to follow xpcom terminology
Changes since 0.5:
- basic type cleanup:
+ remove GString
+ add [u]int, [u]long, [s]size_t
+ rename string to utf8, add filename
- allow blob_type to be zero for non-local entries
Changes since 0.4:
- add a UnionBlob
Changes since 0.3:
- drop short_name for ValueBlob
Changes since 0.2:
- make inline types 4 bytes after all, remove header->types and allow
types to appear anywhere
- allow error domains in the directory
Changes since 0.1:
- drop comments about _GOBJ_METADATA
- drop string pool, strings can appear anywhere
- use 'blob' as collective name for the various blob types
- rename 'type' field in blobs to 'blob_type'
- rename 'type_name' and 'type_init' fields to 'gtype_name', 'gtype_init'
- shrink directory entries to 12 bytes
- merge struct and boxed blobs
- split interface blobs into enum, object and interface blobs
- add an 'unregistered' flag to struct and enum blobs
- add a 'wraps_vfunc' flag to function blobs and link them to
the vfuncs they wrap
- restrict value blobs to only occur inside enums and flags again
- add constant blobs, allow them toplevel, in interfaces and in objects
- rename 'receiver_owns_value' and 'receiver_owns_container' to
'transfer_ownership' and 'transfer_container_ownership'
- add a 'struct_offset' field to virtual function and field blobs
- add 'dipper' and 'optional' flags to arg blobs
- add a 'true_stops_emit' flag to signal blobs
- add variable blob sizes to header
- store offsets to signature blobs instead of including them directly
- change the type offset to be measured in words rather than bytes
*/
/**
* GI_IR_MAGIC:
*
* Identifying prefix for the typelib.
*
* This was inspired by XPCOM, which in turn borrowed from PNG.
*
* Since: 2.80
*/
#define GI_IR_MAGIC "GOBJ\nMETADATA\r\n\032"
/**
* GITypelibBlobType:
* @BLOB_TYPE_INVALID: Should not appear in code
* @BLOB_TYPE_FUNCTION: A #FunctionBlob
* @BLOB_TYPE_CALLBACK: A #CallbackBlob
* @BLOB_TYPE_STRUCT: A #StructBlob
* @BLOB_TYPE_BOXED: Can be either a #StructBlob or #UnionBlob
* @BLOB_TYPE_ENUM: An #EnumBlob
* @BLOB_TYPE_FLAGS: An #EnumBlob
* @BLOB_TYPE_OBJECT: An #ObjectBlob
* @BLOB_TYPE_INTERFACE: An #InterfaceBlob
* @BLOB_TYPE_CONSTANT: A #ConstantBlob
* @BLOB_TYPE_INVALID_0: Deleted, used to be ErrorDomain.
* @BLOB_TYPE_UNION: A #UnionBlob
*
* The integral value of this enumeration appears in each "Blob" component of
* a typelib to identify its type.
*
* Since: 2.80
*/
typedef enum {
BLOB_TYPE_INVALID,
BLOB_TYPE_FUNCTION,
BLOB_TYPE_CALLBACK,
BLOB_TYPE_STRUCT,
BLOB_TYPE_BOXED,
BLOB_TYPE_ENUM,
BLOB_TYPE_FLAGS,
BLOB_TYPE_OBJECT,
BLOB_TYPE_INTERFACE,
BLOB_TYPE_CONSTANT,
BLOB_TYPE_INVALID_0,
BLOB_TYPE_UNION
} GITypelibBlobType;
#if defined (G_CAN_INLINE) && defined (G_ALWAYS_INLINE)
G_ALWAYS_INLINE
inline gboolean
_blob_is_registered_type (GITypelibBlobType blob_type)
{
switch (blob_type)
{
case BLOB_TYPE_STRUCT:
case BLOB_TYPE_UNION:
case BLOB_TYPE_ENUM:
case BLOB_TYPE_FLAGS:
case BLOB_TYPE_OBJECT:
case BLOB_TYPE_INTERFACE:
return TRUE;
default:
return FALSE;
}
}
#define BLOB_IS_REGISTERED_TYPE(blob) \
_blob_is_registered_type ((GITypelibBlobType) (blob)->blob_type)
#else
#define BLOB_IS_REGISTERED_TYPE(blob) \
((blob)->blob_type == BLOB_TYPE_STRUCT || \
(blob)->blob_type == BLOB_TYPE_UNION || \
(blob)->blob_type == BLOB_TYPE_ENUM || \
(blob)->blob_type == BLOB_TYPE_FLAGS || \
(blob)->blob_type == BLOB_TYPE_OBJECT || \
(blob)->blob_type == BLOB_TYPE_INTERFACE)
#endif /* defined (G_CAN_INLINE) && defined (G_ALWAYS_INLINE) */
/**
* Header:
* @magic: See #GI_IR_MAGIC.
* @major_version: The major version number of the typelib format. Major version
* number changes indicate incompatible changes to the tyeplib format.
* @minor_version: The minor version number of the typelib format. Minor version
* number changes indicate compatible changes and should still allow the
* typelib to be parsed by a parser designed for the same @major_version.
* @reserved: Reserved for future use.
* @n_entries: The number of entries in the directory.
* @n_local_entries: The number of entries referring to blobs in this typelib.
* The local entries must occur before the unresolved entries.
* @directory: Offset of the directory in the typelib.
* @n_attributes: Number of attribute blocks
* @attributes: Offset of the list of attributes in the typelib.
* @dependencies: Offset of a single string, which is the list of immediate
* dependencies, separated by the '|' character. The dependencies are
* required in order to avoid having programs consuming a typelib check for
* an "Unresolved" type return from every API call.
* @size: The size in bytes of the typelib.
* @namespace: Offset of the namespace string in the typelib.
* @nsversion: Offset of the namespace version string in the typelib.
* @shared_library: This field is the set of shared libraries associated with
* the typelib. The entries are separated by the '|' (pipe) character.
* @c_prefix: The prefix for the function names of the library
* @entry_blob_size: The sizes of fixed-size blobs. Recording this information
* here allows to write parser which continue to work if the format is
* extended by adding new fields to the end of the fixed-size blobs.
* @function_blob_size: See @entry_blob_size.
* @callback_blob_size: See @entry_blob_size.
* @signal_blob_size: See @entry_blob_size.
* @vfunc_blob_size: See @entry_blob_size.
* @arg_blob_size: See @entry_blob_size.
* @property_blob_size: See @entry_blob_size.
* @field_blob_size: See @entry_blob_size.
* @value_blob_size: See @entry_blob_size.
* @attribute_blob_size: See @entry_blob_size.
* @constant_blob_size: See @entry_blob_size.
* @error_domain_blob_size: See @entry_blob_size.
* @signature_blob_size: See @entry_blob_size.
* @enum_blob_size: See @entry_blob_size.
* @struct_blob_size: See @entry_blob_size.
* @object_blob_size: See @entry_blob_size.
* @interface_blob_size: For variable-size blobs, the size of the struct up to
* the first flexible array member. Recording this information here allows
* to write parser which continue to work if the format is extended by
* adding new fields before the first flexible array member in
* variable-size blobs.
* @union_blob_size: See @entry_blob_size.
* @sections: Offset of section blob array
* @padding: TODO
*
* The header structure appears exactly once at the beginning of a typelib. It is a
* collection of meta-information, such as the number of entries and dependencies.
*
* Since: 2.80
*/
typedef struct {
char magic[16];
uint8_t major_version;
uint8_t minor_version;
uint16_t reserved;
uint16_t n_entries;
uint16_t n_local_entries;
uint32_t directory;
uint32_t n_attributes;
uint32_t attributes;
uint32_t dependencies;
uint32_t size;
uint32_t namespace;
uint32_t nsversion;
uint32_t shared_library;
uint32_t c_prefix;
uint16_t entry_blob_size;
uint16_t function_blob_size;
uint16_t callback_blob_size;
uint16_t signal_blob_size;
uint16_t vfunc_blob_size;
uint16_t arg_blob_size;
uint16_t property_blob_size;
uint16_t field_blob_size;
uint16_t value_blob_size;
uint16_t attribute_blob_size;
uint16_t constant_blob_size;
uint16_t error_domain_blob_size;
uint16_t signature_blob_size;
uint16_t enum_blob_size;
uint16_t struct_blob_size;
uint16_t object_blob_size;
uint16_t interface_blob_size;
uint16_t union_blob_size;
uint32_t sections;
uint16_t padding[6];
} Header;
/**
* SectionType:
* @GI_SECTION_END: TODO
* @GI_SECTION_DIRECTORY_INDEX: TODO
*
* TODO
*
* Since: 2.80
*/
typedef enum {
GI_SECTION_END = 0,
GI_SECTION_DIRECTORY_INDEX = 1
} SectionType;
/**
* Section:
* @id: A #SectionType
* @offset: Integer offset for this section
*
* A section is a blob of data that's (at least theoretically) optional,
* and may or may not be present in the typelib. Presently, just used
* for the directory index. This allows a form of dynamic extensibility
* with different tradeoffs from the format minor version.
*
* Since: 2.80
*/
typedef struct {
uint32_t id;
uint32_t offset;
} Section;
/**
* DirEntry:
* @blob_type: A #GITypelibBlobType
* @local: Whether this entry refers to a blob in this typelib.
* @reserved: Reserved for future use.
* @name: The name of the entry.
* @offset: If is_local is set, this is the offset of the blob in the typelib.
* Otherwise, it is the offset of the namespace in which the blob has to be
* looked up by name.
*
* References to directory entries are stored as 1-based 16-bit indexes.
*
* All blobs pointed to by a directory entry start with the same layout for
* the first 8 bytes (the reserved flags may be used by some blob types)
*
* Since: 2.80
*/
typedef struct {
uint16_t blob_type;
uint16_t local : 1;
uint16_t reserved :15;
uint32_t name;
uint32_t offset;
} DirEntry;
/**
* SimpleTypeBlobFlags:
* @reserved: Reserved for future use.
* @reserved2: Reserved for future use.
* @pointer: TODO
* @reserved3: Reserved for future use.
* @tag: A #GITypeTag
*
* TODO
*
* Since: 2.80
*/
typedef struct {
unsigned reserved : 8;
unsigned reserved2 :16;
unsigned pointer : 1;
unsigned reserved3 : 2;
unsigned tag : 5;
} SimpleTypeBlobFlags;
union _SimpleTypeBlob
{
SimpleTypeBlobFlags flags;
uint32_t offset;
};
/**
* SimpleTypeBlob:
* @flags: TODO
* @offset: Offset relative to header->types that points to a TypeBlob.
* Unlike other offsets, this is in words (ie 32bit units) rather
* than bytes.
*
* The SimpleTypeBlob is the general purpose "reference to a type" construct,
* used in method parameters, returns, callback definitions, fields, constants,
* etc. It's actually just a 32 bit integer which you can see from the union
* definition. This is for efficiency reasons, since there are so many
* references to types.
*
* SimpleTypeBlob is divided into two cases; first, if "reserved" and
* "reserved2" are both zero, the type tag for a basic type is embedded in the
* "tag" bits. This allows e.g. GI_TYPE_TAG_UTF8, GI_TYPE_TAG_INT and the like
* to be embedded directly without taking up extra space.
*
* References to "interfaces" (objects, interfaces) are more complicated;
* In this case, the integer is actually an offset into the directory (see
* above). Because the header is larger than 2^8=256 bits, all offsets will
* have one of the upper 24 bits set.
*
* Since: 2.80
*/
typedef union _SimpleTypeBlob SimpleTypeBlob;
/**
* ArgBlob:
* @name: A suggested name for the parameter.
* @in: The parameter is an input to the function
* @out: The parameter is used to return an output of the function. Parameters
* can be both in and out. Out parameters implicitly add another level of
* indirection to the parameter type. Ie if the type is uint32 in an out
* parameter, the function actually takes an uint32*.
* @caller_allocates: The parameter is a pointer to a struct or object that
* will receive an output of the function.
* @nullable: Only meaningful for types which are passed as pointers. For an
* in parameter, indicates if it is ok to pass NULL in. Gor an out
* parameter, indicates whether it may return NULL. Note that NULL is a
* valid GList and GSList value, thus allow_none will normally be set
* for parameters of these types.
* @optional: For an out parameter, indicates that NULL may be passed in
* if the value is not needed.
* @transfer_ownership: For an in parameter, indicates that the function takes
* over ownership of the parameter value. For an out parameter, it indicates
* that the caller is responsible for freeing the return value.
* @transfer_container_ownership: For container types, indicates that the
* ownership of the container, but not of its contents is transferred.
* This is typically the case for out parameters returning lists of
* statically allocated things.
* @return_value: The parameter should be considered the return value of the
* function. Only out parameters can be marked as return value, and there
* can be at most one per function call. If an out parameter is marked as
* return value, the actual return value of the function should be either
* void or a boolean indicating the success of the call.
* @scope: A #GIScopeType. If the parameter is of a callback type, this denotes
* the scope of the user_data and the callback function pointer itself
* (for languages that emit code at run-time).
* @skip: Indicates that the parameter is only useful in C and should be skipped.
* @reserved: Reserved for future use.
* @closure: Index of the closure (user_data) parameter associated with the
* callback, or -1.
* @destroy: Index of the destroy notfication callback parameter associated
* with the callback, or -1.
* @padding: TODO
* @arg_type: Describes the type of the parameter. See details below.
*
* Types are specified by four bytes. If the three high bytes are zero,
* the low byte describes a basic type, otherwise the 32bit number is an
* offset which points to a TypeBlob.
*
* Since: 2.80
*/
typedef struct {
uint32_t name;
unsigned in : 1;
unsigned out : 1;
unsigned caller_allocates : 1;
unsigned nullable : 1;
unsigned optional : 1;
unsigned transfer_ownership : 1;
unsigned transfer_container_ownership : 1;
unsigned return_value : 1;
unsigned scope : 3;
unsigned skip : 1;
unsigned reserved :20;
int8_t closure;
int8_t destroy;
uint16_t padding;
SimpleTypeBlob arg_type;
} ArgBlob;
/**
* SignatureBlob:
* @return_type: Describes the type of the return value. See details below.
* @may_return_null: Only relevant for pointer types. Indicates whether the
* caller must expect NULL as a return value.
* @caller_owns_return_value: If set, the caller is responsible for freeing
* the return value if it is no longer needed.
* @caller_owns_return_container: This flag is only relevant if the return type
* is a container type. If the flag is set, the caller is resonsible for
* freeing the container, but not its contents.
* @skip_return: Indicates that the return value is only useful in C and should
* be skipped.
* @instance_transfer_ownership: When calling, the function assumes ownership of
* the instance parameter.
* @throws: Denotes the signature takes an additional #GError argument beyond
* the annotated arguments.
* @reserved: Reserved for future use.
* @n_arguments: The number of arguments that this function expects, also the
* length of the array of ArgBlobs.
* @arguments: An array of ArgBlob for the arguments of the function.
*
* TODO
*
* Since: 2.80
*/
typedef struct {
SimpleTypeBlob return_type;
uint16_t may_return_null : 1;
uint16_t caller_owns_return_value : 1;
uint16_t caller_owns_return_container : 1;
uint16_t skip_return : 1;
uint16_t instance_transfer_ownership : 1;
uint16_t throws : 1;
uint16_t reserved :10;
uint16_t n_arguments;
ArgBlob arguments[];
} SignatureBlob;
/**
* CommonBlob:
* @blob_type: A #GITypelibBlobType
* @deprecated: Whether the blob is deprecated.
* @reserved: Reserved for future use.
* @name: The name of the blob.
*
* The #CommonBlob is shared between #FunctionBlob,
* #CallbackBlob, #SignalBlob.
*
* TODO
*
* Since: 2.80
*/
typedef struct {
uint16_t blob_type; /* 1 */
uint16_t deprecated : 1;
uint16_t reserved :15;
uint32_t name;
} CommonBlob;
/**
* FunctionBlob:
* @blob_type: #BLOB_TYPE_FUNCTION
* @deprecated: The function is deprecated.
* @setter: The function is a setter for a property. Language bindings may
* prefer to not bind individual setters and rely on the generic
* g_object_set().
* @getter: The function is a getter for a property. Language bindings may
* prefer to not bind individual getters and rely on the generic
* g_object_get().
* @constructor: The function acts as a constructor for the object it is
* contained in.
* @wraps_vfunc: The function is a simple wrapper for a virtual function.
* @throws: This is now additionally stored in the #SignatureBlob. (deprecated)
* @index: Index of the property that this function is a setter or getter of
* in the array of properties of the containing interface, or index
* of the virtual function that this function wraps.
* @name: TODO
* @symbol: The symbol which can be used to obtain the function pointer with
* dlsym().
* @signature: Offset of the SignatureBlob describing the parameter types and the
* return value type.
* @is_static: The function is a "static method"; in other words it's a pure
* function whose name is conceptually scoped to the object.
* @reserved: Reserved for future use.
* @reserved2: Reserved for future use.
*
* TODO
*
* Since: 2.80
*/
typedef struct {
uint16_t blob_type; /* 1 */
uint16_t deprecated : 1;
uint16_t setter : 1;
uint16_t getter : 1;
uint16_t constructor : 1;
uint16_t wraps_vfunc : 1;
uint16_t throws : 1;
uint16_t index :10;
/* Note the bits above need to match CommonBlob
* and are thus exhausted, extend things using
* the reserved block below. */
uint32_t name;
uint32_t symbol;
uint32_t signature;
uint16_t is_static : 1;
uint16_t reserved : 15;
uint16_t reserved2 : 16;
} FunctionBlob;
/**
* CallbackBlob:
* @blob_type: TODO
* @deprecated: TODO
* @reserved: Reserved for future use.
* @name: TODO
* @signature: Offset of the #SignatureBlob describing the parameter types and
* the return value type.
*
* TODO
*
* Since: 2.80
*/
typedef struct {
uint16_t blob_type; /* 2 */
uint16_t deprecated : 1;
uint16_t reserved :15;
uint32_t name;
uint32_t signature;
} CallbackBlob;
/**
* InterfaceTypeBlob:
* @pointer: Whether this type represents an indirection
* @reserved: Reserved for future use.
* @tag: A #GITypeTag
* @reserved2: Reserved for future use.
* @interface: Index of the directory entry for the interface.
*
* If the interface is an enum of flags type, is_pointer is 0, otherwise it is 1.
*
* Since: 2.80
*/
typedef struct {
uint8_t pointer :1;
uint8_t reserved :2;
uint8_t tag :5;
uint8_t reserved2;
uint16_t interface;
} InterfaceTypeBlob;
/**
* ArrayTypeDimension:
* @length: TODO
* @size: TODO
*
* TODO
*
* Since: 2.80
*/
typedef union {
uint16_t length;
uint16_t size;
} ArrayTypeDimension;
/**
* ArrayTypeBlob:
* @pointer: TODO
* @reserved: Reserved for future use.
* @tag: TODO
* @zero_terminated: Indicates that the array must be terminated by a suitable
* #NULL value.
* @has_length: Indicates that length points to a parameter specifying the
* length of the array. If both has_length and zero_terminated are set, the
* convention is to pass -1 for the length if the array is zero-terminated.
* @has_size: Indicates that size is the fixed size of the array.
* @array_type: Indicates whether this is a C array, GArray, GPtrArray, or
* GByteArray. If something other than a C array, the length and element
* size are implicit in the structure.
* @reserved2: Reserved for future use.
* @dimensions: TODO
* @type: TODO
*
* TODO
*
* Since: 2.80
*/
typedef struct {
uint16_t pointer :1;
uint16_t reserved :2;
uint16_t tag :5;
uint16_t zero_terminated :1;
uint16_t has_length :1;
uint16_t has_size :1;
uint16_t array_type :2;
uint16_t reserved2 :3;
ArrayTypeDimension dimensions;
SimpleTypeBlob type;
} ArrayTypeBlob;
/**
* ParamTypeBlob:
* @pointer: TODO
* @reserved: Reserved for future use.
* @tag: TODO
* @reserved2: Reserved for future use.
* @n_types: The number of parameter types to follow.
* @type: Describes the type of the list elements.
*
* TODO
*
* Since: 2.80
*/
typedef struct {
uint8_t pointer :1;
uint8_t reserved :2;
uint8_t tag :5;
uint8_t reserved2;
uint16_t n_types;
SimpleTypeBlob type[];
} ParamTypeBlob;
/**
* ErrorTypeBlob:
* @pointer: TODO
* @reserved: TODO
* @tag: TODO
* @reserved2: TODO
* @n_domains: TODO: must be 0
* @domains: TODO
*
* TODO
*
* Since: 2.80
*/
typedef struct {
uint8_t pointer :1;
uint8_t reserved :2;
uint8_t tag :5;
uint8_t reserved2;
uint16_t n_domains; /* Must be 0 */
uint16_t domains[];
} ErrorTypeBlob;
/**
* ValueBlob:
* @deprecated: Whether this value is deprecated
* @unsigned_value: if set, value is a 32-bit unsigned integer cast to int32_t
* @reserved: Reserved for future use.
* @name: Name of blob
* @value: The numerical value
*
* Values commonly occur in enums and flags.
*
* Since: 2.80
*/
typedef struct {
uint32_t deprecated : 1;
uint32_t unsigned_value : 1;
uint32_t reserved :30;
uint32_t name;
int32_t value;
} ValueBlob;
/**
* FieldBlob:
* @name: The name of the field.
* @readable: TODO
* @writable: How the field may be accessed.
* @has_embedded_type: An anonymous type follows the FieldBlob.
* @reserved: Reserved for future use.
* @bits: If this field is part of a bitfield, the number of bits which it
* uses, otherwise 0.
* @struct_offset: The offset of the field in the struct. The value 0xFFFF
* indicates that the struct offset is unknown.
* @reserved2: Reserved for future use.
* @type: The type of the field.
*
* TODO
*
* Since: 2.80
*/
typedef struct {
uint32_t name;
uint8_t readable :1;
uint8_t writable :1;
uint8_t has_embedded_type :1;
uint8_t reserved :5;
uint8_t bits;
uint16_t struct_offset;
uint32_t reserved2;
SimpleTypeBlob type;
} FieldBlob;
/**
* RegisteredTypeBlob:
* @blob_type: TODO
* @deprecated: TODO
* @unregistered: TODO
* @reserved: Reserved for future use.
* @name: TODO
* @gtype_name: The name under which the type is registered with GType.
* @gtype_init: The symbol name of the get_type<!-- -->() function which registers the
* type.
*
* TODO
*
* Since: 2.80
*/
typedef struct {
uint16_t blob_type;
uint16_t deprecated : 1;
uint16_t unregistered : 1;
uint16_t reserved :14;
uint32_t name;
uint32_t gtype_name;
uint32_t gtype_init;
} RegisteredTypeBlob;
/**
* StructBlob:
* @blob_type: #BLOB_TYPE_STRUCT
* @deprecated: Whether this structure is deprecated
* @unregistered: If this is set, the type is not registered with GType.
* @is_gtype_struct: Whether this structure is the class or interface layout
* for a GObject
* @alignment: The byte boundary that the struct is aligned to in memory
* @foreign: If the type is foreign, eg if it's expected to be overridden by
* a native language binding instead of relying of introspected bindings.
* @reserved: Reserved for future use.
* @name: TODO
* @gtype_name: String name of the associated #GType
* @gtype_init: String naming the symbol which gets the runtime #GType
* @size: The size of the struct in bytes.
* @n_fields: TODO
* @n_methods: TODO
* @copy_func: String pointing to a function which can be called to copy
* the contents of this struct type
* @free_func: String pointing to a function which can be called to free
* the contents of this struct type
*
* TODO
*
* Since: 2.80
*/
typedef struct {
uint16_t blob_type;
uint16_t deprecated : 1;
uint16_t unregistered : 1;
uint16_t is_gtype_struct : 1;
uint16_t alignment : 6;
uint16_t foreign : 1;
uint16_t reserved : 6;
uint32_t name;
uint32_t gtype_name;
uint32_t gtype_init;
uint32_t size;
uint16_t n_fields;
uint16_t n_methods;
uint32_t copy_func;
uint32_t free_func;
} StructBlob;
/**
* UnionBlob:
* @blob_type: TODO
* @deprecated: TODO
* @unregistered: If this is set, the type is not registered with GType.
* @discriminated: Is set if the union is discriminated
* @alignment: The byte boundary that the union is aligned to in memory
* @reserved: Reserved for future use.
* @name: TODO
* @gtype_name: String name of the associated #GType
* @gtype_init: String naming the symbol which gets the runtime #GType
* @size: TODO
* @n_fields: Length of the arrays
* @n_functions: TODO
* @copy_func: String pointing to a function which can be called to copy
* the contents of this union type
* @free_func: String pointing to a function which can be called to free
* the contents of this union type
* @discriminator_offset: Offset from the beginning of the union where the
* discriminator of a discriminated union is located. The value 0xFFFF
* indicates that the discriminator offset is unknown.
* @discriminator_type: Type of the discriminator
*
* TODO
*
* Since: 2.80
*/
typedef struct {
uint16_t blob_type;
uint16_t deprecated : 1;
uint16_t unregistered : 1;
uint16_t discriminated : 1;
uint16_t alignment : 6;
uint16_t reserved : 7;
uint32_t name;
uint32_t gtype_name;
uint32_t gtype_init;
uint32_t size;
uint16_t n_fields;
uint16_t n_functions;
uint32_t copy_func;
uint32_t free_func;
int32_t discriminator_offset;
SimpleTypeBlob discriminator_type;
} UnionBlob;
/**
* EnumBlob:
* @blob_type: TODO
* @deprecated: TODO
* @unregistered: If this is set, the type is not registered with GType.
* @storage_type: The tag of the type used for the enum in the C ABI
* (will be a signed or unsigned integral type)
* @reserved: Reserved for future use.
* @name: TODO
* @gtype_name: String name of the associated #GType
* @gtype_init: String naming the symbol which gets the runtime #GType
* @n_values: The length of the values array.
* @n_methods: The length of the methods array.
* @error_domain: String naming the #GError domain this enum is associated with
* @values: TODO
*
* TODO
*
* Since: 2.80
*/
typedef struct {
uint16_t blob_type;
uint16_t deprecated : 1;
uint16_t unregistered : 1;
uint16_t storage_type : 5;
uint16_t reserved : 9;
uint32_t name;
uint32_t gtype_name;
uint32_t gtype_init;
uint16_t n_values;
uint16_t n_methods;
uint32_t error_domain;
ValueBlob values[];
} EnumBlob;
#define ACCESSOR_SENTINEL 0x3ff
/**
* PropertyBlob:
* @name: The name of the property.
* @deprecated: TODO
* @readable: TODO
* @writable: TODO
* @construct: TODO
* @construct_only: The ParamFlags used when registering the property.
* @transfer_ownership: When writing, the type containing the property takes
* ownership of the value. When reading, the returned value needs to be
* released by the caller.
* @transfer_container_ownership: For container types indicates that the
* ownership of the container, but not of its contents, is transferred.
* This is typically the case when reading lists of statically allocated
* things.
* @setter: the index of the setter function for this property, if @writable
* is set; if the method is not known, the value will be set to %ACCESSOR_SENTINEL
* @getter: ths index of the getter function for this property, if @readable
* is set; if the method is not known, the value will be set to %ACCESSOR_SENTINEL
* @reserved: Reserved for future use.
* @reserved2: Reserved for future use.
* @type: Describes the type of the property.
*
* TODO
*
* Since: 2.80
*/
typedef struct {
uint32_t name;
uint32_t deprecated : 1;
uint32_t readable : 1;
uint32_t writable : 1;
uint32_t construct : 1;
uint32_t construct_only : 1;
uint32_t transfer_ownership : 1;
uint32_t transfer_container_ownership : 1;
uint32_t setter :10;
uint32_t getter :10;
uint32_t reserved : 5;
uint32_t reserved2;
SimpleTypeBlob type;
} PropertyBlob;
/**
* SignalBlob:
* @deprecated: TODO
* @run_first: TODO
* @run_last: TODO
* @run_cleanup: TODO
* @no_recurse: TODO
* @detailed: TODO
* @action: TODO
* @no_hooks: The flags used when registering the signal.
* @has_class_closure: Set if the signal has a class closure.
* @true_stops_emit: Whether the signal has true-stops-emit semantics
* @reserved: Reserved for future use.
* @class_closure: The index of the class closure in the list of virtual
* functions of the object or interface on which the signal is defined.
* @name: The name of the signal.
* @reserved2: Reserved for future use.
* @signature: Offset of the SignatureBlob describing the parameter types
* and the return value type.
*
* TODO
*
* Since: 2.80
*/
typedef struct {
uint16_t deprecated : 1;
uint16_t run_first : 1;
uint16_t run_last : 1;
uint16_t run_cleanup : 1;
uint16_t no_recurse : 1;
uint16_t detailed : 1;
uint16_t action : 1;
uint16_t no_hooks : 1;
uint16_t has_class_closure : 1;
uint16_t true_stops_emit : 1;
uint16_t reserved : 6;
uint16_t class_closure;
uint32_t name;
uint32_t reserved2;
uint32_t signature;
} SignalBlob;
/**
* VFuncBlob:
* @name: The name of the virtual function.
* @must_chain_up: If set, every implementation of this virtual function must
* chain up to the implementation of the parent class.
* @must_be_implemented: If set, every derived class must override this virtual
* function.
* @must_not_be_implemented: If set, derived class must not override this
* virtual function.
* @class_closure: Set if this virtual function is the class closure of a
* signal.
* @throws: This is now additionally stored in the #SignatureBlob. (deprecated)
* @reserved: Reserved for future use.
* @signal: The index of the signal in the list of signals of the object or
* interface to which this virtual function belongs.
* @struct_offset: The offset of the function pointer in the class struct.
* The value 0xFFFF indicates that the struct offset is unknown.
* @invoker: If a method invoker for this virtual exists, this is the offset
* in the class structure of the method. If no method is known, this value
* will be 0x3ff.
* @reserved2: Reserved for future use.
* @reserved3: Reserved for future use.
* @signature: Offset of the SignatureBlob describing the parameter types and
* the return value type.
*
* TODO
*
* Since: 2.80
*/
typedef struct {
uint32_t name;
uint16_t must_chain_up : 1;
uint16_t must_be_implemented : 1;
uint16_t must_not_be_implemented : 1;
uint16_t class_closure : 1;
uint16_t throws : 1;
uint16_t reserved :11;
uint16_t signal;
uint16_t struct_offset;
uint16_t invoker : 10; /* Number of bits matches @index in FunctionBlob */
uint16_t reserved2 : 6;
uint32_t reserved3;
uint32_t signature;
} VFuncBlob;
/**
* ObjectBlob:
* @blob_type: #BLOB_TYPE_OBJECT
* @deprecated: whether the type is deprecated
* @abstract: whether the type can be instantiated
* @fundamental: this object is not a GObject derived type, instead it's
* an additional fundamental type.
* @final_: whether the type can be derived
* @reserved: Reserved for future use.
* @name: TODO
* @gtype_name: String name of the associated #GType
* @gtype_init: String naming the symbol which gets the runtime #GType
* @parent: The directory index of the parent type. This is only set for
* objects. If an object does not have a parent, it is zero.
* @gtype_struct: TODO
* @n_interfaces: TODO
* @n_fields: TODO
* @n_properties: TODO
* @n_methods: TODO
* @n_signals: TODO
* @n_vfuncs: TODO
* @n_constants: The lengths of the arrays.Up to 16bits of padding may be
* inserted between the arrays to ensure that they start on a 32bit
* boundary.
* @n_field_callbacks: The number of n_fields which are also callbacks.
* This is used to calculate the fields section size in constant time.
* @ref_func: String pointing to a function which can be called to increase
* the reference count for an instance of this object type.
* @unref_func: String pointing to a function which can be called to decrease
* the reference count for an instance of this object type.
* @set_value_func: String pointing to a function which can be called to
* convert a pointer of this object to a GValue
* @get_value_func: String pointing to a function which can be called to
* convert extract a pointer to this object from a GValue
* @reserved3: Reserved for future use.
* @reserved4: Reserved for future use.
* @interfaces: An array of indices of directory entries for the implemented
* interfaces.
*
* TODO
*
* Since: 2.80
*/
typedef struct {
uint16_t blob_type; /* 7 */
uint16_t deprecated : 1;
uint16_t abstract : 1;
uint16_t fundamental : 1;
uint16_t final_ : 1;
uint16_t reserved :12;
uint32_t name;
uint32_t gtype_name;
uint32_t gtype_init;
uint16_t parent;
uint16_t gtype_struct;
uint16_t n_interfaces;
uint16_t n_fields;
uint16_t n_properties;
uint16_t n_methods;
uint16_t n_signals;
uint16_t n_vfuncs;
uint16_t n_constants;
uint16_t n_field_callbacks;
uint32_t ref_func;
uint32_t unref_func;
uint32_t set_value_func;
uint32_t get_value_func;
uint32_t reserved3;
uint32_t reserved4;
uint16_t interfaces[];
} ObjectBlob;
/**
* InterfaceBlob:
* @blob_type: TODO
* @deprecated: TODO
* @reserved: Reserved for future use.
* @name: TODO
* @gtype_name: TODO
* @gtype_init: TODO
* @gtype_struct: Name of the interface "class" C structure
* @n_prerequisites: Number of prerequisites
* @n_properties: Number of properties
* @n_methods: Number of methods
* @n_signals: Number of signals
* @n_vfuncs: Number of virtual functions
* @n_constants: The lengths of the arrays. Up to 16bits of padding may be
* inserted between the arrays to ensure that they start on a 32bit
* boundary.
* @padding: TODO
* @reserved2: Reserved for future use.
* @reserved3: Reserved for future use.
* @prerequisites: An array of indices of directory entries for required
* interfaces.
*
* TODO
*
* Since: 2.80
*/
typedef struct {
uint16_t blob_type;
uint16_t deprecated : 1;
uint16_t reserved :15;
uint32_t name;
uint32_t gtype_name;
uint32_t gtype_init;
uint16_t gtype_struct;
uint16_t n_prerequisites;
uint16_t n_properties;
uint16_t n_methods;
uint16_t n_signals;
uint16_t n_vfuncs;
uint16_t n_constants;
uint16_t padding;
uint32_t reserved2;
uint32_t reserved3;
uint16_t prerequisites[];
} InterfaceBlob;
/**
* ConstantBlob:
* @blob_type: TODO
* @deprecated: TODO
* @reserved: Reserved for future use.
* @name: TODO
* @type: The type of the value. In most cases this should be a numeric type
* or string.
* @size: The size of the value in bytes.
* @offset: The offset of the value in the typelib.
* @reserved2: Reserved for future use.
*
* TODO
*
* Since: 2.80
*/
typedef struct {
uint16_t blob_type;
uint16_t deprecated : 1;
uint16_t reserved :15;
uint32_t name;
SimpleTypeBlob type;
uint32_t size;
uint32_t offset;
uint32_t reserved2;
} ConstantBlob;
/**
* AttributeBlob:
* @offset: The offset of the typelib entry to which this attribute refers.
* Attributes are kept sorted by offset, so that the attributes of an
* entry can be found by a binary search.
* @name: The name of the attribute, a string.
* @value: The value of the attribute (also a string)
*
* TODO
*
* Since: 2.80
*/
typedef struct {
uint32_t offset;
uint32_t name;
uint32_t value;
} AttributeBlob;
struct _GITypelib {
/*< private >*/
uint8_t *data;
size_t len;
gboolean owns_memory;
GMappedFile *mfile;
GList *modules;
gboolean open_attempted;
};
DirEntry *gi_typelib_get_dir_entry (GITypelib *typelib,
uint16_t index);
DirEntry *gi_typelib_get_dir_entry_by_name (GITypelib *typelib,
const char *name);
DirEntry *gi_typelib_get_dir_entry_by_gtype_name (GITypelib *typelib,
const char *gtype_name);
DirEntry *gi_typelib_get_dir_entry_by_error_domain (GITypelib *typelib,
GQuark error_domain);
gboolean gi_typelib_matches_gtype_name_prefix (GITypelib *typelib,
const char *gtype_name);
/**
* gi_typelib_get_string:
* @typelib: TODO
* @offset: TODO
*
* TODO
*
* Returns: TODO
* Since: 2.80
*/
#define gi_typelib_get_string(typelib,offset) ((const char*)&(typelib->data)[(offset)])
/**
* GITypelibError:
* @GI_TYPELIB_ERROR_INVALID: the typelib is invalid
* @GI_TYPELIB_ERROR_INVALID_HEADER: the typelib header is invalid
* @GI_TYPELIB_ERROR_INVALID_DIRECTORY: the typelib directory is invalid
* @GI_TYPELIB_ERROR_INVALID_ENTRY: a typelib entry is invalid
* @GI_TYPELIB_ERROR_INVALID_BLOB: a typelib blob is invalid
*
* A error set while validating the #GITypelib
*
* Since: 2.80
*/
typedef enum
{
GI_TYPELIB_ERROR_INVALID,
GI_TYPELIB_ERROR_INVALID_HEADER,
GI_TYPELIB_ERROR_INVALID_DIRECTORY,
GI_TYPELIB_ERROR_INVALID_ENTRY,
GI_TYPELIB_ERROR_INVALID_BLOB
} GITypelibError;
/**
* GI_TYPELIB_ERROR:
*
* TODO
*
* Since: 2.80
*/
#define GI_TYPELIB_ERROR (gi_typelib_error_quark ())
GQuark gi_typelib_error_quark (void);
GI_AVAILABLE_IN_ALL
gboolean gi_typelib_validate (GITypelib *typelib,
GError **error);
/* defined in gibaseinfo.c */
AttributeBlob *_attribute_blob_find_first (GIBaseInfo *info,
uint32_t blob_offset);
/**
* GITypelibHashBuilder:
*
* TODO
*
* Since: 2.80
*/
typedef struct _GITypelibHashBuilder GITypelibHashBuilder;
GITypelibHashBuilder * gi_typelib_hash_builder_new (void);
void gi_typelib_hash_builder_add_string (GITypelibHashBuilder *builder, const char *str, uint16_t value);
gboolean gi_typelib_hash_builder_prepare (GITypelibHashBuilder *builder);
uint32_t gi_typelib_hash_builder_get_buffer_size (GITypelibHashBuilder *builder);
void gi_typelib_hash_builder_pack (GITypelibHashBuilder *builder, uint8_t* mem, uint32_t size);
void gi_typelib_hash_builder_destroy (GITypelibHashBuilder *builder);
uint16_t gi_typelib_hash_search (uint8_t* memory, const char *str, uint32_t n_entries);
G_END_DECLS
|