Guest User

Untitled

a guest
Apr 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. Index: php_spl.c
  2. ===================================================================
  3. --- php_spl.c (revision 290576)
  4. +++ php_spl.c (working copy)
  5. @@ -359,6 +359,97 @@
  6. }
  7. }
  8.  
  9. +
  10. +/* {{{ spl_strrpos_ascii: borrowed from the php ext/standard/string.c */
  11. +int32_t spl_strrpos_ascii(unsigned char *haystack, int32_t haystack_len, unsigned char *needle, int32_t needle_len, int32_t offset)
  12. +{
  13. + unsigned char *p, *e;
  14. +
  15. + if (offset >= 0) {
  16. + p = haystack + offset;
  17. + e = haystack + haystack_len - needle_len;
  18. + } else {
  19. + p = haystack;
  20. + if (needle_len > -offset) {
  21. + e = haystack + haystack_len - needle_len;
  22. + } else {
  23. + e = haystack + haystack_len + offset;
  24. + }
  25. + }
  26. +
  27. + if (needle_len == 1) {
  28. + /* Single character search can shortcut memcmps */
  29. + while (e >= p) {
  30. + if (*e == *needle) {
  31. + return (e - p + (offset > 0 ? offset : 0));
  32. + }
  33. + e--;
  34. + }
  35. + return -1;
  36. + }
  37. +
  38. + while (e >= p) {
  39. + if (memcmp(e, needle, needle_len) == 0) {
  40. + return (e - p + (offset > 0 ? offset : 0));
  41. + }
  42. + e--;
  43. + }
  44. +
  45. + return -1;
  46. +} /* }}} */
  47. +
  48. +/* {{{ proto void spl_autoload_psr(string class_name) U
  49. + This is the method that is used to be load in the autoloader */
  50. +PHP_FUNCTION(spl_autoload_psr)
  51. +{
  52. + zval *class_name = NULL;
  53. + int class_name_len;
  54. +
  55. + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &class_name, &class_name_len) == FAILURE) {
  56. + return;
  57. + }
  58. +
  59. +
  60. + // Let's set the common items we'll be using
  61. + zval *namespace = NULL, *filename = NULL;
  62. +
  63. + // Process the string stuff first
  64. + if (Z_TYPE_P(class_name) == IS_STRING) {
  65. + Z_TYPE_P(return_value) = IS_STRING;
  66. +
  67. + if (strstr(Z_STRVAL_P(class_name), "\\\\") != NULL) {
  68. + MAKE_STD_ZVAL(namespace);
  69. + MAKE_STD_ZVAL(filename);
  70. +
  71. + int32_t class_pos;
  72. +
  73. + unsigned char *needle = "\\\\";
  74. + int32_t needle_len = 4;
  75. +
  76. + class_pos = spl_strrpos_ascii((unsigned char *)class_name.str.val, (int32_t)class_name.str.len, needle, needle_len, 0);
  77. +
  78. + // $namespace = substr($classname, 0, strrpos($classname, '\\'));
  79. + Z_STRVAL_P(namespace) = strndup(Z_STRVAL_P(class_name), class_pos);
  80. +
  81. + // $classname = substr($classname, strrpos($classname, '\\') + 1);
  82. + // Something is wrong here as well....
  83. + Z_STRVAL_P(class_name) = strndup(Z_STRVAL_P(class_name), class_pos + 1);
  84. +
  85. + // $filename = str_replace('\\', '/', $namespace) . '/';
  86. + // Am I missing some \0 there? I can't find an internal strncpy
  87. + Z_STRVAL_P(filename) = sprintf("%s%s", strncpy("\\\\", "/", Z_STRVAL_P(namespace)), "/");
  88. +
  89. + MAKE_STD_ZVAL(return_value);
  90. + *return_value = filename;
  91. +
  92. + zval_dtor(filename);
  93. + zval_dtor(classname);
  94. + zval_dtor(class_name);
  95. + }
  96. + }
  97. + // I'll care about unicode later when this compiles. Z_TYPE_P(class_name) == IS_UNICODE.
  98. +} /* }}} */
  99. +
  100. /* {{{ proto void spl_autoload_call(string class_name) U
  101. Try all registerd autoload function to load the requested class */
  102. PHP_FUNCTION(spl_autoload_call)
  103. @@ -870,6 +961,11 @@
  104. ZEND_ARG_INFO(0, class_name)
  105. ZEND_END_ARG_INFO()
  106.  
  107. +
  108. +ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload_psr, 0, 0, 0)
  109. + ZEND_ARG_INFO(0, class_name)
  110. +ZEND_END_ARG_INFO()
  111. +
  112. ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload_register, 0, 0, 0)
  113. ZEND_ARG_INFO(0, autoload_function)
  114. ZEND_END_ARG_INFO()
  115. @@ -893,6 +989,7 @@
  116. PHP_FE(spl_autoload_unregister, arginfo_spl_autoload_unregister)
  117. PHP_FE(spl_autoload_functions, arginfo_spl_autoload_functions)
  118. PHP_FE(spl_autoload_call, arginfo_spl_autoload_call)
  119. + PHP_FE(spl_autoload_psr, arginfo_spl_autoload_psr)
  120. PHP_FE(class_parents, arginfo_class_parents)
  121. PHP_FE(class_implements, arginfo_class_implements)
  122. PHP_FE(spl_object_hash, arginfo_spl_object_hash)
Add Comment
Please, Sign In to add comment