sqmk / pecl-jsmin

PHP PECL extension for JavaScript minification
Other
69 stars 21 forks source link

PHP 8 support #58

Open mokraemer opened 3 years ago

mokraemer commented 3 years ago

will this receive php8 support?

Current release does not compile with php 8:

In file included from php_jsmin.c:27:
jsmin.h:28:42: error: expected ';', ',' or ')' before 'TSRMLS_DC'
   28 | extern jsmin_obj* jsmin(char *javascript TSRMLS_DC);
      |                                          ^~~~~~~~~
jsmin.h:29:43: error: expected ';', ',' or ')' before 'TSRMLS_DC'
   29 | extern void free_jsmin_obj(jsmin_obj *jmo TSRMLS_DC);
      |                                           ^~~~~~~~~
php_jsmin.c: In function 'zif_jsmin':
php_jsmin.c:108:44: error: expected ')' before 'TSRMLS_CC'
  108 |  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z/", &javascript, &javascript_len, &ret_code) == FAILURE) {
      |                                            ^~~~~~~~~
Jan-E commented 3 years ago

TSRMLS_CC and TSRMLS_DC did not do anything anymore in PHP7 anyway, so they can be safely removed. Patch is easy:

diff --git a/jsmin.c b/jsmin.c
index 2744aef..773dc09 100644
--- a/jsmin.c
+++ b/jsmin.c
@@ -34,7 +34,7 @@ SOFTWARE.
 */

 static jsmin_obj*
-new_jsmin_obj(char *javascript TSRMLS_DC)
+new_jsmin_obj(char *javascript)
 {
    jsmin_obj *jmo  = ecalloc(1, sizeof(jsmin_obj));
    jmo->javascript = javascript;
@@ -48,7 +48,7 @@ new_jsmin_obj(char *javascript TSRMLS_DC)
 /* free_jsmin_obj -- frees up memory on struct
 */
 void
-free_jsmin_obj(jsmin_obj *jmo TSRMLS_DC)
+free_jsmin_obj(jsmin_obj *jmo)
 {
    smart_string_free(&jmo->buffer);
    efree(jmo);
@@ -250,9 +250,9 @@ jsmin_action(int d, jsmin_obj *jmo)
 */

 jsmin_obj*
-jsmin(char *javascript TSRMLS_DC)
+jsmin(char *javascript)
 {
-   jsmin_obj *jmo = new_jsmin_obj(javascript TSRMLS_CC);
+   jsmin_obj *jmo = new_jsmin_obj(javascript);

    jsmin_action(3, jmo);
    while (jmo->theA != 0) {
diff --git a/jsmin.h b/jsmin.h
index 317b90b..0bda630 100644
--- a/jsmin.h
+++ b/jsmin.h
@@ -25,7 +25,7 @@ enum error_codes {
   PHP_JSMIN_ERROR_UNTERMINATED_REGEX
 };

-extern jsmin_obj* jsmin(char *javascript TSRMLS_DC);
-extern void free_jsmin_obj(jsmin_obj *jmo TSRMLS_DC);
+extern jsmin_obj* jsmin(char *javascript);
+extern void free_jsmin_obj(jsmin_obj *jmo);

 #endif
diff --git a/php_jsmin.c b/php_jsmin.c
index a9783d4..6cc034a 100644
--- a/php_jsmin.c
+++ b/php_jsmin.c
@@ -105,11 +105,11 @@ PHP_FUNCTION(jsmin)

    zval *ret_code = NULL;

-   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z/", &javascript, &javascript_len, &ret_code) == FAILURE) {
+   if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|z/", &javascript, &javascript_len, &ret_code) == FAILURE) {
        RETURN_FALSE;
    }

-   jmo = jsmin(javascript TSRMLS_CC);
+   jmo = jsmin(javascript);
    if (ret_code) {
        zval_dtor(ret_code);
        ZVAL_LONG(ret_code, jmo->errorCode);
@@ -121,7 +121,7 @@ PHP_FUNCTION(jsmin)
    } else {
        ZVAL_STRINGL(return_value, jmo->buffer.c, jmo->buffer.len);
    }
-   free_jsmin_obj(jmo TSRMLS_CC);
+   free_jsmin_obj(jmo);
 }
 /* }}} */
Radcliffe commented 3 years ago

This worked for me. Could this be made into a pull request?

ranqiangjun commented 3 years ago

Requested a PR based on @Jan-E's comment

andypost commented 3 years ago

Packaged it for Alpinelinux, would be great to package jquery into PECL release or skip it like https://github.com/sqmk/pecl-jsmin/pull/60

Awaiting 4.0.0 release!

socialnicheguru commented 2 years ago

I am using php7.4.30 as my php version. I do have php8.1 installed but it is not currently used. I am seeing the same issues as above https://github.com/sqmk/pecl-jsmin/issues/62

shrimpPaste commented 1 year ago

Sorry,How Can I Use Them? Just Run Or Install some plug?