Skip to content

Commit 7a36470

Browse files
committed
Rename to collections extension, Collections\Deque
https://wiki.php.net/rfc/deque_straw_poll
1 parent 9906e13 commit 7a36470

38 files changed

+571
-468
lines changed

ext/spl/spl_deque.c renamed to ext/collections/collections_deque.c

Lines changed: 212 additions & 213 deletions
Large diffs are not rendered by default.

ext/spl/spl_deque.h renamed to ext/collections/collections_deque.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
+----------------------------------------------------------------------+
1515
*/
1616

17-
#ifndef TEDS_DEQUE_H
18-
#define TEDS_DEQUE_H
17+
#ifndef COLLECTIONS_DEQUE_H
18+
#define COLLECTIONS_DEQUE_H
1919

20-
extern zend_class_entry *spl_ce_Deque;
20+
extern zend_class_entry *collections_ce_Deque;
2121

22-
PHP_MINIT_FUNCTION(spl_deque);
22+
PHP_MINIT_FUNCTION(collections_deque);
2323

24-
#endif /* TEDS_DEQUE_H */
24+
#endif /* COLLECTIONS_DEQUE_H */

ext/spl/spl_deque.stub.php renamed to ext/collections/collections_deque.stub.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
/** @generate-class-entries */
44

5+
namespace Collections;
6+
57
/**
68
* A double-ended queue (Typically abbreviated as Deque, pronounced "deck", like "cheque")
79
* represented internally as a circular buffer.
@@ -30,7 +32,7 @@ public function __construct(iterable $iterator = []) {}
3032
* position ends up before the start of the Deque at the time iteration resumes.
3133
* - They will not cause the remaining values to be iterated over more than once or skipped.
3234
*/
33-
public function getIterator(): InternalIterator {}
35+
public function getIterator(): \InternalIterator {}
3436
/** Returns the number of elements in the Deque. */
3537
public function count(): int {}
3638
/** Returns true if there are 0 elements in the Deque. */
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/* This is a generated file, edit the .stub.php file instead.
2+
* Stub hash: 7724c400fc239aace1ab5666df575d7ab2214d4f */
3+
4+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Collections_Deque___construct, 0, 0, 0)
5+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, iterator, IS_ITERABLE, 0, "[]")
6+
ZEND_END_ARG_INFO()
7+
8+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Collections_Deque_getIterator, 0, 0, InternalIterator, 0)
9+
ZEND_END_ARG_INFO()
10+
11+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Collections_Deque_count, 0, 0, IS_LONG, 0)
12+
ZEND_END_ARG_INFO()
13+
14+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Collections_Deque_isEmpty, 0, 0, _IS_BOOL, 0)
15+
ZEND_END_ARG_INFO()
16+
17+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Collections_Deque_clear, 0, 0, IS_VOID, 0)
18+
ZEND_END_ARG_INFO()
19+
20+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Collections_Deque___serialize, 0, 0, IS_ARRAY, 0)
21+
ZEND_END_ARG_INFO()
22+
23+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Collections_Deque___unserialize, 0, 1, IS_VOID, 0)
24+
ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0)
25+
ZEND_END_ARG_INFO()
26+
27+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Collections_Deque___set_state, 0, 1, Collections\\Deque, 0)
28+
ZEND_ARG_TYPE_INFO(0, array, IS_ARRAY, 0)
29+
ZEND_END_ARG_INFO()
30+
31+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Collections_Deque_push, 0, 0, IS_VOID, 0)
32+
ZEND_ARG_VARIADIC_TYPE_INFO(0, values, IS_MIXED, 0)
33+
ZEND_END_ARG_INFO()
34+
35+
#define arginfo_class_Collections_Deque_unshift arginfo_class_Collections_Deque_push
36+
37+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Collections_Deque_pop, 0, 0, IS_MIXED, 0)
38+
ZEND_END_ARG_INFO()
39+
40+
#define arginfo_class_Collections_Deque_shift arginfo_class_Collections_Deque_pop
41+
42+
#define arginfo_class_Collections_Deque_bottom arginfo_class_Collections_Deque_pop
43+
44+
#define arginfo_class_Collections_Deque_top arginfo_class_Collections_Deque_pop
45+
46+
#define arginfo_class_Collections_Deque_toArray arginfo_class_Collections_Deque___serialize
47+
48+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Collections_Deque_get, 0, 1, IS_MIXED, 0)
49+
ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0)
50+
ZEND_END_ARG_INFO()
51+
52+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Collections_Deque_set, 0, 2, IS_VOID, 0)
53+
ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0)
54+
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
55+
ZEND_END_ARG_INFO()
56+
57+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Collections_Deque_offsetGet, 0, 1, IS_MIXED, 0)
58+
ZEND_ARG_TYPE_INFO(0, offset, IS_MIXED, 0)
59+
ZEND_END_ARG_INFO()
60+
61+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Collections_Deque_offsetExists, 0, 1, _IS_BOOL, 0)
62+
ZEND_ARG_TYPE_INFO(0, offset, IS_MIXED, 0)
63+
ZEND_END_ARG_INFO()
64+
65+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Collections_Deque_offsetSet, 0, 2, IS_VOID, 0)
66+
ZEND_ARG_TYPE_INFO(0, offset, IS_MIXED, 0)
67+
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
68+
ZEND_END_ARG_INFO()
69+
70+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Collections_Deque_offsetUnset, 0, 1, IS_VOID, 0)
71+
ZEND_ARG_TYPE_INFO(0, offset, IS_MIXED, 0)
72+
ZEND_END_ARG_INFO()
73+
74+
#define arginfo_class_Collections_Deque_jsonSerialize arginfo_class_Collections_Deque___serialize
75+
76+
77+
ZEND_METHOD(Collections_Deque, __construct);
78+
ZEND_METHOD(Collections_Deque, getIterator);
79+
ZEND_METHOD(Collections_Deque, count);
80+
ZEND_METHOD(Collections_Deque, isEmpty);
81+
ZEND_METHOD(Collections_Deque, clear);
82+
ZEND_METHOD(Collections_Deque, __serialize);
83+
ZEND_METHOD(Collections_Deque, __unserialize);
84+
ZEND_METHOD(Collections_Deque, __set_state);
85+
ZEND_METHOD(Collections_Deque, push);
86+
ZEND_METHOD(Collections_Deque, unshift);
87+
ZEND_METHOD(Collections_Deque, pop);
88+
ZEND_METHOD(Collections_Deque, shift);
89+
ZEND_METHOD(Collections_Deque, bottom);
90+
ZEND_METHOD(Collections_Deque, top);
91+
ZEND_METHOD(Collections_Deque, toArray);
92+
ZEND_METHOD(Collections_Deque, get);
93+
ZEND_METHOD(Collections_Deque, set);
94+
ZEND_METHOD(Collections_Deque, offsetGet);
95+
ZEND_METHOD(Collections_Deque, offsetExists);
96+
ZEND_METHOD(Collections_Deque, offsetSet);
97+
ZEND_METHOD(Collections_Deque, offsetUnset);
98+
ZEND_METHOD(Collections_Deque, jsonSerialize);
99+
100+
101+
static const zend_function_entry class_Collections_Deque_methods[] = {
102+
ZEND_ME(Collections_Deque, __construct, arginfo_class_Collections_Deque___construct, ZEND_ACC_PUBLIC)
103+
ZEND_ME(Collections_Deque, getIterator, arginfo_class_Collections_Deque_getIterator, ZEND_ACC_PUBLIC)
104+
ZEND_ME(Collections_Deque, count, arginfo_class_Collections_Deque_count, ZEND_ACC_PUBLIC)
105+
ZEND_ME(Collections_Deque, isEmpty, arginfo_class_Collections_Deque_isEmpty, ZEND_ACC_PUBLIC)
106+
ZEND_ME(Collections_Deque, clear, arginfo_class_Collections_Deque_clear, ZEND_ACC_PUBLIC)
107+
ZEND_ME(Collections_Deque, __serialize, arginfo_class_Collections_Deque___serialize, ZEND_ACC_PUBLIC)
108+
ZEND_ME(Collections_Deque, __unserialize, arginfo_class_Collections_Deque___unserialize, ZEND_ACC_PUBLIC)
109+
ZEND_ME(Collections_Deque, __set_state, arginfo_class_Collections_Deque___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
110+
ZEND_ME(Collections_Deque, push, arginfo_class_Collections_Deque_push, ZEND_ACC_PUBLIC)
111+
ZEND_ME(Collections_Deque, unshift, arginfo_class_Collections_Deque_unshift, ZEND_ACC_PUBLIC)
112+
ZEND_ME(Collections_Deque, pop, arginfo_class_Collections_Deque_pop, ZEND_ACC_PUBLIC)
113+
ZEND_ME(Collections_Deque, shift, arginfo_class_Collections_Deque_shift, ZEND_ACC_PUBLIC)
114+
ZEND_ME(Collections_Deque, bottom, arginfo_class_Collections_Deque_bottom, ZEND_ACC_PUBLIC)
115+
ZEND_ME(Collections_Deque, top, arginfo_class_Collections_Deque_top, ZEND_ACC_PUBLIC)
116+
ZEND_ME(Collections_Deque, toArray, arginfo_class_Collections_Deque_toArray, ZEND_ACC_PUBLIC)
117+
ZEND_ME(Collections_Deque, get, arginfo_class_Collections_Deque_get, ZEND_ACC_PUBLIC)
118+
ZEND_ME(Collections_Deque, set, arginfo_class_Collections_Deque_set, ZEND_ACC_PUBLIC)
119+
ZEND_ME(Collections_Deque, offsetGet, arginfo_class_Collections_Deque_offsetGet, ZEND_ACC_PUBLIC)
120+
ZEND_ME(Collections_Deque, offsetExists, arginfo_class_Collections_Deque_offsetExists, ZEND_ACC_PUBLIC)
121+
ZEND_ME(Collections_Deque, offsetSet, arginfo_class_Collections_Deque_offsetSet, ZEND_ACC_PUBLIC)
122+
ZEND_ME(Collections_Deque, offsetUnset, arginfo_class_Collections_Deque_offsetUnset, ZEND_ACC_PUBLIC)
123+
ZEND_ME(Collections_Deque, jsonSerialize, arginfo_class_Collections_Deque_jsonSerialize, ZEND_ACC_PUBLIC)
124+
ZEND_FE_END
125+
};
126+
127+
static zend_class_entry *register_class_Collections_Deque(zend_class_entry *class_entry_Collections_IteratorAggregate, zend_class_entry *class_entry_Collections_Countable, zend_class_entry *class_entry_Collections_JsonSerializable, zend_class_entry *class_entry_Collections_ArrayAccess)
128+
{
129+
zend_class_entry ce, *class_entry;
130+
131+
INIT_NS_CLASS_ENTRY(ce, "Collections", "Deque", class_Collections_Deque_methods);
132+
class_entry = zend_register_internal_class_ex(&ce, NULL);
133+
class_entry->ce_flags |= ZEND_ACC_FINAL;
134+
zend_class_implements(class_entry, 4, class_entry_Collections_IteratorAggregate, class_entry_Collections_Countable, class_entry_Collections_JsonSerializable, class_entry_Collections_ArrayAccess);
135+
136+
return class_entry;
137+
}

ext/collections/config.m4

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
PHP_NEW_EXTENSION(collections, php_collections.c collections_deque.c, no,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
2+
PHP_INSTALL_HEADERS([ext/spl], [php_collections.h collections_deque.h])
3+
PHP_ADD_EXTENSION_DEP(collections, pcre, true)
4+
PHP_ADD_EXTENSION_DEP(collections, spl, true)
5+
PHP_ADD_EXTENSION_DEP(collections, standard, true)
6+
PHP_ADD_EXTENSION_DEP(collections, json)

ext/collections/config.w32

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// vim:ft=javascript
2+
3+
EXTENSION("collections", "php_collections.c collections_deque.c", false /*never shared */, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
4+
PHP_COLLECTIONS="yes";
5+
PHP_INSTALL_HEADERS("ext/collections", "php_collections.h collections_deque.h");

ext/collections/php_collections.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| collections extension for PHP |
4+
| See COPYING file for further copyright information |
5+
+----------------------------------------------------------------------+
6+
| Author: Tyson Andre <[email protected]> |
7+
+----------------------------------------------------------------------+
8+
*/
9+
10+
#ifdef HAVE_CONFIG_H
11+
# include "config.h"
12+
#endif
13+
14+
#include "php.h"
15+
16+
#include "ext/standard/info.h"
17+
18+
#include "collections_deque.h"
19+
20+
#include "php_collections.h"
21+
22+
/* {{{ PHP_MINIT_FUNCTION */
23+
PHP_MINIT_FUNCTION(collections)
24+
{
25+
PHP_MINIT(collections_deque)(INIT_FUNC_ARGS_PASSTHRU);
26+
return SUCCESS;
27+
}
28+
/* }}} */
29+
30+
/* {{{ PHP_MINFO_FUNCTION */
31+
PHP_MINFO_FUNCTION(collections)
32+
{
33+
(void) ((ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU));
34+
php_info_print_table_start();
35+
php_info_print_table_header(2, "collections support", "enabled");
36+
php_info_print_table_row(2, "collections version", PHP_COLLECTIONS_VERSION);
37+
php_info_print_table_end();
38+
}
39+
/* }}} */
40+
41+
/* {{{ collections_module_entry */
42+
zend_module_entry collections_module_entry = {
43+
STANDARD_MODULE_HEADER,
44+
"collections", /* Extension name */
45+
NULL, /* zend_function_entry */
46+
PHP_MINIT(collections), /* PHP_MINIT - Module initialization */
47+
NULL, /* PHP_MSHUTDOWN - Module shutdown */
48+
NULL, /* PHP_RINIT - Request initialization */
49+
NULL, /* PHP_RSHUTDOWN - Request shutdown */
50+
PHP_MINFO(collections), /* PHP_MINFO - Module info */
51+
PHP_COLLECTIONS_VERSION, /* Version */
52+
STANDARD_MODULE_PROPERTIES
53+
};
54+
/* }}} */
55+
56+
57+
#ifdef COMPILE_DL_COLLECTIONS
58+
# ifdef ZTS
59+
ZEND_TSRMLS_CACHE_DEFINE()
60+
# endif
61+
ZEND_GET_MODULE(collections)
62+
#endif

ext/collections/php_collections.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| Copyright (c) The PHP Group |
4+
+----------------------------------------------------------------------+
5+
| This source file is subject to version 3.01 of the PHP license, |
6+
| that is bundled with this package in the file LICENSE, and is |
7+
| available through the world-wide-web at the following url: |
8+
| https://www.php.net/license/3_01.txt |
9+
| If you did not receive a copy of the PHP license and are unable to |
10+
| obtain it through the world-wide-web, please send a note to |
11+
| [email protected] so we can mail you a copy immediately. |
12+
+----------------------------------------------------------------------+
13+
| Authors: Tyson Andre <[email protected]> |
14+
+----------------------------------------------------------------------+
15+
*/
16+
17+
#ifndef PHP_COLLECTIONS_H
18+
#define PHP_COLLECTIONS_H
19+
20+
#include "php.h"
21+
#include <stdarg.h>
22+
23+
#define PHP_COLLECTIONS_VERSION PHP_VERSION
24+
25+
extern zend_module_entry collections_module_entry;
26+
#define phpext_collections_ptr &collections_module_entry
27+
28+
PHP_MINIT_FUNCTION(collections);
29+
PHP_MINFO_FUNCTION(collections);
30+
31+
#endif /* PHP_COLLECTIONS_H */

ext/spl/tests/Deque/Deque.phpt renamed to ext/collections/tests/Deque/Deque.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
--TEST--
2-
Deque constructed from array
2+
Collections\Deque constructed from array
33
--FILE--
44
<?php
55
// discards keys
6-
$it = new Deque(['first' => 'x', 'second' => new stdClass()]);
6+
$it = new Collections\Deque(['first' => 'x', 'second' => new stdClass()]);
77
foreach ($it as $key => $value) {
88
printf("Key: %s\nValue: %s\n", var_export($key, true), var_export($value, true));
99
}
1010
var_dump($it);
1111
var_dump((array)$it);
1212

13-
$it = new Deque([]);
13+
$it = new Collections\Deque([]);
1414
var_dump($it);
1515
var_dump((array)$it);
1616
foreach ($it as $key => $value) {
@@ -24,7 +24,7 @@ Value: 'x'
2424
Key: 1
2525
Value: (object) array(
2626
)
27-
object(Deque)#1 (2) {
27+
object(Collections\Deque)#1 (2) {
2828
[0]=>
2929
string(1) "x"
3030
[1]=>
@@ -38,7 +38,7 @@ array(2) {
3838
object(stdClass)#2 (0) {
3939
}
4040
}
41-
object(Deque)#3 (0) {
41+
object(Collections\Deque)#3 (0) {
4242
}
4343
array(0) {
4444
}

ext/spl/tests/Deque/aggregate.phpt renamed to ext/collections/tests/Deque/aggregate.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
Deque is an IteratorAggregate
2+
Collections\Deque is an IteratorAggregate
33
--FILE--
44
<?php
55

6-
$it = new Deque(['discarded_first' => 'x', 'discardedsecond' => (object)['key' => 'value']]);
6+
$it = new Collections\Deque(['discarded_first' => 'x', 'discardedsecond' => (object)['key' => 'value']]);
77
foreach ($it as $k1 => $v1) {
88
foreach ($it as $k2 => $v2) {
99
printf("k1=%s k2=%s v1=%s v2=%s\n", json_encode($k1), json_encode($k2), json_encode($v1), json_encode($v2));

ext/spl/tests/Deque/arrayCast.phpt renamed to ext/collections/tests/Deque/arrayCast.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
Deque to array
2+
Collections\Deque to array
33
--FILE--
44
<?php
55
// discards keys
6-
$it = new Deque([strtoupper('test')]);
6+
$it = new Collections\Deque([strtoupper('test')]);
77
var_dump((array)$it);
88
$it[0] = strtoupper('test2');
99
var_dump((array)$it);
@@ -22,9 +22,9 @@ array(1) {
2222
[0]=>
2323
string(5) "TEST2"
2424
}
25-
object(Deque)#1 (1) {
25+
object(Collections\Deque)#1 (1) {
2626
[0]=>
2727
string(5) "TEST2"
2828
}
29-
object(Deque)#1 (0) {
29+
object(Collections\Deque)#1 (0) {
3030
}

ext/spl/tests/Deque/clear.phpt renamed to ext/collections/tests/Deque/clear.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
Deque clear
2+
Collections\Deque clear
33
--FILE--
44
<?php
55

6-
$it = new Deque(['first' => new stdClass()]);
6+
$it = new Collections\Deque(['first' => new stdClass()]);
77
var_dump($it->toArray());
88
printf("count=%d\n", $it->count());
99
$it->clear();

ext/spl/tests/Deque/clone.phpt renamed to ext/collections/tests/Deque/clone.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
Deque can be cloned
2+
Collections\Deque can be cloned
33
--FILE--
44
<?php
55

6-
$it = new Deque([new stdClass(), new ArrayObject()]);
6+
$it = new Collections\Deque([new stdClass(), new ArrayObject()]);
77
$it2 = clone $it;
88
unset($it);
99
foreach ($it2 as $key => $value) {

ext/spl/tests/Deque/exceptionhandler.phpt renamed to ext/collections/tests/Deque/exceptionhandler.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Deque constructed from Traversable throwing
2+
Collections\Deque constructed from Traversable throwing
33
--FILE--
44
<?php
55

@@ -21,7 +21,7 @@ function yields_and_throws() {
2121
echo "Unreachable\n";
2222
}
2323
try {
24-
$it = new Deque(yields_and_throws());
24+
$it = new Collections\Deque(yields_and_throws());
2525
} catch (RuntimeException $e) {
2626
echo "Caught " . $e->getMessage() . "\n";
2727
}

0 commit comments

Comments
 (0)