Commit 4b3bed2b56136fdae62c25432efc0c9d41ffd4ff

Authored by m-holger
1 parent fd52eae8

Refactor `qpdf-c` object handle management: replace `shared_ptr` with direct `QP…

…DFObjectHandle` storage, remove unused trace calls, and streamline invalid handle checks.
libqpdf/qpdf-c.cc
@@ -833,28 +833,25 @@ static qpdf_oh @@ -833,28 +833,25 @@ static qpdf_oh
833 new_object(qpdf_data qpdf, QPDFObjectHandle const& qoh) 833 new_object(qpdf_data qpdf, QPDFObjectHandle const& qoh)
834 { 834 {
835 qpdf_oh oh = ++qpdf->next_oh; // never return 0 835 qpdf_oh oh = ++qpdf->next_oh; // never return 0
836 - qpdf->oh_cache[oh] = std::make_shared<QPDFObjectHandle>(qoh); 836 + qpdf->oh_cache[oh] = qoh;
837 return oh; 837 return oh;
838 } 838 }
839 839
840 qpdf_oh 840 qpdf_oh
841 qpdf_oh_new_object(qpdf_data qpdf, qpdf_oh oh) 841 qpdf_oh_new_object(qpdf_data qpdf, qpdf_oh oh)
842 { 842 {
843 - QTC::TC("qpdf", "qpdf-c called qpdf_new_object");  
844 - return new_object(qpdf, *(qpdf->oh_cache[oh])); 843 + return new_object(qpdf, qpdf->oh_cache[oh]);
845 } 844 }
846 845
847 void 846 void
848 qpdf_oh_release(qpdf_data qpdf, qpdf_oh oh) 847 qpdf_oh_release(qpdf_data qpdf, qpdf_oh oh)
849 { 848 {
850 - QTC::TC("qpdf", "qpdf-c called qpdf_oh_release");  
851 qpdf->oh_cache.erase(oh); 849 qpdf->oh_cache.erase(oh);
852 } 850 }
853 851
854 void 852 void
855 qpdf_oh_release_all(qpdf_data qpdf) 853 qpdf_oh_release_all(qpdf_data qpdf)
856 { 854 {
857 - QTC::TC("qpdf", "qpdf-c called qpdf_oh_release_all");  
858 qpdf->oh_cache.clear(); 855 qpdf->oh_cache.clear();
859 } 856 }
860 857
@@ -904,8 +901,7 @@ qpdf_get_root(qpdf_data qpdf) @@ -904,8 +901,7 @@ qpdf_get_root(qpdf_data qpdf)
904 qpdf_oh 901 qpdf_oh
905 qpdf_get_object_by_id(qpdf_data qpdf, int objid, int generation) 902 qpdf_get_object_by_id(qpdf_data qpdf, int objid, int generation)
906 { 903 {
907 - QTC::TC("qpdf", "qpdf-c called qpdf_get_object_by_id");  
908 - return new_object(qpdf, qpdf->qpdf->getObjectByID(objid, generation)); 904 + return new_object(qpdf, qpdf->qpdf->getObject(objid, generation));
909 } 905 }
910 906
911 template <class RET> 907 template <class RET>
@@ -918,9 +914,7 @@ do_with_oh( @@ -918,9 +914,7 @@ do_with_oh(
918 { 914 {
919 return trap_oh_errors<RET>(qpdf, fallback, [fn, oh](qpdf_data q) { 915 return trap_oh_errors<RET>(qpdf, fallback, [fn, oh](qpdf_data q) {
920 auto i = q->oh_cache.find(oh); 916 auto i = q->oh_cache.find(oh);
921 - bool result = ((i != q->oh_cache.end()) && (i->second).get());  
922 - if (!result) {  
923 - QTC::TC("qpdf", "qpdf-c invalid object handle"); 917 + if (i == q->oh_cache.end()) {
924 throw QPDFExc( 918 throw QPDFExc(
925 qpdf_e_internal, 919 qpdf_e_internal,
926 q->qpdf->getFilename(), 920 q->qpdf->getFilename(),
@@ -928,7 +922,7 @@ do_with_oh( @@ -928,7 +922,7 @@ do_with_oh(
928 0, 922 0,
929 "attempted access to unknown object handle"); 923 "attempted access to unknown object handle");
930 } 924 }
931 - return fn(*(q->oh_cache[oh])); 925 + return fn(i->second);
932 }); 926 });
933 } 927 }
934 928
libqpdf/qpdf/qpdf-c_impl.hh
@@ -39,7 +39,7 @@ struct _qpdf_data @@ -39,7 +39,7 @@ struct _qpdf_data
39 // QPDFObjectHandle support 39 // QPDFObjectHandle support
40 bool silence_errors{false}; 40 bool silence_errors{false};
41 bool oh_error_occurred{false}; 41 bool oh_error_occurred{false};
42 - std::map<qpdf_oh, std::shared_ptr<QPDFObjectHandle>> oh_cache; 42 + std::map<qpdf_oh, QPDFObjectHandle> oh_cache;
43 qpdf_oh next_oh{0}; 43 qpdf_oh next_oh{0};
44 std::set<std::string> cur_iter_dict_keys; 44 std::set<std::string> cur_iter_dict_keys;
45 std::set<std::string>::const_iterator dict_iter; 45 std::set<std::string>::const_iterator dict_iter;
qpdf/qpdf.testcov
@@ -263,10 +263,6 @@ QPDFJob found shared resources in leaf 0 @@ -263,10 +263,6 @@ QPDFJob found shared resources in leaf 0
263 QPDFJob found shared xobject in leaf 0 263 QPDFJob found shared xobject in leaf 0
264 QPDFObjectHandle need_newline 1 264 QPDFObjectHandle need_newline 1
265 QPDFJob pages range omitted with . 0 265 QPDFJob pages range omitted with . 0
266 -qpdf-c invalid object handle 0  
267 -qpdf-c called qpdf_oh_release 0  
268 -qpdf-c called qpdf_oh_release_all 0  
269 -qpdf-c called qpdf_new_object 0  
270 qpdf-c called qpdf_get_trailer 0 266 qpdf-c called qpdf_get_trailer 0
271 qpdf-c called qpdf_get_root 0 267 qpdf-c called qpdf_get_root 0
272 qpdf-c called qpdf_oh_is_bool 0 268 qpdf-c called qpdf_oh_is_bool 0
@@ -365,7 +361,6 @@ qpdf-c registered progress reporter 0 @@ -365,7 +361,6 @@ qpdf-c registered progress reporter 0
365 qpdf-c called qpdf_oh_new_uninitialized 0 361 qpdf-c called qpdf_oh_new_uninitialized 0
366 qpdf-c warn about oh error 1 362 qpdf-c warn about oh error 1
367 qpdf-c cleanup warned about unhandled error 0 363 qpdf-c cleanup warned about unhandled error 0
368 -qpdf-c called qpdf_get_object_by_id 0  
369 qpdf-c called qpdf_replace_object 0 364 qpdf-c called qpdf_replace_object 0
370 qpdf-c called qpdf_update_all_pages_cache 0 365 qpdf-c called qpdf_update_all_pages_cache 0
371 qpdf-c called qpdf_find_page_by_id 0 366 qpdf-c called qpdf_find_page_by_id 0