aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2021-12-20 20:41:44 +0100
committerJay Berkenbilt <ejb@ql.org>2021-12-20 20:51:45 +0100
commitd866f480813169208efba0e4f32ecde4a5b54ebc (patch)
tree593a93d99ec00e361fbbd51c1054950cfd5491f5
parentcf7b2b5700de735f6db6904d001db598bfb947af (diff)
downloadqpdf-d866f480813169208efba0e4f32ecde4a5b54ebc.tar.zst
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.
-rw-r--r--include/qpdf/Constants.h32
-rw-r--r--include/qpdf/QPDFObject.hh26
-rw-r--r--libqpdf/qpdf-c.cc2
-rw-r--r--qpdf/qpdf-ctest.c24
4 files changed, 44 insertions, 40 deletions
diff --git a/include/qpdf/Constants.h b/include/qpdf/Constants.h
index 3e36a8f9..fab6e370 100644
--- a/include/qpdf/Constants.h
+++ b/include/qpdf/Constants.h
@@ -47,25 +47,29 @@ enum qpdf_error_code_e
* qpdf_oh, have a unique type code that has one of the values in the
* list below. As new object types are added to qpdf, additional items
* may be added to the list, so code that switches on these values
- * should take that into consideration.
+ * should take that into consideration. (Maintainer note: it would be
+ * better to call this qpdf_ot_* rather than ot_* to reduce likelihood
+ * of name collision, but since QPDFObject::object_type_e is an alias
+ * to this type, changing the names of the values breaks backward
+ * compatibility.)
*/
enum qpdf_object_type_e {
/* Object types internal to qpdf */
- qpdf_ot_uninitialized,
- qpdf_ot_reserved,
+ ot_uninitialized,
+ ot_reserved,
/* Object types that can occur in the main document */
- qpdf_ot_null,
- qpdf_ot_boolean,
- qpdf_ot_integer,
- qpdf_ot_real,
- qpdf_ot_string,
- qpdf_ot_name,
- qpdf_ot_array,
- qpdf_ot_dictionary,
- qpdf_ot_stream,
+ ot_null,
+ ot_boolean,
+ ot_integer,
+ ot_real,
+ ot_string,
+ ot_name,
+ ot_array,
+ ot_dictionary,
+ ot_stream,
/* Additional object types that can occur in content streams */
- qpdf_ot_operator,
- qpdf_ot_inlineimage,
+ ot_operator,
+ ot_inlineimage,
/* NOTE: if adding to this list, update QPDFObject.hh */
};
diff --git a/include/qpdf/QPDFObject.hh b/include/qpdf/QPDFObject.hh
index 02f51ab2..2e86a1f8 100644
--- a/include/qpdf/QPDFObject.hh
+++ b/include/qpdf/QPDFObject.hh
@@ -48,19 +48,19 @@ class QPDF_DLL_CLASS QPDFObject
// QPDFObject::object_type_e but was moved to make it accessible
// to the C API. The code below is for backward compatibility.
typedef enum qpdf_object_type_e object_type_e;
- static constexpr object_type_e ot_uninitialized = ::qpdf_ot_uninitialized;
- static constexpr object_type_e ot_reserved = ::qpdf_ot_reserved;
- static constexpr object_type_e ot_null = ::qpdf_ot_null;
- static constexpr object_type_e ot_boolean = ::qpdf_ot_boolean;
- static constexpr object_type_e ot_integer = ::qpdf_ot_integer;
- static constexpr object_type_e ot_real = ::qpdf_ot_real;
- static constexpr object_type_e ot_string = ::qpdf_ot_string;
- static constexpr object_type_e ot_name = ::qpdf_ot_name;
- static constexpr object_type_e ot_array = ::qpdf_ot_array;
- static constexpr object_type_e ot_dictionary = ::qpdf_ot_dictionary;
- static constexpr object_type_e ot_stream = ::qpdf_ot_stream;
- static constexpr object_type_e ot_operator = ::qpdf_ot_operator;
- static constexpr object_type_e ot_inlineimage = ::qpdf_ot_inlineimage;
+ static constexpr object_type_e ot_uninitialized = ::ot_uninitialized;
+ static constexpr object_type_e ot_reserved = ::ot_reserved;
+ static constexpr object_type_e ot_null = ::ot_null;
+ static constexpr object_type_e ot_boolean = ::ot_boolean;
+ static constexpr object_type_e ot_integer = ::ot_integer;
+ static constexpr object_type_e ot_real = ::ot_real;
+ static constexpr object_type_e ot_string = ::ot_string;
+ static constexpr object_type_e ot_name = ::ot_name;
+ static constexpr object_type_e ot_array = ::ot_array;
+ static constexpr object_type_e ot_dictionary = ::ot_dictionary;
+ static constexpr object_type_e ot_stream = ::ot_stream;
+ static constexpr object_type_e ot_operator = ::ot_operator;
+ static constexpr object_type_e ot_inlineimage = ::ot_inlineimage;
virtual ~QPDFObject() {}
virtual std::string unparse() = 0;
diff --git a/libqpdf/qpdf-c.cc b/libqpdf/qpdf-c.cc
index 5f702272..fb79407d 100644
--- a/libqpdf/qpdf-c.cc
+++ b/libqpdf/qpdf-c.cc
@@ -1151,7 +1151,7 @@ QPDF_BOOL qpdf_oh_is_number(qpdf_data qpdf, qpdf_oh oh)
qpdf_object_type_e qpdf_oh_get_type_code(qpdf_data qpdf, qpdf_oh oh)
{
return do_with_oh<qpdf_object_type_e>(
- qpdf, oh, return_T<qpdf_object_type_e>(qpdf_ot_uninitialized),
+ qpdf, oh, return_T<qpdf_object_type_e>(ot_uninitialized),
[](QPDFObjectHandle& o) {
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_type_code");
return o.getTypeCode();
diff --git a/qpdf/qpdf-ctest.c b/qpdf/qpdf-ctest.c
index 953b24d0..af743b01 100644
--- a/qpdf/qpdf-ctest.c
+++ b/qpdf/qpdf-ctest.c
@@ -537,12 +537,12 @@ static void test24(char const* infile,
/* Go to the first page and look at all the keys */
qpdf_oh pages = qpdf_oh_get_key(qpdf, root, "/Pages");
assert(qpdf_oh_is_dictionary(qpdf, pages));
- assert(qpdf_oh_get_type_code(qpdf, pages) == qpdf_ot_dictionary);
+ assert(qpdf_oh_get_type_code(qpdf, pages) == ot_dictionary);
assert(strcmp(qpdf_oh_get_type_name(qpdf, pages), "dictionary") == 0);
assert(qpdf_oh_is_initialized(qpdf, pages));
qpdf_oh kids = qpdf_oh_get_key(qpdf, pages, "/Kids");
assert(qpdf_oh_is_array(qpdf, kids));
- assert(qpdf_oh_get_type_code(qpdf, kids) == qpdf_ot_array);
+ assert(qpdf_oh_get_type_code(qpdf, kids) == ot_array);
assert(strcmp(qpdf_oh_get_type_name(qpdf, kids), "array") == 0);
assert(qpdf_oh_get_array_n_items(qpdf, kids) == 1);
qpdf_oh page1 = qpdf_oh_get_array_item(qpdf, kids, 0);
@@ -555,7 +555,7 @@ static void test24(char const* infile,
/* Inspect the first page */
qpdf_oh type = qpdf_oh_get_key(qpdf, page1, "/Type");
assert(qpdf_oh_is_name(qpdf, type));
- assert(qpdf_oh_get_type_code(qpdf, type) == qpdf_ot_name);
+ assert(qpdf_oh_get_type_code(qpdf, type) == ot_name);
assert(strcmp(qpdf_oh_get_type_name(qpdf, type), "name") == 0);
assert(strcmp(qpdf_oh_get_name(qpdf, type), "/Page") == 0);
qpdf_oh parent = qpdf_oh_get_key(qpdf, page1, "/Parent");
@@ -595,14 +595,14 @@ static void test24(char const* infile,
/* Look at page contents to exercise stream functions */
qpdf_oh contents = qpdf_oh_get_key(qpdf, page1, "/Contents");
assert(qpdf_oh_is_stream(qpdf, contents));
- assert(qpdf_oh_get_type_code(qpdf, contents) == qpdf_ot_stream);
+ assert(qpdf_oh_get_type_code(qpdf, contents) == ot_stream);
assert(strcmp(qpdf_oh_get_type_name(qpdf, contents), "stream") == 0);
qpdf_oh contents_dict = qpdf_oh_get_dict(qpdf, contents);
assert(! qpdf_oh_is_scalar(qpdf, contents));
assert(! qpdf_oh_is_scalar(qpdf, contents_dict));
qpdf_oh contents_length = qpdf_oh_get_key(qpdf, contents_dict, "/Length");
assert(qpdf_oh_is_integer(qpdf, contents_length));
- assert(qpdf_oh_get_type_code(qpdf, contents_length) == qpdf_ot_integer);
+ assert(qpdf_oh_get_type_code(qpdf, contents_length) == ot_integer);
assert(strcmp(qpdf_oh_get_type_name(qpdf, contents_length), "integer") == 0);
assert(qpdf_oh_is_scalar(qpdf, contents_length));
assert(qpdf_oh_is_number(qpdf, contents_length));
@@ -643,7 +643,7 @@ static void test24(char const* infile,
qpdf_oh_release(qpdf, page1);
contents = qpdf_oh_get_key(qpdf, page1, "/Contents");
assert(qpdf_oh_is_null(qpdf, contents));
- assert(qpdf_oh_get_type_code(qpdf, contents) == qpdf_ot_null);
+ assert(qpdf_oh_get_type_code(qpdf, contents) == ot_null);
assert(strcmp(qpdf_oh_get_type_name(qpdf, contents), "null") == 0);
assert(qpdf_oh_is_array(qpdf, mediabox));
qpdf_oh_release_all(qpdf);
@@ -682,18 +682,18 @@ static void test25(char const* infile,
qpdf_oh p_bool = qpdf_oh_get_array_item(qpdf, parsed, 5);
assert(qpdf_oh_is_integer(qpdf, p_int) &&
qpdf_oh_get_int_value_as_int(qpdf, p_int) == 1);
- assert(qpdf_oh_get_type_code(qpdf, p_int) == qpdf_ot_integer);
+ assert(qpdf_oh_get_type_code(qpdf, p_int) == ot_integer);
assert(strcmp(qpdf_oh_get_type_name(qpdf, p_int), "integer") == 0);
assert(qpdf_oh_is_real(qpdf, p_real) &&
(strcmp(qpdf_oh_get_real_value(qpdf, p_real), "2.0") == 0) &&
qpdf_oh_get_numeric_value(qpdf, p_real) == 2.0);
- assert(qpdf_oh_get_type_code(qpdf, p_real) == qpdf_ot_real);
+ assert(qpdf_oh_get_type_code(qpdf, p_real) == ot_real);
assert(strcmp(qpdf_oh_get_type_name(qpdf, p_real), "real") == 0);
assert(qpdf_oh_is_string(qpdf, p_string) &&
(strcmp(qpdf_oh_get_string_value(qpdf, p_string), "3\xf7") == 0) &&
(strcmp(qpdf_oh_get_utf8_value(qpdf, p_string), "3\xc3\xb7") == 0) &&
(strcmp(qpdf_oh_unparse_binary(qpdf, p_string), "<33f7>") == 0));
- assert(qpdf_oh_get_type_code(qpdf, p_string) == qpdf_ot_string);
+ assert(qpdf_oh_get_type_code(qpdf, p_string) == ot_string);
assert(strcmp(qpdf_oh_get_type_name(qpdf, p_string), "string") == 0);
assert(qpdf_oh_is_dictionary(qpdf, p_dict));
qpdf_oh p_five = qpdf_oh_get_key(qpdf, p_dict, "/Four");
@@ -701,11 +701,11 @@ static void test25(char const* infile,
assert(qpdf_oh_is_or_has_name(
qpdf, qpdf_oh_get_array_item(qpdf, p_five, 0), "/Five"));
assert(qpdf_oh_is_null(qpdf, p_null));
- assert(qpdf_oh_get_type_code(qpdf, p_null) == qpdf_ot_null);
+ assert(qpdf_oh_get_type_code(qpdf, p_null) == ot_null);
assert(strcmp(qpdf_oh_get_type_name(qpdf, p_null), "null") == 0);
assert(qpdf_oh_is_bool(qpdf, p_bool) &&
(qpdf_oh_get_bool_value(qpdf, p_bool) == QPDF_TRUE));
- assert(qpdf_oh_get_type_code(qpdf, p_bool) == qpdf_ot_boolean);
+ assert(qpdf_oh_get_type_code(qpdf, p_bool) == ot_boolean);
assert(strcmp(qpdf_oh_get_type_name(qpdf, p_bool), "boolean") == 0);
qpdf_oh_erase_item(qpdf, parsed, 4);
qpdf_oh_insert_item(
@@ -763,7 +763,7 @@ static void test26(char const* infile,
qpdf_data qpdf2 = qpdf_init();
qpdf_oh trailer = qpdf_get_trailer(qpdf2);
assert(! qpdf_oh_is_initialized(qpdf2, trailer));
- assert(qpdf_oh_get_type_code(qpdf, trailer) == qpdf_ot_uninitialized);
+ assert(qpdf_oh_get_type_code(qpdf, trailer) == ot_uninitialized);
qpdf_cleanup(&qpdf2);
}