Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hpy 0.0.4 and c++ #1

Open
wants to merge 6 commits into
base: hpy-1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Cython/Compiler/Backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,13 @@ def put_init_code(code):
code.putln("#define __PYX_NONE %s" % CApiBackend.pynone)
code.putln("#define __PYX_NONE_NEW %s" % CApiBackend.get_none())
for k in CombinedBackend.hpy_functions:
code.putln("#define %s %s" % (CombinedBackend.hpy_functions[k], CApiBackend.py_functions[k]))
code.putln("#define %s %s" % (
CombinedBackend.hpy_functions[k], CApiBackend.py_functions[k],
))
code.putln("#define %s %s" % (
CombinedBackend.get_binary_operation_function(k, True),
CApiBackend.get_binary_operation_function(k, True),
))
CApiBackend.put_init_code(code)

code.putln("#else /* %s */" % hpy_guard)
Expand Down Expand Up @@ -628,7 +634,14 @@ def put_init_code(code):
code.putln("#define __PYX_NONE %s" % HPyBackend.pynone)
code.putln("#define __PYX_NONE_NEW %s" % HPyBackend.get_none())
for k in CombinedBackend.hpy_functions:
code.putln("#define %s %s" % (CombinedBackend.hpy_functions[k], HPyBackend.hpy_functions[k]))
code.putln("#define %s %s" % (
CombinedBackend.hpy_functions[k],
HPyBackend.hpy_functions[k],
))
code.putln("#define %s %s" % (
CombinedBackend.get_binary_operation_function(k, True),
HPyBackend.get_binary_operation_function(k, True),
))
code.putln("#endif /* %s */" % hpy_guard)

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions Cython/Compiler/Code.py
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@ def put_cached_builtin_init(self, pos, name, cname):
UtilityCode.load_cached("GetBuiltinName", "ObjectHandling.c"))
from .PyrexTypes import py_object_type
tmp_var = w.funcstate.allocate_temp(py_object_type, True)
w.putln('%s = %s; if (!%s) %s' % (
w.putln('%s = %s; if (%s) %s' % (
tmp_var,
backend.get_call('__Pyx_GetBuiltinNameFromGlobal', interned_cname),
backend.get_is_null_cond(tmp_var),
Expand Down Expand Up @@ -2314,7 +2314,7 @@ def put_var_xdecrefs_clear(self, entries):
def put_init_to_py_none(self, cname, type, nanny=True):
from .PyrexTypes import py_object_type, typecast
py_none = typecast(type, py_object_type, backend.pynone)
self.putln("%s = %s; %s;" % (cname, py_none, backend.get_newref(py_none, nanny=nanny)))
self.putln("%s = %s;" % (cname, backend.get_newref(py_none, nanny=nanny)))

def put_init_var_to_py_none(self, entry, template = "%s", nanny=True):
code = template % entry.cname
Expand Down
26 changes: 16 additions & 10 deletions Cython/Compiler/ModuleNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -3058,33 +3058,39 @@ def generate_module_init_func(self, imported_modules, env, code):
code.putln("#endif")

code.putln("/* initialise %s */" % Naming.empty_tuple)
code.putln("{")
tmp_empty_tuple_cname = Naming.temp_prefix + "empty_tuple"
code.putln("%s tuple_builder = %s;" % (
code.putln(" %s tuple_builder = %s;" % (
backend.tuple_builder_ctype, backend.get_call(backend.tuple_builder_new, "0")))
code.putln("%s %s = %s; %s" % (
code.putln(" %s %s = %s; %s" % (
backend.pyobject_ctype, tmp_empty_tuple_cname,
backend.get_call(backend.tuple_builder_build, "tuple_builder"),
code.error_goto_if_null(tmp_empty_tuple_cname, self.pos)))
code.putln("%s;" % backend.get_write_global(env.module_cname, Naming.empty_tuple, tmp_empty_tuple_cname))
code.putln("%s;" % backend.get_closeref(tmp_empty_tuple_cname, False, False))
code.putln(" %s;" % backend.get_write_global(env.module_cname, Naming.empty_tuple, tmp_empty_tuple_cname))
code.putln(" %s;" % backend.get_closeref(tmp_empty_tuple_cname, False, False))
code.putln("}")

tmp_empty_bytes_cname = Naming.temp_prefix + "empty_bytes"
code.putln("/* initialise %s */" % Naming.empty_bytes)
code.putln("%s %s = %s; %s" % (
code.putln("{")
code.putln(" %s %s = %s; %s" % (
backend.pyobject_ctype, tmp_empty_bytes_cname,
backend.get_call(backend.bytes_from_string_and_size, "\"\"", "0"),
code.error_goto_if_null(tmp_empty_bytes_cname, self.pos)))
code.putln("%s;" % backend.get_write_global(env.module_cname, Naming.empty_bytes, tmp_empty_bytes_cname))
code.putln("%s;" % backend.get_closeref(tmp_empty_bytes_cname, False, False))
code.putln(" %s;" % backend.get_write_global(env.module_cname, Naming.empty_bytes, tmp_empty_bytes_cname))
code.putln(" %s;" % backend.get_closeref(tmp_empty_bytes_cname, False, False))
code.putln("}")

tmp_empty_unicode_cname = Naming.temp_prefix + "empty_unicode"
code.putln("/* initialise %s */" % Naming.empty_unicode)
code.putln("%s %s = %s; %s" % (
code.putln("{")
code.putln(" %s %s = %s; %s" % (
backend.pyobject_ctype, tmp_empty_unicode_cname,
backend.get_call(backend.unicode_from_string, "\"\""),
code.error_goto_if_null(tmp_empty_unicode_cname, self.pos)))
code.putln("%s;" % backend.get_write_global(env.module_cname, Naming.empty_unicode, tmp_empty_unicode_cname))
code.putln("%s;" % backend.get_closeref(tmp_empty_unicode_cname, False, False))
code.putln(" %s;" % backend.get_write_global(env.module_cname, Naming.empty_unicode, tmp_empty_unicode_cname))
code.putln(" %s;" % backend.get_closeref(tmp_empty_unicode_cname, False, False))
code.putln("}")

# TODO(fa): currently not supported with the HPy backend
code.putln("#if !(%s)" % backend.hpy_guard)
Expand Down
1 change: 1 addition & 0 deletions Cython/Compiler/Nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3591,6 +3591,7 @@ def generate_function_definitions(self, env, code):
code.put_label(code.error_label)
for cname, type in code.funcstate.all_managed_temps():
code.put_xdecref(cname, type)
code.funcstate.release_temp(cname)
err_val = self.error_value()
if err_val is not None:
code.putln("%s = %s;" % (Naming.retval_cname, err_val))
Expand Down
2 changes: 1 addition & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
numpy
coverage
pycodestyle
git+https://github.com/hpyproject/hpy.git@0.0.3
hpy==0.0.4
4 changes: 2 additions & 2 deletions tests/memoryview/extension_type_memoryview.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_getitem():
"""
for i in range(view.shape[0]):
item = view[i]
print item.dummy
print(item.dummy)

def test_getitem_typed():
"""
Expand All @@ -33,4 +33,4 @@ def test_getitem_typed():
cdef ExtensionType item
for i in range(view.shape[0]):
item = view[i]
print item.dummy
print(item.dummy)