Skip to content

Commit

Permalink
Merge branch 'master' into pylupa
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/ci.yml
#	.github/workflows/wheels.yml
#	appveyor.yml
#	pyproject.toml
#	requirements.txt
#	setup.py
  • Loading branch information
emcek committed Jan 10, 2025
2 parents 7408009 + 4570127 commit 5b15e04
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 106 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ jobs:
matrix:
os:
- windows-2019
- ubuntu-20.04
- macos-13
- ubuntu-latest
- macos-latest
python-version:
- "2.7"
Expand Down Expand Up @@ -110,12 +109,6 @@ jobs:
if: contains(matrix.os, 'ubuntu') && matrix.lua-version != 'bundle'
run: sudo apt-get install lib${{ matrix.lua-version }}-dev

- name: Setup Visual Studio
if: contains(matrix.os, 'windows')
uses: TheMrMilchmann/setup-msvc-dev@v3
with:
arch: x64

- name: Build wheel
run: python setup.py ${{ contains(matrix.python-version, '3.') && 'build_ext -j6' || '' }} bdist_wheel
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ permissions: {}

jobs:
sdist:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
Expand Down
21 changes: 21 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
Lupa change log
===============

2.4 (2025-01-10)
----------------

* The windows wheels now bundle LuaJIT 2.0 and 2.1.
(patch by Michal Plichta)

* Failures in the test suite didn't set a non-zero process exit value.


2.3 (2025-01-09)
----------------

* The bundled LuaJIT versions were updated to the latest git branches.

* The bundled Lua 5.4 was updated to 5.4.7.

* Removed support for Python 2.x.

* Built with Cython 3.0.11.


2.2 (2024-06-02)
----------------

Expand Down
3 changes: 2 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ environment:

install:
- SET PATH=C:\\Python%PYTHON%;c:\\Python%PYTHON%\\scripts;%PATH%
- python -m pip.__main__ install -U pip wheel "setuptools<72.0.0"
- python -m pip.__main__ install -U pip wheel "setuptools<72.0.0" # "setuptools!=72.0.0"
- pip install -r requirements.txt
- git submodule update --init --recursive

Expand All @@ -47,6 +47,7 @@ build_script:
test: off
test_script:
- python -u setup.py -q test
# - python -u -m lupa.tests.__main__

