@@ -134,7 +134,7 @@ static void _php_intlgregcal_constructor_body(
134
134
135
135
// instantion of ICU object
136
136
Calendar_object *co = Z_INTL_CALENDAR_P (return_value);
137
- GregorianCalendar * gcal = NULL ;
137
+ std::unique_ptr< GregorianCalendar> gcal;
138
138
139
139
if (co->ucal ) {
140
140
zend_throw_error (NULL , " IntlGregorianCalendar object is already constructed" );
@@ -159,15 +159,12 @@ static void _php_intlgregcal_constructor_body(
159
159
locale = const_cast <char *>(intl_locale_get_default ());
160
160
}
161
161
162
- gcal = new GregorianCalendar (tz, Locale::createFromName (locale),
163
- status);
162
+ gcal = std::unique_ptr<GregorianCalendar>( new GregorianCalendar (tz, Locale::createFromName (locale),
163
+ status)) ;
164
164
// Should this throw?
165
165
if (U_FAILURE (status)) {
166
166
intl_error_set (NULL , status, " intlgregcal_create_instance: error "
167
167
" creating ICU GregorianCalendar from time zone and locale" , 0 );
168
- if (gcal) {
169
- delete gcal;
170
- }
171
168
delete tz;
172
169
if (!is_constructor) {
173
170
zval_ptr_dtor (return_value);
@@ -177,26 +174,28 @@ static void _php_intlgregcal_constructor_body(
177
174
}
178
175
} else {
179
176
// From date/time (3, 5 or 6 arguments)
177
+ GregorianCalendar *tmp;
180
178
for (int i = 0 ; i < variant; i++) {
181
179
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE (largs[i], hasThis () ? (i-1 ) : i);
182
180
}
183
181
184
182
if (variant == 3 ) {
185
- gcal = new GregorianCalendar ((int32_t )largs[0 ], (int32_t )largs[1 ],
183
+ tmp = new GregorianCalendar ((int32_t )largs[0 ], (int32_t )largs[1 ],
186
184
(int32_t )largs[2 ], status);
187
185
} else if (variant == 5 ) {
188
- gcal = new GregorianCalendar ((int32_t )largs[0 ], (int32_t )largs[1 ],
186
+ tmp = new GregorianCalendar ((int32_t )largs[0 ], (int32_t )largs[1 ],
189
187
(int32_t )largs[2 ], (int32_t )largs[3 ], (int32_t )largs[4 ], status);
190
188
} else if (variant == 6 ) {
191
- gcal = new GregorianCalendar ((int32_t )largs[0 ], (int32_t )largs[1 ],
189
+ tmp = new GregorianCalendar ((int32_t )largs[0 ], (int32_t )largs[1 ],
192
190
(int32_t )largs[2 ], (int32_t )largs[3 ], (int32_t )largs[4 ], (int32_t )largs[5 ],
193
191
status);
194
192
} else {
195
193
ZEND_UNREACHABLE ();
196
194
}
197
195
198
- if (!set_gregorian_calendar_time_zone (gcal, status)) {
199
- delete gcal;
196
+ gcal = std::unique_ptr<GregorianCalendar>(tmp);
197
+
198
+ if (!set_gregorian_calendar_time_zone (gcal.get (), status)) {
200
199
if (!is_constructor) {
201
200
zval_ptr_dtor (return_value);
202
201
RETVAL_NULL ();
@@ -205,7 +204,7 @@ static void _php_intlgregcal_constructor_body(
205
204
}
206
205
}
207
206
208
- co->ucal = gcal;
207
+ co->ucal = gcal. release () ;
209
208
}
210
209
211
210
U_CFUNC PHP_FUNCTION (intlgregcal_create_instance)
@@ -234,7 +233,7 @@ U_CFUNC PHP_METHOD(IntlGregorianCalendar, createFromDate)
234
233
UErrorCode status = U_ZERO_ERROR;
235
234
zend_error_handling error_handling;
236
235
Calendar_object *co;
237
- GregorianCalendar * gcal;
236
+ std::unique_ptr< GregorianCalendar> gcal;
238
237
239
238
intl_error_reset (NULL );
240
239
@@ -250,15 +249,14 @@ U_CFUNC PHP_METHOD(IntlGregorianCalendar, createFromDate)
250
249
251
250
zend_replace_error_handling (EH_THROW, IntlException_ce_ptr, &error_handling);
252
251
253
- gcal = new GregorianCalendar ((int32_t ) year, (int32_t ) month, (int32_t ) day, status);
254
- if (!set_gregorian_calendar_time_zone (gcal, status)) {
255
- delete gcal;
252
+ gcal = std::unique_ptr<GregorianCalendar>(new GregorianCalendar ((int32_t ) year, (int32_t ) month, (int32_t ) day, status));
253
+ if (!set_gregorian_calendar_time_zone (gcal.get (), status)) {
256
254
goto cleanup;
257
255
}
258
256
259
257
object_init_ex (return_value, GregorianCalendar_ce_ptr);
260
258
co = Z_INTL_CALENDAR_P (return_value);
261
- co->ucal = gcal;
259
+ co->ucal = gcal. release () ;
262
260
263
261
cleanup:
264
262
zend_restore_error_handling (&error_handling);
@@ -271,7 +269,7 @@ U_CFUNC PHP_METHOD(IntlGregorianCalendar, createFromDateTime)
271
269
UErrorCode status = U_ZERO_ERROR;
272
270
zend_error_handling error_handling;
273
271
Calendar_object *co;
274
- GregorianCalendar *gcal ;
272
+ GregorianCalendar *tmp ;
275
273
276
274
intl_error_reset (NULL );
277
275
@@ -294,19 +292,20 @@ U_CFUNC PHP_METHOD(IntlGregorianCalendar, createFromDateTime)
294
292
zend_replace_error_handling (EH_THROW, IntlException_ce_ptr, &error_handling);
295
293
296
294
if (second_is_null) {
297
- gcal = new GregorianCalendar ((int32_t ) year, (int32_t ) month, (int32_t ) day, (int32_t ) hour, (int32_t ) minute, status);
295
+ tmp = new GregorianCalendar ((int32_t ) year, (int32_t ) month, (int32_t ) day, (int32_t ) hour, (int32_t ) minute, status);
298
296
} else {
299
297
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE (second, 6 );
300
- gcal = new GregorianCalendar ((int32_t ) year, (int32_t ) month, (int32_t ) day, (int32_t ) hour, (int32_t ) minute, (int32_t ) second, status);
298
+ tmp = new GregorianCalendar ((int32_t ) year, (int32_t ) month, (int32_t ) day, (int32_t ) hour, (int32_t ) minute, (int32_t ) second, status);
301
299
}
302
- if (! set_gregorian_calendar_time_zone ( gcal, status)) {
303
- delete gcal;
300
+ auto gcal = std::unique_ptr<GregorianCalendar>(tmp);
301
+ if (! set_gregorian_calendar_time_zone ( gcal. get (), status)) {
304
302
goto cleanup;
305
303
}
306
304
307
305
object_init_ex (return_value, GregorianCalendar_ce_ptr);
308
306
co = Z_INTL_CALENDAR_P (return_value);
309
- co->ucal = gcal;
307
+ // TODO: trying to get passed the ownership change step
308
+ co->ucal = gcal.release ();
310
309
311
310
cleanup:
312
311
zend_restore_error_handling (&error_handling);
0 commit comments