Skip to content

Commit 3c72573

Browse files
burgesQdunglas
authored andcommitted
refactor(frankenlog): rework func params type
Currently, franken.gp:705 won't compile
1 parent a16eaff commit 3c72573

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

frankenphp.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,20 +550,19 @@ PHP_FUNCTION(mercure_publish) {
550550
}
551551

552552
PHP_FUNCTION(frankenphp_log) {
553-
char *message = NULL;
554-
size_t message_len = 0;
553+
zend_string *message = NULL;
555554
zend_long level = 0;
556555
zval *context = NULL;
557556

558557
ZEND_PARSE_PARAMETERS_START(2, 3)
559-
Z_PARAM_STRING(message, message_len)
558+
Z_PARAM_STR(message)
560559
Z_PARAM_LONG(level)
561560
Z_PARAM_OPTIONAL
562561
Z_PARAM_ARRAY(context)
563562
ZEND_PARSE_PARAMETERS_END();
564563

565564
char *ret = NULL;
566-
ret = go_log_attrs(thread_index, message, message_len, (int)level, context);
565+
ret = go_log_attrs(thread_index, message, level, context);
567566
if (ret != NULL) {
568567
zend_throw_exception(spl_ce_RuntimeException, ret, 0);
569568
free(ret);

frankenphp.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ func go_log(threadIndex C.uintptr_t, message *C.char, level C.int) {
694694
}
695695

696696
//export go_log_attrs
697-
func go_log_attrs(threadIndex C.uintptr_t, message *C.char, len C.int, level C.int, cattrs *C.zval) *C.char {
697+
func go_log_attrs(threadIndex C.uintptr_t, message *C.zend_string, level C.zend_long, cattrs *C.zval) *C.char {
698698
var attrs map[string]any
699699

700700
if cattrs == nil {
@@ -707,13 +707,13 @@ func go_log_attrs(threadIndex C.uintptr_t, message *C.char, len C.int, level C.i
707707
}
708708
}
709709

710-
m := C.GoStringN(message, len)
711-
lvl := slog.Level(level)
712-
713710
ctx := phpThreads[threadIndex].context()
714711

715-
if globalLogger.Enabled(ctx, lvl) {
716-
globalLogger.LogAttrs(ctx, lvl, m, mapToAttr(attrs)...)
712+
if globalLogger.Enabled(ctx, slog.Level(level)) {
713+
globalLogger.LogAttrs(ctx,
714+
slog.Level(level),
715+
GoString(unsafe.Pointer(message)),
716+
mapToAttr(attrs)...)
717717
}
718718

719719
return nil

0 commit comments

Comments
 (0)