Skip to content

Commit 2567ae7

Browse files
committed
ext/intl: trying out ideas for GH-19362
we re not implementing zend for C++ really here, just seeing how creating objects with zend mm allocator would play out with ICU.
1 parent fe88711 commit 2567ae7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extern "C" {
2222
#include <limits.h>
2323
}
2424

25+
#include "../intl_cppshims.h"
2526
#include "../intl_convertcpp.h"
2627
#include "../intl_common.h"
2728

@@ -138,7 +139,10 @@ U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, getRuleStatusVec)
138139
ZEND_ASSERT(BREAKITER_ERROR_CODE(bio) == U_BUFFER_OVERFLOW_ERROR);
139140
BREAKITER_ERROR_CODE(bio) = U_ZERO_ERROR;
140141

141-
std::unique_ptr<int32_t[]> rules = std::unique_ptr<int32_t[]>(new int32_t[num_rules]);
142+
int32_t *r = static_cast<int32_t *>(emalloc(num_rules * sizeof(int32_t)));
143+
144+
std::unique_ptr<int32_t[], decltype(&zend_mm_destructor<int32_t>)> rules(r, zend_mm_destructor);
145+
142146
num_rules = fetch_rbbi(bio)->getRuleStatusVec(rules.get(), num_rules,
143147
BREAKITER_ERROR_CODE(bio));
144148
if (U_FAILURE(BREAKITER_ERROR_CODE(bio))) {

ext/intl/intl_cppshims.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,15 @@
2929
#define _MSC_STDINT_H_ 1
3030
#endif
3131

32+
#include <type_traits>
33+
34+
template<typename T>
35+
void zend_mm_destructor(T *inst) {
36+
if (inst) {
37+
if constexpr (std::is_class_v<T>) {
38+
inst->~T();
39+
}
40+
efree(inst);
41+
}
42+
}
3243
#endif

0 commit comments

Comments
 (0)