mirror of
https://github.com/php/php-src.git
synced 2024-09-22 02:17:32 +00:00
92ac598aab
This patch removes the so called local variables defined per file basis for certain editors to properly show tab width, and similar settings. These are mainly used by Vim and Emacs editors yet with recent changes the once working definitions don't work anymore in Vim without custom plugins or additional configuration. Neither are these settings synced across the PHP code base. A simpler and better approach is EditorConfig and fixing code using some code style fixing tools in the future instead. This patch also removes the so called modelines for Vim. Modelines allow Vim editor specifically to set some editor configuration such as syntax highlighting, indentation style and tab width to be set in the first line or the last 5 lines per file basis. Since the php test files have syntax highlighting already set in most editors properly and EditorConfig takes care of the indentation settings, this patch removes these as well for the Vim 6.0 and newer versions. With the removal of local variables for certain editors such as Emacs and Vim, the footer is also probably not needed anymore when creating extensions using ext_skel.php script. Additionally, Vim modelines for setting php syntax and some editor settings has been removed from some *.phpt files. All these are mostly not relevant for phpt files neither work properly in the middle of the file.
125 lines
3.0 KiB
C
125 lines
3.0 KiB
C
/*
|
|
+----------------------------------------------------------------------+
|
|
| PHP Version 7 |
|
|
+----------------------------------------------------------------------+
|
|
| Copyright (c) The PHP Group |
|
|
+----------------------------------------------------------------------+
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
| available through the world-wide-web at the following url: |
|
|
| http://www.php.net/license/3_01.txt |
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
+----------------------------------------------------------------------+
|
|
| Author: Sascha Schumann <sascha@schumann.cx> |
|
|
+----------------------------------------------------------------------+
|
|
*/
|
|
|
|
#include "php.h"
|
|
#include "php_lcg.h"
|
|
|
|
#if HAVE_UNISTD_H
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#ifdef PHP_WIN32
|
|
#include "win32/time.h"
|
|
#else
|
|
#include <sys/time.h>
|
|
#endif
|
|
|
|
#ifdef ZTS
|
|
int lcg_globals_id;
|
|
#else
|
|
static php_lcg_globals lcg_globals;
|
|
#endif
|
|
|
|
#ifdef PHP_WIN32
|
|
#include <process.h>
|
|
#endif
|
|
|
|
/*
|
|
* combinedLCG() returns a pseudo random number in the range of (0, 1).
|
|
* The function combines two CGs with periods of
|
|
* 2^31 - 85 and 2^31 - 249. The period of this function
|
|
* is equal to the product of both primes.
|
|
*/
|
|
|
|
#define MODMULT(a, b, c, m, s) q = s/a;s=b*(s-a*q)-c*q;if(s<0)s+=m
|
|
|
|
static void lcg_seed(void);
|
|
|
|
PHPAPI double php_combined_lcg(void) /* {{{ */
|
|
{
|
|
int32_t q;
|
|
int32_t z;
|
|
|
|
if (!LCG(seeded)) {
|
|
lcg_seed();
|
|
}
|
|
|
|
MODMULT(53668, 40014, 12211, 2147483563L, LCG(s1));
|
|
MODMULT(52774, 40692, 3791, 2147483399L, LCG(s2));
|
|
|
|
z = LCG(s1) - LCG(s2);
|
|
if (z < 1) {
|
|
z += 2147483562;
|
|
}
|
|
|
|
return z * 4.656613e-10;
|
|
}
|
|
/* }}} */
|
|
|
|
static void lcg_seed(void) /* {{{ */
|
|
{
|
|
struct timeval tv;
|
|
|
|
if (gettimeofday(&tv, NULL) == 0) {
|
|
LCG(s1) = tv.tv_sec ^ (tv.tv_usec<<11);
|
|
} else {
|
|
LCG(s1) = 1;
|
|
}
|
|
#ifdef ZTS
|
|
LCG(s2) = (zend_long) tsrm_thread_id();
|
|
#else
|
|
LCG(s2) = (zend_long) getpid();
|
|
#endif
|
|
|
|
/* Add entropy to s2 by calling gettimeofday() again */
|
|
if (gettimeofday(&tv, NULL) == 0) {
|
|
LCG(s2) ^= (tv.tv_usec<<11);
|
|
}
|
|
|
|
LCG(seeded) = 1;
|
|
}
|
|
/* }}} */
|
|
|
|
static void lcg_init_globals(php_lcg_globals *lcg_globals_p) /* {{{ */
|
|
{
|
|
LCG(seeded) = 0;
|
|
}
|
|
/* }}} */
|
|
|
|
PHP_MINIT_FUNCTION(lcg) /* {{{ */
|
|
{
|
|
#ifdef ZTS
|
|
ts_allocate_id(&lcg_globals_id, sizeof(php_lcg_globals), (ts_allocate_ctor) lcg_init_globals, NULL);
|
|
#else
|
|
lcg_init_globals(&lcg_globals);
|
|
#endif
|
|
return SUCCESS;
|
|
}
|
|
/* }}} */
|
|
|
|
/* {{{ proto float lcg_value()
|
|
Returns a value from the combined linear congruential generator */
|
|
PHP_FUNCTION(lcg_value)
|
|
{
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
return;
|
|
}
|
|
RETURN_DOUBLE(php_combined_lcg());
|
|
}
|
|
/* }}} */
|