diff --git a/src/chinese_whispers.cc b/src/chinese_whispers.cc index 7f329a6..6b9d0b5 100644 --- a/src/chinese_whispers.cc +++ b/src/chinese_whispers.cc @@ -17,11 +17,7 @@ PHP_FUNCTION(dlib_chinese_whispers) std::vector edges; std::vector labels; - if(zend_parse_parameters(ZEND_NUM_ARGS(), "a", &edges_arg) == FAILURE){ - zend_throw_exception_ex( - zend_ce_exception, - 0, - "Unable to parse edges in dlib_chinese_whispers"); + if(zend_parse_parameters_throw(ZEND_NUM_ARGS(), "a", &edges_arg) == FAILURE){ return; } diff --git a/src/chinese_whispers.h b/src/chinese_whispers.h index ec38e62..784b1c9 100644 --- a/src/chinese_whispers.h +++ b/src/chinese_whispers.h @@ -6,7 +6,7 @@ #define PHP_DLIB_CHINESE_WHISPERS_H ZEND_BEGIN_ARG_INFO_EX(dlib_chinese_whispers_arginfo, 0, 0, 1) - ZEND_ARG_INFO(0, edges) + ZEND_ARG_ARRAY_INFO(0, edges, 0) ZEND_END_ARG_INFO() PHP_FUNCTION(dlib_chinese_whispers); diff --git a/src/cnn_face_detection.cc b/src/cnn_face_detection.cc index 458be81..602e5c9 100644 --- a/src/cnn_face_detection.cc +++ b/src/cnn_face_detection.cc @@ -29,9 +29,8 @@ PHP_METHOD(CnnFaceDetection, __construct) return; } - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "p", &sz_cnn_face_detection_model_path, &cnn_face_detection_model_path_len) == FAILURE){ - zend_throw_exception_ex(zend_ce_exception, 0, "Unable to parse face_detection_model_path"); return; } @@ -53,8 +52,7 @@ PHP_METHOD(CnnFaceDetection, detect) size_t img_path_len; long upsample_num = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &img_path, &img_path_len, &upsample_num) == FAILURE){ - zend_throw_exception_ex(zend_ce_exception, 0, "Unable to parse detect arguments"); + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "p|l", &img_path, &img_path_len, &upsample_num) == FAILURE){ RETURN_FALSE; } diff --git a/src/cnn_face_detection.h b/src/cnn_face_detection.h index 1a604a8..e8ea8fa 100644 --- a/src/cnn_face_detection.h +++ b/src/cnn_face_detection.h @@ -23,13 +23,17 @@ typedef struct _cnn_face_detection { } cnn_face_detection; ZEND_BEGIN_ARG_INFO_EX(cnn_face_detection_ctor_arginfo, 0, 0, 1) - ZEND_ARG_INFO(0, cnn_face_detection_model_path) + ZEND_ARG_TYPE_INFO(0, cnn_face_detection_model_path, IS_STRING, 0) ZEND_END_ARG_INFO() PHP_METHOD(CnnFaceDetection, __construct); -ZEND_BEGIN_ARG_INFO_EX(cnn_face_detection_detect_arginfo, 0, 0, 2) - ZEND_ARG_INFO(0, img_path) - ZEND_ARG_INFO(0, upsample_num) +ZEND_BEGIN_ARG_INFO_EX(cnn_face_detection_detect_arginfo, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, img_path, IS_STRING, 0) +#if PHP_VERSION_ID < 80000 + ZEND_ARG_TYPE_INFO(0, upsample_num, IS_LONG, 0) +#else + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, upsample_num, IS_LONG, 0, "0") +#endif ZEND_END_ARG_INFO() PHP_METHOD(CnnFaceDetection, detect); diff --git a/src/face_detection.cc b/src/face_detection.cc index d7ae923..01239b5 100644 --- a/src/face_detection.cc +++ b/src/face_detection.cc @@ -17,8 +17,7 @@ PHP_FUNCTION(dlib_face_detection) size_t img_path_len; long upsample_num = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &img_path, &img_path_len, &upsample_num) == FAILURE) { - zend_throw_exception_ex(zend_ce_exception, 0, "Unable to parse dlib_face_detection arguments"); + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "p|l", &img_path, &img_path_len, &upsample_num) == FAILURE) { RETURN_FALSE; } try { diff --git a/src/face_detection.h b/src/face_detection.h index a95667e..b9ef226 100644 --- a/src/face_detection.h +++ b/src/face_detection.h @@ -6,8 +6,12 @@ #define PHP_DLIB_FACE_DETECTION_H ZEND_BEGIN_ARG_INFO_EX(dlib_face_detection_arginfo, 0, 0, 1) - ZEND_ARG_INFO(0, img_path) - ZEND_ARG_INFO(0, upsample_num) + ZEND_ARG_TYPE_INFO(0, img_path, IS_STRING, 0) +#if PHP_VERSION_ID < 80000 + ZEND_ARG_TYPE_INFO(0, upsample_num, IS_LONG, 0) +#else + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, upsample_num, IS_LONG, 0, "0") +#endif ZEND_END_ARG_INFO() PHP_FUNCTION(dlib_face_detection); diff --git a/src/face_landmark_detection.cc b/src/face_landmark_detection.cc index ebf1546..d36f7ff 100644 --- a/src/face_landmark_detection.cc +++ b/src/face_landmark_detection.cc @@ -27,7 +27,7 @@ PHP_FUNCTION(dlib_face_landmark_detection) char *img_path; size_t shape_predictor_file_path_len, img_path_len; - if(zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &shape_predictor_file_path, &shape_predictor_file_path_len, + if(zend_parse_parameters_throw(ZEND_NUM_ARGS(), "ss", &shape_predictor_file_path, &shape_predictor_file_path_len, &img_path, &img_path_len) == FAILURE){ RETURN_FALSE; } @@ -83,9 +83,8 @@ PHP_METHOD(FaceLandmarkDetection, __construct) } // Parse predictor model's path - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "p", &sz_shape_predictor_file_path, &shape_predictor_file_path_len) == FAILURE){ - zend_throw_exception_ex(zend_ce_exception, 0, "Unable to parse shape_predictor_file_path"); return; } @@ -114,8 +113,7 @@ PHP_METHOD(FaceLandmarkDetection, detect) // Parse path to image and bounding box. Bounding box is associative array of 4 elements - "top", "bottom", "left" and "right". // - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sa", &img_path, &img_path_len, &bounding_box) == FAILURE){ - zend_throw_exception_ex(zend_ce_exception, 0, "Unable to parse detect arguments"); + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "pa", &img_path, &img_path_len, &bounding_box) == FAILURE){ return; } diff --git a/src/face_landmark_detection.h b/src/face_landmark_detection.h index 873ba49..ac290a7 100644 --- a/src/face_landmark_detection.h +++ b/src/face_landmark_detection.h @@ -9,9 +9,9 @@ using namespace dlib; -ZEND_BEGIN_ARG_INFO_EX(dlib_face_landmark_detection_arginfo, 0, 0, 1) -ZEND_ARG_INFO(0, shape_predictor_file_path) -ZEND_ARG_INFO(0, img_path) +ZEND_BEGIN_ARG_INFO_EX(dlib_face_landmark_detection_arginfo, 0, 0, 2) + ZEND_ARG_TYPE_INFO(0, shape_predictor_file_path, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, img_path, IS_STRING, 0) ZEND_END_ARG_INFO() PHP_FUNCTION(dlib_face_landmark_detection); @@ -21,13 +21,13 @@ typedef struct _face_landmark_detection { } face_landmark_detection; ZEND_BEGIN_ARG_INFO_EX(face_landmark_detection_ctor_arginfo, 0, 0, 1) - ZEND_ARG_INFO(0, shape_predictor_file_path) + ZEND_ARG_TYPE_INFO(0, shape_predictor_file_path, IS_STRING, 0) ZEND_END_ARG_INFO() PHP_METHOD(FaceLandmarkDetection, __construct); ZEND_BEGIN_ARG_INFO_EX(face_landmark_detection_detect_arginfo, 0, 0, 2) - ZEND_ARG_INFO(0, img_path) - ZEND_ARG_INFO(0, bounding_box) + ZEND_ARG_TYPE_INFO(0, img_path, IS_STRING, 0) + ZEND_ARG_ARRAY_INFO(0, bounding_box, 0) ZEND_END_ARG_INFO() PHP_METHOD(FaceLandmarkDetection, detect); diff --git a/src/face_recognition.cc b/src/face_recognition.cc index 5cffabe..8ecdfae 100644 --- a/src/face_recognition.cc +++ b/src/face_recognition.cc @@ -26,9 +26,8 @@ PHP_METHOD(FaceRecognition, __construct) return; } - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "p", &sz_face_recognition_model_path, &face_recognition_model_path_len) == FAILURE){ - zend_throw_exception_ex(zend_ce_exception, 0, "Unable to parse face_recognition_model_path"); return; } @@ -73,8 +72,7 @@ PHP_METHOD(FaceRecognition, computeDescriptor) zval *shape; long num_jitters = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sa|l", &img_path, &img_path_len, &shape, &num_jitters) == FAILURE){ - zend_throw_exception_ex(zend_ce_exception, 0, "Unable to parse computeDescriptor arguments"); + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "pa|l", &img_path, &img_path_len, &shape, &num_jitters) == FAILURE){ return; } diff --git a/src/face_recognition.h b/src/face_recognition.h index 0939d41..e649747 100644 --- a/src/face_recognition.h +++ b/src/face_recognition.h @@ -44,14 +44,18 @@ typedef struct _face_recognition { } face_recognition; ZEND_BEGIN_ARG_INFO_EX(face_recognition_ctor_arginfo, 0, 0, 1) - ZEND_ARG_INFO(0, face_recognition_model_path) + ZEND_ARG_TYPE_INFO(0, face_recognition_model_path, IS_STRING, 0) ZEND_END_ARG_INFO() PHP_METHOD(FaceRecognition, __construct); -ZEND_BEGIN_ARG_INFO_EX(face_recognition_compute_descriptor_arginfo, 0, 0, 3) - ZEND_ARG_INFO(0, img_path) - ZEND_ARG_INFO(0, landmarks) - ZEND_ARG_INFO(0, num_jitters) +ZEND_BEGIN_ARG_INFO_EX(face_recognition_compute_descriptor_arginfo, 0, 0, 2) + ZEND_ARG_TYPE_INFO(0, img_path, IS_STRING, 0) + ZEND_ARG_ARRAY_INFO(0, landmarks, 0) +#if PHP_VERSION_ID < 80000 + ZEND_ARG_TYPE_INFO(0, num_jitters, IS_LONG, 0) +#else + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, num_jitters, IS_LONG, 0, "1") +#endif ZEND_END_ARG_INFO() PHP_METHOD(FaceRecognition, computeDescriptor); diff --git a/tests/chinese_whispers_wrong_arg_type_error.phpt b/tests/chinese_whispers_wrong_arg_type_error.phpt index 7c09765..822dea0 100644 --- a/tests/chinese_whispers_wrong_arg_type_error.phpt +++ b/tests/chinese_whispers_wrong_arg_type_error.phpt @@ -6,10 +6,9 @@ Args given to chinese_whispers functions is not correct getMessage()); } ?> --EXPECTF-- -Warning: dlib_chinese_whispers() expects parameter 1 to be array, string given in %s on line 3 -string(46) "Unable to parse edges in dlib_chinese_whispers" +string(%d) "%s type array, string given" diff --git a/tests/cnn_face_detection_ctor_error.phpt b/tests/cnn_face_detection_ctor_error.phpt index 528342f..3535448 100644 --- a/tests/cnn_face_detection_ctor_error.phpt +++ b/tests/cnn_face_detection_ctor_error.phpt @@ -6,10 +6,10 @@ Testing CnnFaceDetection constructor without arguments getMessage()); } ?> --EXPECTF-- -Warning: CnnFaceDetection::__construct() expects exactly 1 parameter, 0 given in %s on line 3 -string(41) "Unable to parse face_detection_model_path" +string(68) "CnnFaceDetection::__construct() expects exactly 1 parameter, 0 given" + diff --git a/tests/face_landmark_detection_ctor_error.phpt b/tests/face_landmark_detection_ctor_error.phpt index 9da5418..2a717db 100644 --- a/tests/face_landmark_detection_ctor_error.phpt +++ b/tests/face_landmark_detection_ctor_error.phpt @@ -6,7 +6,7 @@ Testing FaceLandmarkDetection constructor without arguments getMessage()); } try { @@ -16,6 +16,5 @@ try { } ?> --EXPECTF-- -Warning: FaceLandmarkDetection::__construct() expects exactly 1 parameter, 0 given in %s on line 3 -string(41) "Unable to parse shape_predictor_file_path" +string(73) "FaceLandmarkDetection::__construct() expects exactly 1 parameter, 0 given" string(45) "Unable to open non-existent file for reading." diff --git a/tests/face_recognition_ctor_error.phpt b/tests/face_recognition_ctor_error.phpt index 70a7749..c06ed39 100644 --- a/tests/face_recognition_ctor_error.phpt +++ b/tests/face_recognition_ctor_error.phpt @@ -6,10 +6,9 @@ Testing FaceRecognition constructor without arguments getMessage()); } ?> --EXPECTF-- -Warning: FaceRecognition::__construct() expects exactly 1 parameter, 0 given in %s on line 3 -string(43) "Unable to parse face_recognition_model_path" +string(67) "FaceRecognition::__construct() expects exactly 1 parameter, 0 given"