Merge pull request #29 from remicollet/issue-build

Fix build and PHP 8 compat.
This commit is contained in:
goodspb
2020-07-05 22:52:46 +08:00
committed by GitHub
17 changed files with 87 additions and 123 deletions

View File

@@ -18,8 +18,6 @@ dnl Make sure that the comment is aligned:
[ --with-pdlib Include pdlib support])
if test "$PHP_PDLIB" != "no"; then
dnl using C++11
CXXFLAGS="-std=c++11"
PHP_REQUIRE_CXX()
PHP_ADD_LIBRARY(stdc++, 1, PDLIB_SHARED_LIBADD)
PHP_SUBST(PDLIB_SHARED_LIBADD)
@@ -49,5 +47,6 @@ if test "$PHP_PDLIB" != "no"; then
PHP_EVAL_LIBLINE($LIBDLIB_LIBDIR, PDLIB_SHARED_LIBADD)
PHP_EVAL_INCLINE($LIBDLIB_CFLAGS)
PHP_NEW_EXTENSION(pdlib, $pdlib_src_files, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1, cxx)
dnl using C++11
PHP_NEW_EXTENSION(pdlib, $pdlib_src_files, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -std=c++11, cxx)
fi

View File

@@ -39,9 +39,6 @@ extern "C" {
ZEND_DECLARE_MODULE_GLOBALS(pdlib)
*/
/* True global resources - no need for thread safety here */
static int le_pdlib;
static zend_class_entry *cnn_face_detection_ce = nullptr;
static zend_object_handlers cnn_face_detection_obj_handlers;
@@ -61,34 +58,6 @@ PHP_INI_END()
*/
/* }}} */
/* Remove the following function when you have successfully modified config.m4
so that your module can be compiled into PHP, it exists only for testing
purposes. */
/* Every user-visible function in PHP should document itself in the source */
/* {{{ proto string confirm_pdlib_compiled(string arg)
Return a string to confirm that the module is compiled in */
PHP_FUNCTION(confirm_pdlib_compiled)
{
char *arg = NULL;
size_t arg_len, len;
zend_string *strg;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE) {
return;
}
strg = strpprintf(0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "pdlib", arg);
RETURN_STR(strg);
}
/* }}} */
/* The previous line is meant for vim and emacs, so it can correctly fold and
unfold functions in source code. See the corresponding marks just before
function definition, where the functions purpose is also documented. Please
follow this convention for the convenience of others editing your code.
*/
/* {{{ php_pdlib_init_globals
*/
@@ -107,10 +76,10 @@ const zend_function_entry cnn_face_detection_class_methods[] = {
PHP_FE_END
};
zend_object* php_cnn_face_detection_new(zend_class_entry *class_type TSRMLS_DC)
zend_object* php_cnn_face_detection_new(zend_class_entry *class_type)
{
cnn_face_detection *cfd = (cnn_face_detection*)ecalloc(1, sizeof(cnn_face_detection));
zend_object_std_init(&cfd->std, class_type TSRMLS_CC);
zend_object_std_init(&cfd->std, class_type);
object_properties_init(&cfd->std, class_type);
cfd->std.handlers = &cnn_face_detection_obj_handlers; //zend_get_std_object_handlers();
@@ -130,10 +99,10 @@ const zend_function_entry face_landmark_detection_class_methods[] = {
PHP_FE_END
};
zend_object* php_face_landmark_detection_new(zend_class_entry *class_type TSRMLS_DC)
zend_object* php_face_landmark_detection_new(zend_class_entry *class_type)
{
face_landmark_detection *fld = (face_landmark_detection*)ecalloc(1, sizeof(face_landmark_detection));
zend_object_std_init(&fld->std, class_type TSRMLS_CC);
zend_object_std_init(&fld->std, class_type);
object_properties_init(&fld->std, class_type);
fld->std.handlers = &face_landmark_detection_obj_handlers;
@@ -153,10 +122,10 @@ const zend_function_entry face_recognition_class_methods[] = {
PHP_FE_END
};
zend_object* php_face_recognition_new(zend_class_entry *class_type TSRMLS_DC)
zend_object* php_face_recognition_new(zend_class_entry *class_type)
{
face_recognition *fr = (face_recognition*)ecalloc(1, sizeof(face_recognition));
zend_object_std_init(&fr->std, class_type TSRMLS_CC);
zend_object_std_init(&fr->std, class_type);
object_properties_init(&fr->std, class_type);
fr->std.handlers = &face_recognition_obj_handlers;
@@ -178,7 +147,7 @@ PHP_MINIT_FUNCTION(pdlib)
// CnnFaceDetection class definition
//
INIT_CLASS_ENTRY(ce, "CnnFaceDetection", cnn_face_detection_class_methods);
cnn_face_detection_ce = zend_register_internal_class(&ce TSRMLS_CC);
cnn_face_detection_ce = zend_register_internal_class(&ce);
cnn_face_detection_ce->create_object = php_cnn_face_detection_new;
memcpy(&cnn_face_detection_obj_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
cnn_face_detection_obj_handlers.offset = XtOffsetOf(cnn_face_detection, std);
@@ -187,7 +156,7 @@ PHP_MINIT_FUNCTION(pdlib)
// FaceLandmarkDetection class definition
//
INIT_CLASS_ENTRY(ce, "FaceLandmarkDetection", face_landmark_detection_class_methods);
face_landmark_detection_ce = zend_register_internal_class(&ce TSRMLS_CC);
face_landmark_detection_ce = zend_register_internal_class(&ce);
face_landmark_detection_ce->create_object = php_face_landmark_detection_new;
memcpy(&face_landmark_detection_obj_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
face_landmark_detection_obj_handlers.offset = XtOffsetOf(face_landmark_detection, std);
@@ -196,7 +165,7 @@ PHP_MINIT_FUNCTION(pdlib)
// FaceRecognition class definition
//
INIT_CLASS_ENTRY(ce, "FaceRecognition", face_recognition_class_methods);
face_recognition_ce = zend_register_internal_class(&ce TSRMLS_CC);
face_recognition_ce = zend_register_internal_class(&ce);
face_recognition_ce->create_object = php_face_recognition_new;
memcpy(&face_recognition_obj_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
face_recognition_obj_handlers.offset = XtOffsetOf(face_recognition, std);
@@ -266,7 +235,6 @@ PHP_MINFO_FUNCTION(pdlib)
* Every user visible function must have an entry in pdlib_functions[].
*/
const zend_function_entry pdlib_functions[] = {
PHP_FE(confirm_pdlib_compiled, NULL)
PHP_FE(dlib_chinese_whispers, dlib_chinese_whispers_arginfo)
PHP_FE(dlib_face_detection, dlib_face_detection_arginfo)
PHP_FE(dlib_face_landmark_detection, dlib_face_landmark_detection_arginfo)

View File

@@ -66,13 +66,13 @@ ZEND_TSRMLS_CACHE_EXTERN()
/* Tries to find given key in array */ \
data##key = zend_hash_str_find(hashtable, #key, sizeof(#key)-1); \
if (data##key == nullptr) { \
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, #error_key_missing); \
zend_throw_exception_ex(zend_ce_exception, 0, #error_key_missing); \
return; \
} \
\
/* We also need to check proper type of value in associative array */ \
if (Z_TYPE_P(data##key) != IS_LONG) { \
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, #error_key_not_long); \
zend_throw_exception_ex(zend_ce_exception, 0, #error_key_not_long); \
return; \
} \
zend_long key = Z_LVAL_P(data##key); \

View File

@@ -17,11 +17,7 @@ PHP_FUNCTION(dlib_chinese_whispers)
std::vector<sample_pair> edges;
std::vector<unsigned long> labels;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "a", &edges_arg) == FAILURE){
zend_throw_exception_ex(
zend_ce_exception,
0 TSRMLS_CC,
"Unable to parse edges in dlib_chinese_whispers");
if(zend_parse_parameters_throw(ZEND_NUM_ARGS(), "a", &edges_arg) == FAILURE){
return;
}
@@ -43,7 +39,7 @@ PHP_FUNCTION(dlib_chinese_whispers)
if (Z_TYPE_P(edge) != IS_ARRAY) {
zend_throw_exception_ex(
zend_ce_exception,
0 TSRMLS_CC,
0,
"Each edge provided in array needs to be numeric array of 2 elements");
return;
}
@@ -55,7 +51,7 @@ PHP_FUNCTION(dlib_chinese_whispers)
if (zend_hash_num_elements(edge_hash) != 2) {
zend_throw_exception_ex(
zend_ce_exception,
0 TSRMLS_CC,
0,
"Edges need to contain exactly two elements");
return;
}
@@ -66,7 +62,7 @@ PHP_FUNCTION(dlib_chinese_whispers)
!zend_hash_index_exists(edge_hash, 1)) {
zend_throw_exception_ex(
zend_ce_exception,
0 TSRMLS_CC,
0,
"Edge should be numeric array with integer keys");
return;
}
@@ -78,7 +74,7 @@ PHP_FUNCTION(dlib_chinese_whispers)
if ((Z_TYPE_P(elem_i) != IS_LONG) || (Z_TYPE_P(elem_j) != IS_LONG)) {
zend_throw_exception_ex(
zend_ce_exception,
0 TSRMLS_CC,
0,
"Both elements in each edge must be of long type");
return;
}
@@ -97,7 +93,7 @@ PHP_FUNCTION(dlib_chinese_whispers)
}
} catch (exception& e)
{
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what());
zend_throw_exception_ex(zend_ce_exception, 0, "%s", e.what());
return;
}
}

View File

@@ -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);

View File

@@ -25,13 +25,12 @@ PHP_METHOD(CnnFaceDetection, __construct)
cnn_face_detection *cfd = Z_CNN_FACE_DETECTION_P(getThis());
if (NULL == cfd) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unable to find obj in CnnFaceDetection::__construct()");
php_error_docref(NULL, E_ERROR, "Unable to find obj in 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 TSRMLS_CC, "Unable to parse face_detection_model_path");
return;
}
@@ -42,7 +41,7 @@ PHP_METHOD(CnnFaceDetection, __construct)
deserialize(cnn_face_detection_model_path) >> *pnet;
cfd->net = pnet;
} catch (exception& e) {
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what());
zend_throw_exception_ex(zend_ce_exception, 0, "%s", e.what());
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 TSRMLS_CC, "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;
}
@@ -77,7 +75,6 @@ PHP_METHOD(CnnFaceDetection, detect)
net_type *pnet = cfd->net;
auto dets = (*pnet)(img);
int rect_count = 0;
array_init(return_value);
// Scale the detection locations back to the original image size
@@ -101,7 +98,7 @@ PHP_METHOD(CnnFaceDetection, detect)
}
catch (exception& e)
{
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what());
zend_throw_exception_ex(zend_ce_exception, 0, "%s", e.what());
return;
}
}

