The **const** modifier needs to be added to read-only parameters of all ZendAPI and PHPAPI functions
Nessuno ha ancora preso questa issue.
- Lingua principale
- C
- Stelle
- 40.4k
- Fork
- 8.1k
- Merge medio
- 2g 13h
- PR unite (30g)
- 96
Descrizione
Description
Many functions in the php source code receive the zval parameter. The value of the parameter is not modified in the function implementation. These parameters are read-only, but the const modifier is not added.
As a result, C/C++underlying developers do not know whether the function is a read-only operation or a write operation, and will pollute all downstream functions. If these PHPAPI or ZEND_API functions are used in a C++function, even if the function is designed to be read-only, the const modifier cannot be used, or only unsafe const_cast can be used to cast.
An example:
class Variant {
protected:
zval val;
void destroy() {
zval_ptr_dtor(&val);
}
public:
Variant(const zval *v) noexcept {
ZVAL_COPY_VALUE(&val, v);
}
const zval *const_ptr() const {
return &val;
}
// fast_equal_check_function should be `fast_equal_check_function(const zval *op1, const zval *op2)`
bool equals(const Variant &v) const {
return fast_equal_check_function(const_ptr(), v.const_ptr());
}
}
Problem function:
- fast_equal_check_function
- php_debug_zval_dump
- php_var_dump
- php_var_unserialize
- concat_function
- add_function
- is_equal_function
- zval_get_string
- zval_get_double // version 8.1
... a lot more functions
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia individuando le dichiarazioni e le implementazioni PHPAPI e ZEND_API di fast_equal_check_function, php_debug_zval_dump, php_var_dump, php_var_unserialize, concat_function, add_function, is_equal_function, zval_get_string e zval_get_double. Determina quali parametri zval non vengono modificati, quindi aggiorna in modo coerente le firme applicabili in tutte le funzioni interessate e verifica che il codice sorgente di PHP continui a compilare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- c
- Ambito
- compilers
- Tipo di issue
- Refactoring
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 35/100