artifacts:
- path: dist/*.whl
Expand Down
60 changes: 14 additions & 46 deletions lupa/_lupa.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,7 @@ from cpython.method cimport (
from cpython.bytes cimport PyBytes_FromFormat

#from libc.stdint cimport uintptr_t
cdef extern from *:
"""
#if PY_VERSION_HEX < 0x03040000 && defined(_MSC_VER)
#ifndef _MSC_STDINT_H_
#ifdef _WIN64 // [
typedef unsigned __int64 uintptr_t;
#else // _WIN64 ][
typedef _W64 unsigned int uintptr_t;
#endif // _WIN64 ]
#endif
#else
#include <stdint.h>
#endif
"""
cdef extern from "stdint.h":
ctypedef size_t uintptr_t
cdef const Py_ssize_t PY_SSIZE_T_MAX
cdef const char CHAR_MIN, CHAR_MAX
Expand All @@ -51,10 +38,7 @@ from sys import exc_info

cdef object Mapping
cdef object Sequence
try:
from collections.abc import Mapping, Sequence
except ImportError:
from collections import Mapping, Sequence # Py2
from collections.abc import Mapping, Sequence

cdef object wraps
from functools import wraps
Expand All @@ -75,12 +59,6 @@ DEF POBJECT = b"POBJECT" # as used by LunaticPython
DEF LUPAOFH = b"LUPA_NUMBER_OVERFLOW_CALLBACK_FUNCTION"
DEF PYREFST = b"LUPA_PYTHON_REFERENCES_TABLE"

cdef extern from *:
"""
#define IS_PY2 (PY_MAJOR_VERSION == 2)
"""
int IS_PY2

cdef enum WrappedObjectFlags:
# flags that determine the behaviour of a wrapped object:
OBJ_AS_INDEX = 1 # prefers the getitem protocol (over getattr)
Expand Down Expand Up @@ -165,7 +143,7 @@ def lua_type(obj):
return 'userdata'
else:
lua_type_name = lua.lua_typename(L, ltype)
return lua_type_name if IS_PY2 else lua_type_name.decode('ascii')
return lua_type_name.decode('ascii')
finally:
lua.lua_settop(L, old_top)
unlock_runtime(lua_object._runtime)
Expand Down Expand Up @@ -235,7 +213,7 @@ cdef class LuaRuntime:
Normally, it should return the now well-behaved object that can be
converted/wrapped to a Lua type. If the object cannot be precisely
represented in Lua, it should raise an ``OverflowError``.
* ``max_memory``: max memory usage this LuaRuntime can use in bytes.
If max_memory is None, the default lua allocator is used and calls to
``set_max_memory(limit)`` will fail with a ``LuaMemoryError``.
Expand Down Expand Up @@ -656,20 +634,20 @@ cdef class LuaRuntime:
luaL_openlib(L, "python", py_lib, 0) # lib
lua.lua_pushlightuserdata(L, <void*>self) # lib udata
lua.lua_pushcclosure(L, py_args, 1) # lib function
lua.lua_setfield(L, -2, "args") # lib
lua.lua_setfield(L, -2, "args") # lib

# register our own object metatable
lua.luaL_newmetatable(L, POBJECT) # lib metatbl
luaL_openlib(L, NULL, py_object_lib, 0)
lua.lua_pop(L, 1) # lib
lua.lua_pop(L, 1) # lib

# create and store the python references table
lua.lua_newtable(L) # lib tbl
lua.lua_createtable(L, 0, 1) # lib tbl metatbl
lua.lua_pushlstring(L, "v", 1) # lib tbl metatbl "v"
lua.lua_setfield(L, -2, "__mode") # lib tbl metatbl
lua.lua_setmetatable(L, -2) # lib tbl
lua.lua_setfield(L, lua.LUA_REGISTRYINDEX, PYREFST) # lib
lua.lua_setfield(L, lua.LUA_REGISTRYINDEX, PYREFST) # lib

# register global names in the module
self.register_py_object(b'Py_None', b'none', None)
Expand Down Expand Up @@ -818,17 +796,14 @@ cdef tuple unpack_lua_table(LuaRuntime runtime, lua_State* L):
while lua.lua_next(L, -2): # key value
key = py_from_lua(runtime, L, -2)
value = py_from_lua(runtime, L, -1)
if isinstance(key, (int, long)) and not isinstance(key, bool):
if isinstance(key, int) and not isinstance(key, bool):
index = <Py_ssize_t>key
if index < 1 or index > length:
raise IndexError("table index out of range")
cpython.ref.Py_INCREF(value)
cpython.tuple.PyTuple_SET_ITEM(args, index-1, value)
elif isinstance(key, bytes):
if IS_PY2:
kwargs[key] = value
else:
kwargs[(<bytes>key).decode(source_encoding)] = value
kwargs[(<bytes>key).decode(source_encoding)] = value
elif isinstance(key, unicode):
kwargs[key] = value
else:
Expand Down Expand Up @@ -1508,21 +1483,14 @@ cdef object py_from_lua(LuaRuntime runtime, lua_State *L, int n):
elif lua_type == lua.LUA_TNUMBER:
if lua.LUA_VERSION_NUM >= 503:
if lua.lua_isinteger(L, n):
integer = lua.lua_tointeger(L, n)
if IS_PY2 and (sizeof(lua.lua_Integer) <= sizeof(long) or LONG_MIN <= integer <= LONG_MAX):
return <long>integer
else:
return integer
return lua.lua_tointeger(L, n)
else:
return lua.lua_tonumber(L, n)
else:
number = lua.lua_tonumber(L, n)
integer = <lua.lua_Integer>number
if number == integer:
if IS_PY2 and (sizeof(lua.lua_Integer) <= sizeof(long) or LONG_MIN <= integer <= LONG_MAX):
return <long>integer
else:
return integer
return integer
else:
return number
elif lua_type == lua.LUA_TSTRING:
Expand Down Expand Up @@ -1632,7 +1600,7 @@ cdef int py_to_lua(LuaRuntime runtime, lua_State *L, object o, bint wrap_none=Fa
elif type(o) is float:
lua.lua_pushnumber(L, <lua.lua_Number>cpython.float.PyFloat_AS_DOUBLE(o))
pushed_values_count = 1
elif isinstance(o, (long, int)):
elif isinstance(o, int):
try:
lua.lua_pushinteger(L, <lua.lua_Integer>o)
pushed_values_count = 1
Expand Down Expand Up @@ -2013,7 +1981,7 @@ cdef void* _lua_alloc_restricted(void* ud, void* ptr, size_t old_size, size_t ne
return NULL
elif new_size == old_size:
return ptr

if memory_status.limit > 0 and new_size > old_size and memory_status.limit <= memory_status.used + new_size - old_size: # reached the limit
# print("REACHED LIMIT")
return NULL
Expand Down Expand Up @@ -2085,7 +2053,7 @@ cdef int py_object_gc_with_gil(py_object *py_obj, lua_State* L) noexcept with gi
return 0
finally:
py_obj.obj = NULL

cdef int py_object_gc(lua_State* L) noexcept nogil:
if not lua.lua_isuserdata(L, 1):
return 0
Expand Down
10 changes: 0 additions & 10 deletions lupa/lock.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@
from cpython cimport pythread

cdef extern from *:
# Compatibility definitions for Python
"""
#if PY_VERSION_HEX >= 0x030700a2
typedef unsigned long pythread_t;
#else
typedef long pythread_t;
#endif
"""

# Just let Cython understand that pythread_t is
# a long type, but be aware that it is actually
# signed for versions of Python prior to 3.7.0a2 and
# unsigned for later versions
ctypedef unsigned long pythread_t


Expand Down
5 changes: 5 additions & 0 deletions lupa/tests/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if __name__ == '__main__':
import sys
import unittest
from . import suite
sys.exit(1 if unittest.TextTestRunner(verbosity=2).run(suite()).failures else 0)
2 changes: 1 addition & 1 deletion lupa/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2911,7 +2911,7 @@ def test_all_types(self):
if objtype not in {'number', 'string'}:
self.assertIncorrect('python.args{[kwargs["%s"]] = true}' % objtype,
regex='table key is neither an integer nor a string')

def test_kwargs_merge(self):
self.assertResult('python.args{1, a=1}, python.args{2}, python.args{}, python.args{b=2}', (1, 2), dict(a=1, b=2))

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["Cython>=3.0.9", "setuptools<72.0.0", "wheel"]
requires = ["Cython>=3.0.11,<3.1", "setuptools<72.0.0", "wheel"]

[tool.cibuildwheel]
build-verbosity = 2
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Cython>=3.0.9
Cython>=3.0.11,<3.1
setuptools<72.0.0
wheel
33 changes: 0 additions & 33 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ def cmd_output(command):


def decode_path_output(s):
if sys.version_info[0] < 3:
return s # no need to decode, and safer not to do it
# we don't really know in which encoding pkgconfig
# outputs its results, so we try to guess
for encoding in (sys.getfilesystemencoding(),
Expand Down Expand Up @@ -365,9 +363,6 @@ def has_option(name):
# http://t-p-j.blogspot.com/2010/11/lupa-on-os-x-with-macports-python-26.html
# LuaJIT 2.1-alpha3 fails at runtime.
or (platform == 'darwin' and 'luajit' in os.path.basename(lua_bundle_path.rstrip(os.sep)))
# Couldn't get the Windows build to work. See
# https://luajit.org/install.html#windows
or (get_machine() != "AMD64" and get_machine() != "x86_64" and 'luajit' in os.path.basename(lua_bundle_path.rstrip(os.sep)))
# Let's restrict LuaJIT to x86_64 for now.
or (get_machine() not in ("x86_64", "AMD64") and 'luajit' in os.path.basename(lua_bundle_path.rstrip(os.sep)))
)
Expand Down Expand Up @@ -422,34 +417,6 @@ def prepare_extensions(use_cython=True):
if cythonize is not None:
ext_modules = cythonize(ext_modules)

# Fix compiler warning due to missing pragma-push in Cython 3.0.9.
for ext in ext_modules:
for source_file in ext.sources:
if not os.path.basename(source_file).startswith('lua') or not source_file.endswith('.c'):
continue
with open(source_file, 'rb') as f:
lines = f.readlines()
if b'Generated by Cython 3.0.9' not in lines[0]:
continue

modified = False
temp_file = source_file + ".tmp"
with open(temp_file, 'wb') as f:
last_was_push = False
for line in lines:
if b'#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"' in line and not last_was_push:
f.write(b"#pragma GCC diagnostic push\n")
modified = True
last_was_push = b'#pragma GCC diagnostic push' in line
f.write(line)

if modified:
print("Fixed Cython 3.0.9 generated source file " + source_file)
os.unlink(source_file)
os.rename(temp_file, source_file)
else:
os.unlink(temp_file)

return ext_modules, ext_libraries


Expand Down
2 changes: 1 addition & 1 deletion third-party/lua54
2 changes: 1 addition & 1 deletion third-party/luajit20
Submodule luajit20 updated from 4a2205 to e2e0b1
2 changes: 1 addition & 1 deletion third-party/luajit21
Submodule luajit21 updated from 93e879 to f73e64
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ passenv=
SETUP_OPTIONS
commands=
{envpython} setup.py --with-cython {env:SETUP_OPTIONS:} build install
{envpython} setup.py test
{envpython} -m lupa.tests.__main__
sitepackages=False

0 comments on commit 5b15e04

Please sign in to comment.