Commit d866f480813169208efba0e4f32ecde4a5b54ebc

Authored by Jay Berkenbilt
1 parent cf7b2b57

Change names of qpdf_object_type_e enumerations

They have to be ot_* rather than qpdf_ot_* for compatibility.

* Different enumerated types are not assignment-compatible in C++, at
  least with strict compiler settings
* While you can do `constexpr ot_xyz = ::qpdf_ot_xyz` in QPDFObject.hh to
  make QPDFObject::ot_xyz work, QPDFObject::object_type_e::ot_xyz will
  only work if the enumerated type names are the same.
include/qpdf/Constants.h
... ... @@ -47,25 +47,29 @@ enum qpdf_error_code_e
47 47 * qpdf_oh, have a unique type code that has one of the values in the
48 48 * list below. As new object types are added to qpdf, additional items
49 49 * may be added to the list, so code that switches on these values
50   - * should take that into consideration.
  50 + * should take that into consideration. (Maintainer note: it would be
  51 + * better to call this qpdf_ot_* rather than ot_* to reduce likelihood
  52 + * of name collision, but since QPDFObject::object_type_e is an alias
  53 + * to this type, changing the names of the values breaks backward
  54 + * compatibility.)
51 55 */
52 56 enum qpdf_object_type_e {
53 57 /* Object types internal to qpdf */
54   - qpdf_ot_uninitialized,
55   - qpdf_ot_reserved,
  58 + ot_uninitialized,
  59 + ot_reserved,
56 60 /* Object types that can occur in the main document */
57   - qpdf_ot_null,
58   - qpdf_ot_boolean,
59   - qpdf_ot_integer,
60   - qpdf_ot_real,
61   - qpdf_ot_string,
62   - qpdf_ot_name,
63   - qpdf_ot_array,
64   - qpdf_ot_dictionary,
65   - qpdf_ot_stream,
  61 + ot_null,
  62 + ot_boolean,
  63 + ot_integer,
  64 + ot_real,
  65 + ot_string,
  66 + ot_name,
  67 + ot_array,
  68 + ot_dictionary,
  69 + ot_stream,
66 70 /* Additional object types that can occur in content streams */
67   - qpdf_ot_operator,
68   - qpdf_ot_inlineimage,
  71 + ot_operator,
  72 + ot_inlineimage,
69 73 /* NOTE: if adding to this list, update QPDFObject.hh */
70 74 };
71 75  
... ...
include/qpdf/QPDFObject.hh
... ... @@ -48,19 +48,19 @@ class QPDF_DLL_CLASS QPDFObject
48 48 // QPDFObject::object_type_e but was moved to make it accessible
49 49 // to the C API. The code below is for backward compatibility.
50 50 typedef enum qpdf_object_type_e object_type_e;
51   - static constexpr object_type_e ot_uninitialized = ::qpdf_ot_uninitialized;
52   - static constexpr object_type_e ot_reserved = ::qpdf_ot_reserved;
53   - static constexpr object_type_e ot_null = ::qpdf_ot_null;
54   - static constexpr object_type_e ot_boolean = ::qpdf_ot_boolean;
55   - static constexpr object_type_e ot_integer = ::qpdf_ot_integer;
56   - static constexpr object_type_e ot_real = ::qpdf_ot_real;
57   - static constexpr object_type_e ot_string = ::qpdf_ot_string;
58   - static constexpr object_type_e ot_name = ::qpdf_ot_name;
59   - static constexpr object_type_e ot_array = ::qpdf_ot_array;
60   - static constexpr object_type_e ot_dictionary = ::qpdf_ot_dictionary;
61   - static constexpr object_type_e ot_stream = ::qpdf_ot_stream;
62   - static constexpr object_type_e ot_operator = ::qpdf_ot_operator;
63   - static constexpr object_type_e ot_inlineimage = ::qpdf_ot_inlineimage;
  51 + static constexpr object_type_e ot_uninitialized = ::ot_uninitialized;
  52 + static constexpr object_type_e ot_reserved = ::ot_reserved;
  53 + static constexpr object_type_e ot_null = ::ot_null;
  54 + static constexpr object_type_e ot_boolean = ::ot_boolean;
  55 + static constexpr object_type_e ot_integer = ::ot_integer;
  56 + static constexpr object_type_e ot_real = ::ot_real;
  57 + static constexpr object_type_e ot_string = ::ot_string;
  58 + static constexpr object_type_e ot_name = ::ot_name;
  59 + static constexpr object_type_e ot_array = ::ot_array;
  60 + static constexpr object_type_e ot_dictionary = ::ot_dictionary;
  61 + static constexpr object_type_e ot_stream = ::ot_stream;
  62 + static constexpr object_type_e ot_operator = ::ot_operator;
  63 + static constexpr object_type_e ot_inlineimage = ::ot_inlineimage;
