Skip to content

Commit

Permalink
Fix incorrect behavior, enum must not be converted to integer
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Jan 22, 2024
1 parent e6bf09e commit 4fa62b2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/bridge/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ static bool py2php_base_type(PyObject *pv, zval *zv) {
ZVAL_BOOL(zv, Py_IsTrue(pv));
} else if (Py_IsNone(pv)) {
ZVAL_NULL(zv);
} else if (PyLong_Check(pv)) {
} else if (PyLong_CheckExact(pv)) {
long2long(pv, zv);
} else if (PyFloat_Check(pv)) {
ZVAL_DOUBLE(zv, PyFloat_AsDouble(pv));
Expand Down
2 changes: 1 addition & 1 deletion src/python/callable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static PyObject *Callable_call(ZendCallable *self, PyObject *args, PyObject *kwd
zval retval;
zend_result result = phpy::php::call_fn(NULL, &self->callable, &retval, argc, argv);
if (result == FAILURE) {
if (EG(exception) ) {
if (EG(exception)) {
zend_exception_error(EG(exception), E_ERROR);
}
PyErr_Format(PyExc_RuntimeError, "Function call failed");
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/app/user.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
from enum import Enum


def test():
print("app.user.main.test()")


storage = {}


class Color(Enum):
RED = 1
BLUE = 2
GREEN = 3


class User:
def __init__(self, name):
self._name = name
Expand Down
8 changes: 8 additions & 0 deletions tests/phpunit/IntTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ function testIntOverflow()

$this->assertEquals(strval($i->__pow__(3)), '1881564851360655187875');
}

function testEnum()
{
$m = PyCore::import('app.user');
$v = $m->Color->GREEN;
$this->assertIsNotInt($v);
$this->assertEquals($v->value, 3);
}
}

0 comments on commit 4fa62b2

Please sign in to comment.