@@ -24,20 +24,7 @@ from cpython.method cimport (
24
24
from cpython.bytes cimport PyBytes_FromFormat
25
25
26
26
# from libc.stdint cimport uintptr_t
27
- cdef extern from * :
28
- """
29
- #if PY_VERSION_HEX < 0x03040000 && defined(_MSC_VER)
30
- #ifndef _MSC_STDINT_H_
31
- #ifdef _WIN64 // [
32
- typedef unsigned __int64 uintptr_t;
33
- #else // _WIN64 ][
34
- typedef _W64 unsigned int uintptr_t;
35
- #endif // _WIN64 ]
36
- #endif
37
- #else
38
- #include <stdint.h>
39
- #endif
40
- """
27
+ cdef extern from " stdint.h" :
41
28
ctypedef size_t uintptr_t
42
29
cdef const Py_ssize_t PY_SSIZE_T_MAX
43
30
cdef const char CHAR_MIN, CHAR_MAX
@@ -51,10 +38,7 @@ from sys import exc_info
51
38
52
39
cdef object Mapping
53
40
cdef object Sequence
54
- try :
55
- from collections.abc import Mapping, Sequence
56
- except ImportError :
57
- from collections import Mapping, Sequence # Py2
41
+ from collections.abc import Mapping, Sequence
58
42
59
43
cdef object wraps
60
44
from functools import wraps
@@ -75,12 +59,6 @@ DEF POBJECT = b"POBJECT" # as used by LunaticPython
75
59
DEF LUPAOFH = b" LUPA_NUMBER_OVERFLOW_CALLBACK_FUNCTION"
76
60
DEF PYREFST = b" LUPA_PYTHON_REFERENCES_TABLE"
77
61
78
- cdef extern from * :
79
- """
80
- #define IS_PY2 (PY_MAJOR_VERSION == 2)
81
- """
82
- int IS_PY2
83
-
84
62
cdef enum WrappedObjectFlags:
85
63
# flags that determine the behaviour of a wrapped object:
86
64
OBJ_AS_INDEX = 1 # prefers the getitem protocol (over getattr)
@@ -165,7 +143,7 @@ def lua_type(obj):
165
143
return ' userdata'
166
144
else :
167
145
lua_type_name = lua.lua_typename(L, ltype)
168
- return lua_type_name if IS_PY2 else lua_type_name .decode(' ascii' )
146
+ return lua_type_name.decode(' ascii' )
169
147
finally :
170
148
lua.lua_settop(L, old_top)
171
149
unlock_runtime(lua_object._runtime)
@@ -235,7 +213,7 @@ cdef class LuaRuntime:
235
213
Normally, it should return the now well-behaved object that can be
236
214
converted/wrapped to a Lua type. If the object cannot be precisely
237
215
represented in Lua, it should raise an ``OverflowError``.
238
-
216
+
239
217
* ``max_memory``: max memory usage this LuaRuntime can use in bytes.
240
218
If max_memory is None, the default lua allocator is used and calls to
241
219
``set_max_memory(limit)`` will fail with a ``LuaMemoryError``.
@@ -656,20 +634,20 @@ cdef class LuaRuntime:
656
634
luaL_openlib(L, " python" , py_lib, 0 ) # lib
657
635
lua.lua_pushlightuserdata(L, < void * > self ) # lib udata
658
636
lua.lua_pushcclosure(L, py_args, 1 ) # lib function
659
- lua.lua_setfield(L, - 2 , " args" ) # lib
637
+ lua.lua_setfield(L, - 2 , " args" ) # lib
660
638
661
639
# register our own object metatable
662
640
lua.luaL_newmetatable(L, POBJECT) # lib metatbl
663
641
luaL_openlib(L, NULL , py_object_lib, 0 )
664
- lua.lua_pop(L, 1 ) # lib
642
+ lua.lua_pop(L, 1 ) # lib
665
643
666
644
# create and store the python references table
667
645
lua.lua_newtable(L) # lib tbl
668
646
lua.lua_createtable(L, 0 , 1 ) # lib tbl metatbl
669
647
lua.lua_pushlstring(L, " v" , 1 ) # lib tbl metatbl "v"
670
648
lua.lua_setfield(L, - 2 , " __mode" ) # lib tbl metatbl
671
649
lua.lua_setmetatable(L, - 2 ) # lib tbl
672
- lua.lua_setfield(L, lua.LUA_REGISTRYINDEX, PYREFST) # lib
650
+ lua.lua_setfield(L, lua.LUA_REGISTRYINDEX, PYREFST) # lib
673
651
674
652
# register global names in the module
675
653
self .register_py_object(b' Py_None' , b' none' , None )
@@ -818,17 +796,14 @@ cdef tuple unpack_lua_table(LuaRuntime runtime, lua_State* L):
818
796
while lua.lua_next(L, - 2 ): # key value
819
797
key = py_from_lua(runtime, L, - 2 )
820
798
value = py_from_lua(runtime, L, - 1 )
821
- if isinstance (key, ( int , long ) ) and not isinstance (key, bool ):
799
+ if isinstance (key, int ) and not isinstance (key, bool ):
822
800
index = < Py_ssize_t> key
823
801
if index < 1 or index > length:
824
802
raise IndexError (" table index out of range" )
825
803
cpython.ref.Py_INCREF(value)
826
804
cpython.tuple.PyTuple_SET_ITEM(args, index- 1 , value)
827
805
elif isinstance (key, bytes):
828
- if IS_PY2:
829
- kwargs[key] = value
830
- else :
831
- kwargs[(< bytes> key).decode(source_encoding)] = value
806
+ kwargs[(< bytes> key).decode(source_encoding)] = value
832
807
elif isinstance (key, unicode ):
833
808
kwargs[key] = value
834
809
else :
@@ -1508,21 +1483,14 @@ cdef object py_from_lua(LuaRuntime runtime, lua_State *L, int n):
1508
1483
elif lua_type == lua.LUA_TNUMBER:
1509
1484
if lua.LUA_VERSION_NUM >= 503 :
1510
1485
if lua.lua_isinteger(L, n):
1511
- integer = lua.lua_tointeger(L, n)
1512
- if IS_PY2 and (sizeof(lua.lua_Integer) <= sizeof(long ) or LONG_MIN <= integer <= LONG_MAX):
1513
- return < long > integer
1514
- else :
1515
- return integer
1486
+ return lua.lua_tointeger(L, n)
1516
1487
else :
1517
1488
return lua.lua_tonumber(L, n)
1518
1489
else :
1519
1490
number = lua.lua_tonumber(L, n)
1520
1491
integer = < lua.lua_Integer> number
1521
1492
if number == integer:
1522
- if IS_PY2 and (sizeof(lua.lua_Integer) <= sizeof(long ) or LONG_MIN <= integer <= LONG_MAX):
1523
- return < long > integer
1524
- else :
1525
- return integer
1493
+ return integer
1526
1494
else :
1527
1495
return number
1528
1496
elif lua_type == lua.LUA_TSTRING:
@@ -1632,7 +1600,7 @@ cdef int py_to_lua(LuaRuntime runtime, lua_State *L, object o, bint wrap_none=Fa
1632
1600
elif type (o) is float :
1633
1601
lua.lua_pushnumber(L, < lua.lua_Number> cpython.float.PyFloat_AS_DOUBLE(o))
1634
1602
pushed_values_count = 1
1635
- elif isinstance (o, ( long , int ) ):
1603
+ elif isinstance (o, int ):
1636
1604
try :
1637
1605
lua.lua_pushinteger(L, < lua.lua_Integer> o)
1638
1606
pushed_values_count = 1
@@ -2013,7 +1981,7 @@ cdef void* _lua_alloc_restricted(void* ud, void* ptr, size_t old_size, size_t ne
2013
1981
return NULL
2014
1982
elif new_size == old_size:
2015
1983
return ptr
2016
-
1984
+
2017
1985
if memory_status.limit > 0 and new_size > old_size and memory_status.limit <= memory_status.used + new_size - old_size: # reached the limit
2018
1986
# print("REACHED LIMIT")
2019
1987
return NULL
@@ -2085,7 +2053,7 @@ cdef int py_object_gc_with_gil(py_object *py_obj, lua_State* L) noexcept with gi
2085
2053
return 0
2086
2054
finally :
2087
2055
py_obj.obj = NULL
2088
-
2056
+
2089
2057
cdef int py_object_gc(lua_State* L) noexcept nogil:
2090
2058
if not lua.lua_isuserdata(L, 1 ):
2091
2059
return 0
0 commit comments