Giter Club home page Giter Club logo

Comments (4)

bwoebi avatar bwoebi commented on August 26, 2024

Yes, don't put non-interned persistent strings into non-persistent hashtables (array_init creates a non-persistent hashtable), it's not permitted.

Either intern the string (in minit) or allocate a non-persistent one.

from php-src.

TimWolla avatar TimWolla commented on August 26, 2024

it's not permitted.

Two questions:

  1. Should this then be verified during insertion?
  2. Why does this work for raw (non-array) HashTables then:
	HashTable array;
	zend_hash_init(&array, 0, NULL, ZVAL_PTR_DTOR, 0);

	zval value;
	ZVAL_LONG(&value, 1);

	zend_string *key = zend_string_init("foo", strlen("foo"), 1);
	zend_hash_update(&array, key, &value);
	zend_string_release(key);

	zend_hash_destroy(&array);

I also believe this is unnecessarily restrictive. Persistent strings should outlive the request-specific array, resulting in needless duplication when using them to index the array, no?

from php-src.

bwoebi avatar bwoebi commented on August 26, 2024

Okay, to be more precise: it's not permitted for arrays exposed as zvals to userland. The zend_array_destroy() API is used for pure runtime things.

You can do it for raw hashtables. But the goal of not permitting this is mostly so that you avoid accidentally exposing a refcounted persistent key to userland, which in threaded environments may lead to race conditions.
As long as you mutex these or keep the persistent string bound to a thread, it's fine.

from php-src.

TimWolla avatar TimWolla commented on August 26, 2024

Understood, thanks for the clarification.

from php-src.

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.