Giter Site home page Giter Site logo

Comments (2)

avengerx avatar avengerx commented on August 16, 2024 3

Hello! I'm too lazy to create a pull request so I release my fix in open domain here:

diff --git a/protobuf.c b/protobuf.c
index 0bf18b5..21a8deb 100644
--- a/protobuf.c
+++ b/protobuf.c
@@ -58,7 +58,7 @@ enum

 zend_class_entry *pb_entry;

-static int pb_assign_value(zval *this, zval *dst, zval *src, uint32_t field_number);
+static int pb_assign_value(zval *this, zval *dst, zval *src, uint32_t field_number TSRMLS_DC);
 static int pb_print_field_value(zval **value, long level, zend_bool only_set);
 static int pb_dump_field_value(zval **value, long level, zend_bool only_set);
 static int pb_print_debug_field_value(zval **value, long level);
@@ -70,9 +70,9 @@ static int pb_get_wire_type(int field_type);
 static const char *pb_get_wire_type_name(int wire_type);
 static zval **pb_get_value(zval *this, zval **values, uint32_t field_number);
 static zval **pb_get_values(zval *this);
-static int pb_parse_field_value(zval *this, reader_t *reader, long field_number, long field_type, zval *value);
+static int pb_parse_field_value(zval *this, reader_t *reader, long field_number, long field_type, zval *value TSRMLS_DC);
 static int pb_serialize_field_value(zval *this, writer_t *writer, uint32_t field_number, zval **type, zval **value);
-static int pb_serialize_packed_field(zval *this, writer_t *writer, long field_number, long field_type, zval *values);
+static int pb_serialize_packed_field(zval *this, writer_t *writer, long field_number, long field_type, zval *values TSRMLS_DC);

 static ulong PB_FIELD_TYPE_HASH;
 static ulong PB_VALUES_PROPERTY_HASH;
@@ -106,7 +106,7 @@ PHP_METHOD(ProtobufMessage, append)
                RETURN_THIS();

        MAKE_STD_ZVAL(val);
-       if (pb_assign_value(getThis(), val, value, field_number) != 0) {
+       if (pb_assign_value(getThis(), val, value, field_number TSRMLS_CC) != 0) {
                zval_ptr_dtor(&val);
                RETURN_THIS();
        }
@@ -462,7 +462,7 @@ PHP_METHOD(ProtobufMessage, parseFromString)
                                                ALLOC_INIT_ZVAL(value);
                                                add_next_index_zval(*old_value, value);
                                        }
-                                       if (pb_parse_field_value(getThis(), &packed_reader, field_number, Z_LVAL_PP(field_type), value) != 0) {
+                                       if (pb_parse_field_value(getThis(), &packed_reader, field_number, Z_LVAL_PP(field_type), value TSRMLS_CC) != 0) {
                                                return;
                                        }
                                        value = NULL;
@@ -473,7 +473,7 @@ PHP_METHOD(ProtobufMessage, parseFromString)
                                        return;
                                }

-                               if (pb_parse_field_value(getThis(), &reader, field_number, Z_LVAL_PP(field_type), value) != 0) {
+                               if (pb_parse_field_value(getThis(), &reader, field_number, Z_LVAL_PP(field_type), value TSRMLS_CC) != 0) {
                                        return;
                                }
                        }
@@ -532,7 +532,7 @@ PHP_METHOD(ProtobufMessage, serializeToString)
                        array = value;

                        if (zend_hash_find(Z_ARRVAL_PP(field_descriptor), PB_FIELD_PACKED, sizeof(PB_FIELD_PACKED), (void **) &packed) != FAILURE && Z_BVAL_PP(packed)) {
-                               if (pb_serialize_packed_field(getThis(), &writer, field_number, Z_LVAL_PP(type), *array) != 0)
+                               if (pb_serialize_packed_field(getThis(), &writer, field_number, Z_LVAL_PP(type), *array TSRMLS_CC) != 0)
                                        goto fail;
                        } else {
                                PB_FOREACH(&j, Z_ARRVAL_PP(array)) {
@@ -577,7 +577,7 @@ PHP_METHOD(ProtobufMessage, set)
                }
        } else {
                zval_dtor(*old_value);
-               pb_assign_value(getThis(), *old_value, value, field_number);
+               pb_assign_value(getThis(), *old_value, value, field_number TSRMLS_CC);
        }

        RETURN_THIS();
@@ -685,10 +685,9 @@ zend_module_entry protobuf_module_entry = {
 ZEND_GET_MODULE(protobuf)
 #endif

-static int pb_assign_value(zval *this, zval *dst, zval *src, uint32_t field_number)
+static int pb_assign_value(zval *this, zval *dst, zval *src, uint32_t field_number TSRMLS_DC)
 {
        zval **field_descriptor, *field_descriptors, tmp, **type;
-       TSRMLS_FETCH();

        if ((field_descriptors = pb_get_field_descriptors(this)) == NULL)
                goto fail0;
@@ -988,7 +987,7 @@ static zval **pb_get_values(zval *this)
        return values;
 }

-static int pb_parse_field_value(zval *this, reader_t *reader, long field_number, long field_type, zval *value)
+static int pb_parse_field_value(zval *this, reader_t *reader, long field_number, long field_type, zval *value TSRMLS_DC)
 {
        int ret, str_size;
        char *str;
@@ -1115,7 +1114,7 @@ static int pb_serialize_field_value(zval *this, writer_t *writer, uint32_t field
        return 0;
 }

-static int pb_serialize_packed_field(zval *this, writer_t *writer, long field_number, long field_type, zval *values)
+static int pb_serialize_packed_field(zval *this, writer_t *writer, long field_number, long field_type, zval *values TSRMLS_DC)
 {
        int ret = 0;

@@ -1152,4 +1151,4 @@ static int pb_serialize_packed_field(zval *this, writer_t *writer, long field_nu
        }

        return ret;
-}
\ No newline at end of file
+}

Point is: to support ZTS you have to add to related functions:

  • to function prototypes: TSRMLS_DC (or TSRMLS_D if you don't want it to pretend a comma to the function's argument
  • to function calls: TSRMLS_CC (or TSRMLS_C likewise)

There's also a #ifdef ZTS thing that I didn't really try to fiddle with. The changes above were enough to build the package pragmatically and I'll see what happens when running the lib. :B

This blog post helped me understand an actual application of the ZTS rules to an extension: STILL TRYING TO GET IT ALL OUT - What the heck is TSRMLS_CC, anyway? from -- what? -- 2006. :)

I'd better leave this open until someone merges the changes to the code, right? :)

from php-protobuf.

avengerx avatar avengerx commented on August 16, 2024

This seems to be the best documentation (linked from libgeos/geos#9) on how to handle this issue. But as I am not really experienced in building and developing PHP extensions, and I also not familiar to the php-protobuf source code, it might take a lot to me to figure out & fix where it hurts, but may be just easy for someone acquainted with the project. :)

Thread-Safe Resource Manager

from php-protobuf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.