Skip to content

Commit 62a4844

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 62a4844

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp

Lines changed: 6 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,11 @@ 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+
void *p = emalloc(num_rules * sizeof(int32_t));
143+
int32_t *r = static_cast<int32_t *>(p);
144+
145+
std::unique_ptr<int32_t[], decltype(&zend_mm_destructor<int32_t>)> rules(r, zend_mm_destructor);
146+
142147
num_rules = fetch_rbbi(bio)->getRuleStatusVec(rules.get(), num_rules,
143148
BREAKITER_ERROR_CODE(bio));
144149
if (U_FAILURE(BREAKITER_ERROR_CODE(bio))) {

ext/intl/intl_cppshims.h

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

32+
template<typename T>
33+
void zend_mm_destructor(T *inst) {
34+
if (inst) {
35+
inst->~T();
36+
efree(inst);
37+
}
38+
}
39+
3240
#endif

0 commit comments

Comments
 (0)