Skip to content

Commit 68345ec

Browse files
committed
refactor(frankenlog): rework func params type
Currently, franken.gp:705 won't compile
1 parent ba25c2c commit 68345ec

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

frankenphp.c

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

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

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

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

frankenphp.go

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

685685
//export go_log_attrs
686-
func go_log_attrs(threadIndex C.uintptr_t, message *C.char, len C.int, level C.int, cattrs *C.zval) *C.char {
686+
func go_log_attrs(threadIndex C.uintptr_t, message *C.zend_string, level C.zend_long, cattrs *C.zval) *C.char {
687687
var attrs map[string]any
688688

689689
if cattrs == nil {
@@ -696,13 +696,13 @@ func go_log_attrs(threadIndex C.uintptr_t, message *C.char, len C.int, level C.i
696696
}
697697
}
698698

699-
m := C.GoStringN(message, len)
700-
lvl := slog.Level(level)
701-
702699
ctx := phpThreads[threadIndex].context()
703700

704-
if globalLogger.Enabled(ctx, lvl) {
705-
globalLogger.LogAttrs(ctx, lvl, m, mapToAttr(attrs)...)
701+
if globalLogger.Enabled(ctx, slog.Level(level)) {
702+
globalLogger.LogAttrs(ctx,
703+
slog.Level(level),
704+
GoString(unsafe.Pointer(message)),
705+
mapToAttr(attrs)...)
706706
}
707707

708708
return nil

0 commit comments

Comments
 (0)