64 64  
65 65 virtual ~QPDFObject() {}
66 66 virtual std::string unparse() = 0;
... ...
libqpdf/qpdf-c.cc
... ... @@ -1151,7 +1151,7 @@ QPDF_BOOL qpdf_oh_is_number(qpdf_data qpdf, qpdf_oh oh)
1151 1151 qpdf_object_type_e qpdf_oh_get_type_code(qpdf_data qpdf, qpdf_oh oh)
1152 1152 {
1153 1153 return do_with_oh<qpdf_object_type_e>(
1154   - qpdf, oh, return_T<qpdf_object_type_e>(qpdf_ot_uninitialized),
  1154 + qpdf, oh, return_T<qpdf_object_type_e>(ot_uninitialized),
1155 1155 [](QPDFObjectHandle& o) {
1156 1156 QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_type_code");
1157 1157 return o.getTypeCode();
... ...
qpdf/qpdf-ctest.c
... ... @@ -537,12 +537,12 @@ static void test24(char const* infile,
537 537 /* Go to the first page and look at all the keys */
538 538 qpdf_oh pages = qpdf_oh_get_key(qpdf, root, "/Pages");
539 539 assert(qpdf_oh_is_dictionary(qpdf, pages));
540   - assert(qpdf_oh_get_type_code(qpdf, pages) == qpdf_ot_dictionary);
  540 + assert(qpdf_oh_get_type_code(qpdf, pages) == ot_dictionary);
541 541 assert(strcmp(qpdf_oh_get_type_name(qpdf, pages), "dictionary") == 0);
542 542 assert(qpdf_oh_is_initialized(qpdf, pages));
543 543 qpdf_oh kids = qpdf_oh_get_key(qpdf, pages, "/Kids");
544 544 assert(qpdf_oh_is_array(qpdf, kids));
545   - assert(qpdf_oh_get_type_code(qpdf, kids) == qpdf_ot_array);
  545 + assert(qpdf_oh_get_type_code(qpdf, kids) == ot_array);
546 546 assert(strcmp(qpdf_oh_get_type_name(qpdf, kids), "array") == 0);
547 547 assert(qpdf_oh_get_array_n_items(qpdf, kids) == 1);
548 548 qpdf_oh page1 = qpdf_oh_get_array_item(qpdf, kids, 0);
... ... @@ -555,7 +555,7 @@ static void test24(char const* infile,
555 555 /* Inspect the first page */
556 556 qpdf_oh type = qpdf_oh_get_key(qpdf, page1, "/Type");
557 557 assert(qpdf_oh_is_name(qpdf, type));
558   - assert(qpdf_oh_get_type_code(qpdf, type) == qpdf_ot_name);
  558 + assert(qpdf_oh_get_type_code(qpdf, type) == ot_name);
559 559 assert(strcmp(qpdf_oh_get_type_name(qpdf, type), "name") == 0);
560 560 assert(strcmp(qpdf_oh_get_name(qpdf, type), "/Page") == 0);
561 561 qpdf_oh parent = qpdf_oh_get_key(qpdf, page1, "/Parent");
... ... @@ -595,14 +595,14 @@ static void test24(char const* infile,
595 595 /* Look at page contents to exercise stream functions */
596 596 qpdf_oh contents = qpdf_oh_get_key(qpdf, page1, "/Contents");
597 597 assert(qpdf_oh_is_stream(qpdf, contents));
598   - assert(qpdf_oh_get_type_code(qpdf, contents) == qpdf_ot_stream);
  598 + assert(qpdf_oh_get_type_code(qpdf, contents) == ot_stream);
599 599 assert(strcmp(qpdf_oh_get_type_name(qpdf, contents), "stream") == 0);
600 600 qpdf_oh contents_dict = qpdf_oh_get_dict(qpdf, contents);
601 601 assert(! qpdf_oh_is_scalar(qpdf, contents));
602 602 assert(! qpdf_oh_is_scalar(qpdf, contents_dict));
603 603 qpdf_oh contents_length = qpdf_oh_get_key(qpdf, contents_dict, "/Length");
604 604 assert(qpdf_oh_is_integer(qpdf, contents_length));
605   - assert(qpdf_oh_get_type_code(qpdf, contents_length) == qpdf_ot_integer);
  605 + assert(qpdf_oh_get_type_code(qpdf, contents_length) == ot_integer);
606 606 assert(strcmp(qpdf_oh_get_type_name(qpdf, contents_length), "integer") == 0);
607 607 assert(qpdf_oh_is_scalar(qpdf, contents_length));
608 608 assert(qpdf_oh_is_number(qpdf, contents_length));
... ... @@ -643,7 +643,7 @@ static void test24(char const* infile,
643 643 qpdf_oh_release(qpdf, page1);
644 644 contents = qpdf_oh_get_key(qpdf, page1, "/Contents");
645 645 assert(qpdf_oh_is_null(qpdf, contents));
646   - assert(qpdf_oh_get_type_code(qpdf, contents) == qpdf_ot_null);
  646 + assert(qpdf_oh_get_type_code(qpdf, contents) == ot_null);
647 647 assert(strcmp(qpdf_oh_get_type_name(qpdf, contents), "null") == 0);
648 648 assert(qpdf_oh_is_array(qpdf, mediabox));
649 649 qpdf_oh_release_all(qpdf);
... ... @@ -682,18 +682,18 @@ static void test25(char const* infile,
682 682 qpdf_oh p_bool = qpdf_oh_get_array_item(qpdf, parsed, 5);
683 683 assert(qpdf_oh_is_integer(qpdf, p_int) &&
684 684 qpdf_oh_get_int_value_as_int(qpdf, p_int) == 1);
685   - assert(qpdf_oh_get_type_code(qpdf, p_int) == qpdf_ot_integer);
  685 + assert(qpdf_oh_get_type_code(qpdf, p_int) == ot_integer);
686 686 assert(strcmp(qpdf_oh_get_type_name(qpdf, p_int), "integer") == 0);
687 687 assert(qpdf_oh_is_real(qpdf, p_real) &&
688 688 (strcmp(qpdf_oh_get_real_value(qpdf, p_real), "2.0") == 0) &&
689 689 qpdf_oh_get_numeric_value(qpdf, p_real) == 2.0);
690   - assert(qpdf_oh_get_type_code(qpdf, p_real) == qpdf_ot_real);
  690 + assert(qpdf_oh_get_type_code(qpdf, p_real) == ot_real);
691 691 assert(strcmp(qpdf_oh_get_type_name(qpdf, p_real), "real") == 0);
692 692 assert(qpdf_oh_is_string(qpdf, p_string) &&
693 693 (strcmp(qpdf_oh_get_string_value(qpdf, p_string), "3\xf7") == 0) &&
694 694 (strcmp(qpdf_oh_get_utf8_value(qpdf, p_string), "3\xc3\xb7") == 0) &&
695 695 (strcmp(qpdf_oh_unparse_binary(qpdf, p_string), "<33f7>") == 0));
696   - assert(qpdf_oh_get_type_code(qpdf, p_string) == qpdf_ot_string);
  696 + assert(qpdf_oh_get_type_code(qpdf, p_string) == ot_string);
697 697 assert(strcmp(qpdf_oh_get_type_name(qpdf, p_string), "string") == 0);
698 698 assert(qpdf_oh_is_dictionary(qpdf, p_dict));
699 699 qpdf_oh p_five = qpdf_oh_get_key(qpdf, p_dict, "/Four");
... ... @@ -701,11 +701,11 @@ static void test25(char const* infile,
701 701 assert(qpdf_oh_is_or_has_name(
702 702 qpdf, qpdf_oh_get_array_item(qpdf, p_five, 0), "/Five"));
703 703 assert(qpdf_oh_is_null(qpdf, p_null));
704   - assert(qpdf_oh_get_type_code(qpdf, p_null) == qpdf_ot_null);
  704 + assert(qpdf_oh_get_type_code(qpdf, p_null) == ot_null);
705 705 assert(strcmp(qpdf_oh_get_type_name(qpdf, p_null), "null") == 0);
706 706 assert(qpdf_oh_is_bool(qpdf, p_bool) &&
707 707 (qpdf_oh_get_bool_value(qpdf, p_bool) == QPDF_TRUE));
708   - assert(qpdf_oh_get_type_code(qpdf, p_bool) == qpdf_ot_boolean);
  708 + assert(qpdf_oh_get_type_code(qpdf, p_bool) == ot_boolean);
709 709 assert(strcmp(qpdf_oh_get_type_name(qpdf, p_bool), "boolean") == 0);
710 710 qpdf_oh_erase_item(qpdf, parsed, 4);
711 711 qpdf_oh_insert_item(
... ... @@ -763,7 +763,7 @@ static void test26(char const* infile,
763 763 qpdf_data qpdf2 = qpdf_init();
764 764 qpdf_oh trailer = qpdf_get_trailer(qpdf2);
765 765 assert(! qpdf_oh_is_initialized(qpdf2, trailer));
766   - assert(qpdf_oh_get_type_code(qpdf, trailer) == qpdf_ot_uninitialized);
  766 + assert(qpdf_oh_get_type_code(qpdf, trailer) == ot_uninitialized);
767 767 qpdf_cleanup(&qpdf2);
768 768 }
769 769  
... ...