Skip to content

Instantly share code, notes, and snippets.

Nikita Popov nikic

Block or report user

Report or block nikic

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nikic
nikic / shell_exec
Created Oct 7, 2019
Usage of shell exec operation in packagist top 2k
View shell_exec
/home/nikic/package-analysis/sources/globalcitizen/php-iban/utils/convert-registry.php:10
`iconv -f utf8 -t ascii --byte-subst="<0x%x>" --unicode-subst="<U+%04X>" 'IBAN_Registry.txt'`
/home/nikic/package-analysis/sources/johnpbloch/wordpress-core/wp-includes/ID3/getid3.lib.php:621
`$commandline`
/home/nikic/package-analysis/sources/johnpbloch/wordpress-core/wp-includes/ID3/getid3.lib.php:1416
`$commandline`
/home/nikic/package-analysis/sources/johnpbloch/wordpress-core/wp-includes/ID3/getid3.php:196
`$commandline`
/home/nikic/package-analysis/sources/johnpbloch/wordpress-core/wp-includes/ID3/getid3.php:1358
`$commandline`
@nikic
nikic / php74_shim.h
Last active Apr 29, 2019
PHP 7.4 shim for the typed properties RFC
View php74_shim.h
#ifndef PHP74_SHIM_H
#define PHP74_SHIM_H
#if PHP_VERSION_ID < 70400
#define ZEND_TRY_ASSIGN_NULL(zv) do { \
ZVAL_DEREF(zv); \
zval_ptr_dtor(zv); \
ZVAL_NULL(zv); \
} while (0)
View validate_ascii.ll
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%struct.__loadu_si128 = type { <2 x i64> }
define i32 @validate_ascii(i8*, i64, i8*, i64*) #4 {
%5 = icmp ule i64 16, %1
br i1 %5, label %6, label %30
%7 = sub i64 %1, 16
View gc_compress.diff
diff --git a/Zend/zend_gc.c b/Zend/zend_gc.c
index 79c3470..f8fc6cd 100644
--- a/Zend/zend_gc.c
+++ b/Zend/zend_gc.c
@@ -126,16 +126,12 @@
#define GC_DEFAULT_BUF_SIZE (16 * 1024)
#define GC_BUF_GROW_STEP (128 * 1024)
-#define GC_COMPRESS_FACTOR 4096 /* shold be 0 to disable compression */
-#define GC_MAX_UNCOMPRESSED ((1024 * 1024) - GC_COMPRESS_FACTOR)
View mt_rand.c
// Resulting code as the diff is hard to read
static uint32_t rand_range32(uint32_t umax) {
uint32_t result, limit;
result = php_mt_rand();
/* Special case where no modulus is required */
if (UNEXPECTED(umax == UINT32_MAX)) {
return result;
@nikic
nikic / demo.php
Created Dec 26, 2016
Demo for format preserving AST transformation
View demo.php
<?php
/* This demo replaces all unqualified function calls and namespaced lookups
* with fully qualified ones. Apart from this change all formatting should
* be preserved. */
use PhpParser\Lexer;
use PhpParser\Parser;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
View jit_output.asm
JIT$$interrupt_handler: ; (unknown)
mov $0x0, EG(vm_interrupt)
cmp $0x0, EG(timed_out)
jz .L1
xor %edi, %edi
call zend_timeout
.L1:
add $0x8, %rsp
jmp (%r15)
View timelib.diff
diff --git a/ext/date/lib/parse_tz.c b/ext/date/lib/parse_tz.c
index 308437e..ebc4d1e 100644
--- a/ext/date/lib/parse_tz.c
+++ b/ext/date/lib/parse_tz.c
@@ -438,7 +438,7 @@ static struct location_info **create_location_table(void)
return NULL;
}
- li = timelib_calloc(LOCINFO_HASH_SIZE, sizeof *li);
+ li = calloc(LOCINFO_HASH_SIZE, sizeof *li);
View bench.php
<?php error_reporting(E_ALL);
function formatT($t) {
return sprintf('%.1f mus', $t * 1000000);
}
function formatResult($result) {
list($mean, $stddev) = $result;
return formatT($mean) . " +/- " . formatT($stddev);
}
@nikic
nikic / BinaryTree.php
Created Apr 23, 2015
Tree traversal performance: yield from vs. naive implementation
View BinaryTree.php
<?php error_reporting(E_ALL);
class BinaryTree {
private $content, $left, $right;
public function __construct($content, BinaryTree $left = null, BinaryTree $right = null) {
$this->content = $content;
$this->left = $left;
$this->right = $right;
}
You can’t perform that action at this time.