This repository has been archived by the owner on Dec 6, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
php_python_internal.h
115 lines (96 loc) · 3.84 KB
/
php_python_internal.h
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
/*
* Python in PHP - Embedded Python Extension
*
* Copyright (c) 2003,2004,2005,2006,2007,2008 Jon Parise <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* $Id$
*/
#ifndef PHP_PYTHON_INTERNAL_H
#define PHP_PYTHON_INTERNAL_H
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4005 4142)
#endif
#include "Python.h"
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
#include "zend.h"
/*
* Make sure our version of Python is recent enough and that it has been
* built with all of the options that we need.
*/
#if !defined(PY_VERSION_HEX) || PY_VERSION_HEX <= 0x02050000
#error Sorry, the Python extension requires Python 2.5.0 or later.
#endif
#if !defined(WITH_THREAD)
#error Sorry, the Python extension requires Python's threading support.
#endif
/*
* Py_ssize_t was introduced in Python 2.5. Define our own version for
* compatiblity with earlier versions.
*/
#ifndef Py_ssize_t
#define Py_ssize_t ssize_t
#endif
ZEND_BEGIN_MODULE_GLOBALS(python)
PyThreadState *tstate;
ZEND_END_MODULE_GLOBALS(python)
#ifdef ZTS
#define PYG(v) TSRMG(python_globals_id, zend_python_globals *, v)
#else
#define PYG(v) (python_globals.v)
#endif
typedef struct _php_python_object {
zend_object base;
PyObject * object;
zend_class_entry * ce;
} php_python_object;
#define PHP_PYTHON_FETCH(name, zv) php_python_object *name = (php_python_object *)zend_object_store_get_object(zv TSRMLS_CC)
#define PHP_PYTHON_THREAD_ASSERT() assert(PyThreadState_GET() == PYG(tstate))
#define PHP_PYTHON_THREAD_ACQUIRE() PyEval_AcquireThread(PYG(tstate))
#define PHP_PYTHON_THREAD_RELEASE() PyEval_ReleaseThread(PyThreadState_GET())
/* Python Streams */
int python_streams_init();
int python_streams_intercept();
/* Python Modules */
int python_php_init();
/* PHP Object API */
zend_object_value python_object_create(zend_class_entry *ce TSRMLS_DC);
zend_uint python_get_arg_info(PyObject *callable, zend_arg_info **arg_info TSRMLS_DC) ;
/* PHP to Python Conversion */
PyObject * pip_hash_to_list(zval *hash TSRMLS_DC);
PyObject * pip_hash_to_tuple(zval *hash TSRMLS_DC);
PyObject * pip_hash_to_dict(zval *hash TSRMLS_DC);
PyObject * pip_zobject_to_pyobject(zval *obj TSRMLS_DC);
PyObject * pip_zval_to_pyobject(zval *val TSRMLS_DC);
/* Python to PHP Conversion */
int pip_sequence_to_hash(PyObject *o, HashTable *ht TSRMLS_DC);
int pip_sequence_to_array(PyObject *o, zval *zv TSRMLS_DC);
int pip_mapping_to_hash(PyObject *o, HashTable *ht TSRMLS_DC);
int pip_mapping_to_array(PyObject *o, zval *zv TSRMLS_DC);
int pip_pyobject_to_zobject(PyObject *o, zval *zv TSRMLS_DC);
int pip_pyobject_to_zval(PyObject *o, zval *zv TSRMLS_DC);
/* Argument Conversion */
PyObject * pip_args_to_tuple(int argc, int start TSRMLS_DC);
/* Object Representations */
int python_str(PyObject *o, char **buffer, Py_ssize_t *length TSRMLS_DC);
#endif /* PHP_PYTHON_INTERNAL_H */