You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.4 KiB

  1. From b69e1067f70ef293587b72979193e68b01d90902 Mon Sep 17 00:00:00 2001
  2. From: Michael Heimpold <mhei@heimpold.de>
  3. Date: Wed, 13 Jul 2016 00:23:29 +0200
  4. Subject: [PATCH 06/16] Replace ZEND_FETCH_RESOURCE macro with
  5. zend_fetch_resource
  6. Signed-off-by: Michael Heimpold <mhei@heimpold.de>
  7. ---
  8. dio.c | 36 +++++++++++++++++++++++++++---------
  9. 1 file changed, 27 insertions(+), 9 deletions(-)
  10. diff --git a/dio.c b/dio.c
  11. index 408a171..6b687ac 100644
  12. --- a/dio.c
  13. +++ b/dio.c
  14. @@ -161,7 +161,9 @@ PHP_FUNCTION(dio_dup)
  15. return;
  16. }
  17. - ZEND_FETCH_RESOURCE(f, php_fd_t *, &r_fd, -1, le_fd_name, le_fd);
  18. + if ((f = (php_fd_t *)zend_fetch_resource(Z_RES_P(r_fd), le_fd_name, le_fd)) == NULL) {
  19. + RETURN_FALSE;
  20. + }
  21. dfd = dup(f->fd);
  22. if (dfd == -1) {
  23. @@ -192,7 +194,9 @@ PHP_FUNCTION(dio_read)
  24. return;
  25. }
  26. - ZEND_FETCH_RESOURCE(f, php_fd_t *, &r_fd, -1, le_fd_name, le_fd);
  27. + if ((f = (php_fd_t *)zend_fetch_resource(Z_RES_P(r_fd), le_fd_name, le_fd)) == NULL) {
  28. + RETURN_FALSE;
  29. + }
  30. if (bytes <= 0) {
  31. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0.");
  32. @@ -233,7 +237,9 @@ PHP_FUNCTION(dio_write)
  33. RETURN_FALSE;
  34. }
  35. - ZEND_FETCH_RESOURCE(f, php_fd_t *, &r_fd, -1, le_fd_name, le_fd);
  36. + if ((f = (php_fd_t *)zend_fetch_resource(Z_RES_P(r_fd), le_fd_name, le_fd)) == NULL) {
  37. + RETURN_FALSE;
  38. + }
  39. res = write(f->fd, data, trunc_len ? trunc_len : data_len);
  40. if (res == -1) {
  41. @@ -258,7 +264,9 @@ PHP_FUNCTION(dio_truncate)
  42. return;
  43. }
  44. - ZEND_FETCH_RESOURCE(f, php_fd_t *, &r_fd, -1, le_fd_name, le_fd);
  45. + if ((f = (php_fd_t *)zend_fetch_resource(Z_RES_P(r_fd), le_fd_name, le_fd)) == NULL) {
  46. + RETURN_FALSE;
  47. + }
  48. if (ftruncate(f->fd, offset) == -1) {
  49. php_error_docref(NULL TSRMLS_CC, E_WARNING, "couldn't truncate %d to %ld bytes: %s", f->fd, offset, strerror(errno));
  50. @@ -284,7 +292,9 @@ PHP_FUNCTION(dio_stat)
  51. return;
  52. }
  53. - ZEND_FETCH_RESOURCE(f, php_fd_t *, &r_fd, -1, le_fd_name, le_fd);
  54. + if ((f = (php_fd_t *)zend_fetch_resource(Z_RES_P(r_fd), le_fd_name, le_fd)) == NULL) {
  55. + RETURN_FALSE;
  56. + }
  57. if (fstat(f->fd, &s) == -1) {
  58. php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot stat %d: %s", f->fd, strerror(errno));
  59. @@ -323,7 +333,9 @@ PHP_FUNCTION(dio_seek)
  60. return;
  61. }
  62. - ZEND_FETCH_RESOURCE(f, php_fd_t *, &r_fd, -1, le_fd_name, le_fd);
  63. + if ((f = (php_fd_t *)zend_fetch_resource(Z_RES_P(r_fd), le_fd_name, le_fd)) == NULL) {
  64. + RETURN_FALSE;
  65. + }
  66. RETURN_LONG(lseek(f->fd, offset, whence));
  67. }
  68. @@ -344,7 +356,9 @@ PHP_FUNCTION(dio_fcntl)
  69. return;
  70. }
  71. - ZEND_FETCH_RESOURCE(f, php_fd_t *, &r_fd, -1, le_fd_name, le_fd);
  72. + if ((f = (php_fd_t *)zend_fetch_resource(Z_RES_P(r_fd), le_fd_name, le_fd)) == NULL) {
  73. + RETURN_FALSE;
  74. + }
  75. switch (cmd) {
  76. case F_SETLK:
  77. @@ -454,7 +468,9 @@ PHP_FUNCTION(dio_tcsetattr)
  78. return;
  79. }
  80. - ZEND_FETCH_RESOURCE(f, php_fd_t *, &r_fd, -1, le_fd_name, le_fd);
  81. + if ((f = (php_fd_t *)zend_fetch_resource(Z_RES_P(r_fd), le_fd_name, le_fd)) == NULL) {
  82. + RETURN_FALSE;
  83. + }
  84. if (Z_TYPE_P(arg) != IS_ARRAY) {
  85. php_error_docref(NULL TSRMLS_CC, E_WARNING,"tcsetattr, third argument should be an associative array");
  86. @@ -639,7 +655,9 @@ PHP_FUNCTION(dio_close)
  87. return;
  88. }
  89. - ZEND_FETCH_RESOURCE(f, php_fd_t *, &r_fd, -1, le_fd_name, le_fd);
  90. + if ((f = (php_fd_t *)zend_fetch_resource(Z_RES_P(r_fd), le_fd_name, le_fd)) == NULL) {
  91. + RETURN_FALSE;
  92. + }
  93. zend_list_delete(Z_LVAL_P(r_fd));
  94. }
  95. --
  96. 2.5.0