extractZvalValue returns a pointer to the zval value cast to the expected type
(zval *C.zval, expectedType C.uint8_t)
| 437 | |
| 438 | // extractZvalValue returns a pointer to the zval value cast to the expected type |
| 439 | func extractZvalValue(zval *C.zval, expectedType C.uint8_t) (unsafe.Pointer, error) { |
| 440 | if zval == nil { |
| 441 | if expectedType == C.IS_NULL { |
| 442 | return nil, nil |
| 443 | } |
| 444 | |
| 445 | return nil, fmt.Errorf("zval type mismatch: expected %d, got nil", expectedType) |
| 446 | } |
| 447 | |
| 448 | if zType := C.zval_get_type(zval); zType != expectedType { |
| 449 | return nil, fmt.Errorf("zval type mismatch: expected %d, got %d", expectedType, zType) |
| 450 | } |
| 451 | |
| 452 | v := unsafe.Pointer(&zval.value[0]) |
| 453 | |
| 454 | switch expectedType { |
| 455 | case C.IS_LONG, C.IS_DOUBLE: |
| 456 | return v, nil |
| 457 | case C.IS_STRING: |
| 458 | return unsafe.Pointer(*(**C.zend_string)(v)), nil |
| 459 | case C.IS_ARRAY: |
| 460 | return unsafe.Pointer(*(**C.zend_array)(v)), nil |
| 461 | } |
| 462 | |
| 463 | return nil, fmt.Errorf("unsupported zval type %d", expectedType) |
| 464 | } |
| 465 | |
| 466 | func zendStringRelease(p unsafe.Pointer) { |
| 467 | zs := (*C.zend_string)(p) |