summaryrefslogtreecommitdiffstats
path: root/termbox-php7.patch
blob: 2eb060881199b0903438f54d82a1de9e1210fec3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
From 02a7c1c0a05614bd42e9d624aeda3be90d476f3a Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@php.net>
Date: Sat, 28 Mar 2015 11:56:23 +0100
Subject: [PATCH] PHP 7 compatibility

---
 php_termbox.h | 10 ++++++++++
 termbox.c     | 30 +++++++++++++++++-------------
 2 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/php_termbox.h b/php_termbox.h
index 179dcd3..c21ac75 100644
--- a/php_termbox.h
+++ b/php_termbox.h
@@ -89,6 +89,16 @@ PHP_FUNCTION(termbox_last_error);
 #define TERMBOX_G(v) (termbox_globals.v)
 #endif
 
+#if PHP_MAJOR_VERSION < 7
+typedef long zend_long;
+typedef int  strsize;
+#define TERMBOX_RETSTRL(a,l) RETURN_STRINGL(a,l,1)
+#else
+typedef size_t strsize;
+#define TSRMLS_CC
+#define TERMBOX_RETSTRL(a,l) RETURN_STRINGL(a,l)
+#endif
+
 #endif    /* PHP_TERMBOX_H */
 
 /*
diff --git a/termbox.c b/termbox.c
index 0b51b0f..575b5dd 100644
--- a/termbox.c
+++ b/termbox.c
@@ -149,8 +149,7 @@ PHP_MINIT_FUNCTION(termbox)
     ZEND_INIT_MODULE_GLOBALS(termbox, _termbox_init_globals, NULL);
 
     /** Register constants */
-    #define PHP_TERMBOX_CONSTANT(NAME) \
-        zend_register_long_constant(#NAME, sizeof(#NAME), NAME, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);
+    #define PHP_TERMBOX_CONSTANT(NAME) REGISTER_LONG_CONSTANT(#NAME, NAME, CONST_CS | CONST_PERSISTENT);
     #include "constants.h"
     #undef PHP_TERMBOX_CONSTANT
     return SUCCESS;
@@ -262,7 +261,8 @@ PHP_FUNCTION(termbox_clear)
    initialized yet. */
 PHP_FUNCTION(termbox_set_clear_attributes)
 {
-    long fg, bg;
+    zend_long fg, bg;
+
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &fg, &bg) == FAILURE) {
         return;
     }
@@ -292,7 +292,8 @@ PHP_FUNCTION(termbox_present)
    Cursor is hidden by default. Return FALSE if not initialized yet. */
 PHP_FUNCTION(termbox_set_cursor)
 {
-    long x, y;
+    zend_long x, y;
+
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &x, &y) == FAILURE) {
         return;
     }
@@ -307,7 +308,8 @@ PHP_FUNCTION(termbox_set_cursor)
    position. Return FALSE if not initialized yet. */
 PHP_FUNCTION(termbox_change_cell)
 {
-    long x, y, ch, fg, bg;
+    zend_long x, y, ch, fg, bg;
+
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllll", &x, &y, &ch, &fg, &bg) == FAILURE) {
         return;
     }
@@ -322,7 +324,8 @@ PHP_FUNCTION(termbox_change_cell)
     if not yet initialized. */
 PHP_FUNCTION(termbox_set_input_mode)
 {
-    long mode;
+    zend_long mode;
+
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &mode) == FAILURE) {
         return;
     }
@@ -354,7 +357,8 @@ PHP_FUNCTION(termbox_get_input_mode) {
    yet initialized. */
 PHP_FUNCTION(termbox_set_output_mode)
 {
-    long mode;
+    zend_long mode;
+
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &mode) == FAILURE) {
         return;
     }
@@ -398,7 +402,7 @@ static void _termbox_event_to_php_array(struct tb_event *event, zval *event_arr)
    NULL. If an error occurrs, return FALSE. */
 PHP_FUNCTION(termbox_peek_event)
 {
-    long timeout_ms;
+    zend_long timeout_ms;
     struct tb_event event;
     int rc;
 
@@ -449,7 +453,7 @@ PHP_FUNCTION(termbox_poll_event)
 PHP_FUNCTION(termbox_utf8_char_to_unicode)
 {
     char *str;
-    int str_len;
+    strsize str_len;
     uint32_t unicode_int;
 
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
@@ -470,7 +474,7 @@ PHP_FUNCTION(termbox_utf8_unicode_to_char)
 {
     char str[7];
     int str_len;
-    long unicode;
+    zend_long unicode;
 
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &unicode) == FAILURE) {
         return;
@@ -483,7 +487,7 @@ PHP_FUNCTION(termbox_utf8_unicode_to_char)
         str_len = 0;
     }
 
-    RETURN_STRINGL(str, str_len, 1);
+    TERMBOX_RETSTRL(str, str_len);
 }
 /* }}} */
 
@@ -493,8 +497,8 @@ PHP_FUNCTION(termbox_utf8_unicode_to_char)
 PHP_FUNCTION(termbox_print)
 {
     char *str;
-    int str_len;
-    long x, y, fg, bg;
+    strsize str_len;
+    zend_long x, y, fg, bg;
     uint32_t unicode;
 
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllll", &str, &str_len, &x, &y, &fg, &bg) == FAILURE) {
-- 
2.1.4