View File

@@ -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);

View File

@@ -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 TSRMLS_CC, "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 {

View File

@@ -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);

View File

@@ -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;
}
@@ -52,7 +52,7 @@ PHP_FUNCTION(dlib_face_landmark_detection)
zval ARRAY_NAME_WITH_INDEX(face, j);
array_init(&ARRAY_NAME_WITH_INDEX(face, j));
for (int k = 0; k < shape.num_parts(); k++) {
for (unsigned int k = 0; k < shape.num_parts(); k++) {
zval ARRAY_NAME_WITH_INDEX(part, k);
array_init(&ARRAY_NAME_WITH_INDEX(part, k));
dlib::point p = shape.part(k);
@@ -78,14 +78,13 @@ PHP_METHOD(FaceLandmarkDetection, __construct)
face_landmark_detection *fld = Z_FACE_LANDMARK_DETECTION_P(getThis());
if (nullptr == fld) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unable to find obj in FaceLandmarkDetection::__construct()");
php_error_docref(NULL, E_ERROR, "Unable to find obj in FaceLandmarkDetection::__construct()");
return;
}
// 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 TSRMLS_CC, "Unable to parse shape_predictor_file_path");
return;
}
@@ -95,7 +94,7 @@ PHP_METHOD(FaceLandmarkDetection, __construct)
fld->sp = new shape_predictor;
deserialize(shape_predictor_file_path) >> *(fld->sp);
} catch (exception& e) {
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what());
zend_throw_exception_ex(zend_ce_exception, 0, "%s", e.what());
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 TSRMLS_CC, "Unable to parse detect arguments");
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "pa", &img_path, &img_path_len, &bounding_box) == FAILURE){
return;
}
@@ -123,7 +121,7 @@ PHP_METHOD(FaceLandmarkDetection, detect)
HashTable *bounding_box_hash = Z_ARRVAL_P(bounding_box);
uint32_t bounding_box_num_elements = zend_hash_num_elements(bounding_box_hash);
if (bounding_box_num_elements < 4) {
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Bounding box (second argument) needs to have at least 4 elements");
zend_throw_exception_ex(zend_ce_exception, 0, "Bounding box (second argument) needs to have at least 4 elements");
return;
}
@@ -151,7 +149,7 @@ PHP_METHOD(FaceLandmarkDetection, detect)
array_init(&rect_arr);
array_init(&parts_arr);
for (int i = 0; i < shape.num_parts(); i++) {
for (unsigned int i = 0; i < shape.num_parts(); i++) {
zval part;
array_init(&part);
dlib::point p = shape.part(i);
@@ -169,7 +167,7 @@ PHP_METHOD(FaceLandmarkDetection, detect)
add_assoc_zval(return_value, "rect", &rect_arr);
add_assoc_zval(return_value, "parts", &parts_arr);
} catch (exception& e) {
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what());
zend_throw_exception_ex(zend_ce_exception, 0, "%s", e.what());
return;
}
}

