Commit 89692bfc3f5ed44e00437747b34334126ea639b9
1 parent
57622f88
Exists in
master
and in
1 other branch
Fixing MSVC autoptr issue.
Showing
3 changed files
with
43 additions
and
7 deletions
Show diff stats
client/src/include/lib3270/ipc.h
... | ... | @@ -100,6 +100,42 @@ |
100 | 100 | */ |
101 | 101 | TN3270_PUBLIC std::vector<const LIB3270_ACTION *> getActions(); |
102 | 102 | |
103 | + /** | |
104 | + * @brief Lib3270 dynamic memory block wrapper. | |
105 | + * | |
106 | + */ | |
107 | + template<typename T> | |
108 | + class lib3270_auto_cleanup { | |
109 | + private: | |
110 | + T *data; | |
111 | + | |
112 | + public: | |
113 | + lib3270_auto_cleanup(T *data) { | |
114 | + this->data = data; | |
115 | + } | |
116 | + | |
117 | + ~lib3270_auto_cleanup() { | |
118 | + lib3270_free((void *) this->data); | |
119 | + } | |
120 | + | |
121 | + operator bool() const noexcept { | |
122 | + return this->data != NULL; | |
123 | + } | |
124 | + | |
125 | + T * operator->() { | |
126 | + return this->data; | |
127 | + } | |
128 | + | |
129 | + operator T *() const noexcept { | |
130 | + return this->data; | |
131 | + } | |
132 | + | |
133 | + }; | |
134 | + | |
135 | + /** | |
136 | + * @brief TN3270 Event. | |
137 | + * | |
138 | + */ | |
103 | 139 | class TN3270_PUBLIC Event { |
104 | 140 | public: |
105 | 141 | ... | ... |
client/src/session/local/get.cc
... | ... | @@ -46,39 +46,39 @@ |
46 | 46 | |
47 | 47 | std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); |
48 | 48 | |
49 | - lib3270_autoptr(char) text = lib3270_get_string_at_address(hSession, 0, -1, '\n'); | |
49 | + lib3270_auto_cleanup<char> text = lib3270_get_string_at_address(hSession, 0, -1, '\n'); | |
50 | 50 | |
51 | 51 | if(!text) { |
52 | 52 | throw std::runtime_error( _("Can't get screen contents") ); |
53 | 53 | } |
54 | 54 | |
55 | - return std::string(text); | |
55 | + return std::string((char *) text); | |
56 | 56 | } |
57 | 57 | |
58 | 58 | std::string Local::Session::get(int baddr, int len, char lf) const { |
59 | 59 | |
60 | 60 | std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); |
61 | 61 | |
62 | - lib3270_autoptr(char) text = lib3270_get_string_at_address(hSession, baddr, len, lf); | |
62 | + lib3270_auto_cleanup<char> text = lib3270_get_string_at_address(hSession, baddr, len, lf); | |
63 | 63 | |
64 | 64 | if(!text) { |
65 | 65 | throw std::runtime_error( _("Can't get screen contents") ); |
66 | 66 | } |
67 | 67 | |
68 | - return std::string(text); | |
68 | + return std::string((char *) text); | |
69 | 69 | } |
70 | 70 | |
71 | 71 | std::string Local::Session::get(unsigned int row, unsigned int col, int len, char lf) const { |
72 | 72 | |
73 | 73 | std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); |
74 | 74 | |
75 | - lib3270_autoptr(char) text = lib3270_get_string_at(hSession, row, col, len, lf); | |
75 | + lib3270_auto_cleanup<char> text = lib3270_get_string_at(hSession, row, col, len, lf); | |
76 | 76 | |
77 | 77 | if(!text) { |
78 | 78 | throw std::runtime_error( _("Can't get screen contents") ); |
79 | 79 | } |
80 | 80 | |
81 | - return std::string(text); | |
81 | + return std::string((char *) text); | |
82 | 82 | |
83 | 83 | } |
84 | 84 | ... | ... |
client/src/testprogram/testprogram.cc