View File

@@ -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);

View File

@@ -22,13 +22,12 @@ PHP_METHOD(FaceRecognition, __construct)
face_recognition *fr = Z_FACE_RECOGNITION_P(getThis());
if (NULL == fr) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unable to find obj in FaceRecognition::__construct()");
php_error_docref(NULL, E_ERROR, "Unable to find obj in 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 TSRMLS_CC, "Unable to parse face_recognition_model_path");
return;
}
@@ -37,7 +36,7 @@ PHP_METHOD(FaceRecognition, __construct)
fr->net = new anet_type;
deserialize(face_recognition_model_path) >> *(fr->net);
} catch (exception& e) {
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what());
zend_throw_exception_ex(zend_ce_exception, 0, "%s", e.what());
return;
}
}
@@ -73,25 +72,24 @@ 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 TSRMLS_CC, "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;
}
HashTable *shape_hash = Z_ARRVAL_P(shape);
uint32_t shape_hash_num_elements = zend_hash_num_elements(shape_hash);
if (shape_hash_num_elements != 2) {
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Shape (second argument) needs to have exactly 2 elements - keys \"rect\" and \"parts\"");
zend_throw_exception_ex(zend_ce_exception, 0, "Shape (second argument) needs to have exactly 2 elements - keys \"rect\" and \"parts\"");
return;
}
zval *rect_zval = zend_hash_str_find(shape_hash, "rect", sizeof("rect")-1);
if (rect_zval == nullptr) {
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Shape (second argument) array needs to have \"rect\" key"); \
zend_throw_exception_ex(zend_ce_exception, 0, "Shape (second argument) array needs to have \"rect\" key"); \
return;
}
if (Z_TYPE_P(rect_zval) != IS_ARRAY) {
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Value of shape's key \"rect\" must be array");
zend_throw_exception_ex(zend_ce_exception, 0, "Value of shape's key \"rect\" must be array");
return;
}
HashTable *rect_hash = Z_ARRVAL_P(rect_zval);
@@ -104,11 +102,11 @@ PHP_METHOD(FaceRecognition, computeDescriptor)
zval *parts_zval = zend_hash_str_find(shape_hash, "parts", sizeof("parts")-1);
if (parts_zval == nullptr) {
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Shape (second argument) array needs to have \"parts\" key"); \
zend_throw_exception_ex(zend_ce_exception, 0, "Shape (second argument) array needs to have \"parts\" key"); \
return;
}
if (Z_TYPE_P(parts_zval) != IS_ARRAY) {
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Value of shape's key \"parts\" must be array");
zend_throw_exception_ex(zend_ce_exception, 0, "Value of shape's key \"parts\" must be array");
return;
}
HashTable *parts_hash = Z_ARRVAL_P(parts_zval);
@@ -117,7 +115,7 @@ PHP_METHOD(FaceRecognition, computeDescriptor)
point parts_points[parts_count];
if ((parts_count != 5) && (parts_count != 68)) {
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC,
zend_throw_exception_ex(zend_ce_exception, 0,
"The full_object_detection must use the iBUG 300W 68 point face landmark style or dlib's 5 point style");
return;
}
@@ -137,17 +135,17 @@ PHP_METHOD(FaceRecognition, computeDescriptor)
PARSE_POINT(x)
PARSE_POINT(y)
if (num_index > parts_count) {
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Internal error, bad parsing of parts array");
zend_throw_exception_ex(zend_ce_exception, 0, "Internal error, bad parsing of parts array");
return;
}
parts_points[num_index] = point(x, y);
} else {
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Values from parts array must be arrays with \"x\" and \"y\" keys");
zend_throw_exception_ex(zend_ce_exception, 0, "Values from parts array must be arrays with \"x\" and \"y\" keys");
return;
}
break;
case HASH_KEY_IS_STRING:
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Parts array must be indexed and it contains string keys");
zend_throw_exception_ex(zend_ce_exception, 0, "Parts array must be indexed and it contains string keys");
return;
break;
}
@@ -183,7 +181,7 @@ PHP_METHOD(FaceRecognition, computeDescriptor)
add_next_index_double(return_value, d);
}
} catch (exception& e) {
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what());
zend_throw_exception_ex(zend_ce_exception, 0, "%s", e.what());
return;
}
}

View File

@@ -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);

View File

@@ -6,10 +6,9 @@ Args given to chinese_whispers functions is not correct
<?php
try {
dlib_chinese_whispers("foo");
} catch (Exception $e) {
} catch (Error $e) {
var_dump($e->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"

View File

@@ -6,10 +6,10 @@ Testing CnnFaceDetection constructor without arguments
<?php
try {
new CnnFaceDetection();
} catch (Exception $e) {
} catch (Error $e) {
var_dump($e->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"

View File

@@ -6,7 +6,7 @@ Testing FaceLandmarkDetection constructor without arguments
<?php
try {
new FaceLandmarkDetection();
} catch (Exception $e) {
} catch (Error $e) {
var_dump($e->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."

View File

@@ -6,10 +6,9 @@ Testing FaceRecognition constructor without arguments
<?php
try {
new FaceRecognition();
} catch (Exception $e) {
} catch (Error $e) {
var_dump($e->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"