exaloop / codon

A high-performance, zero-overhead, extensible Python compiler using LLVM
https://docs.exaloop.io/codon
Other
13.96k stars 498 forks source link

Segmentation fault when using OrderedDict #423

Closed aresper closed 11 months ago

aresper commented 11 months ago

In the following sample code, I try to convert a Dict to an OrderedDict, but I get a segmentation fault when compiling:

import python
from python import collections
from typing import Dict, List, Union
import sys

def initializeJobGraph(in_events_dict: Dict[int, List[Dict[str, Union[str, int]]]]) -> Dict[int, List[Dict[str, Union[str, int]]]]:

    in_events_dict[10000].append({'event': Union[int, str]("release"), 'job_id': Union[int, str](1)})

    # build ordered event dict
    ordered_event_dict_tmp = collections.OrderedDict(in_events_dict)

    return ordered_event_dict_tmp

def main(arg1: str, arg2: str) -> None:

    events_dict = Dict[int, List[Dict[str, Union[str, int]]]]()
    ordered_event_dict = Dict[int, List[Dict[str, Union[str, int]]]]()

    ordered_event_dict = initializeJobGraph(events_dict)

if __name__ == "__main__":

    arg1 = sys.argv[1]
    arg2 = sys.argv[2]
    main(arg1, arg2)

I think there is some mismatch in the data types that is causing the issue. Any ideas?

elisbyberi commented 11 months ago

@aresper You don't need to predefine the type of the same variable everywhere. Variable is passed by reference (pointer).

def initializeJobGraph(in_events_dict): in_events_dict[10000] = List[Dict[str, Union[str, int]]]() in_events_dict[10000].append({ 'event': Unionint, str, 'job_id': Unionint, str })

# build ordered event dict
return collections.OrderedDict(in_events_dict)

def main(arg1: str, arg2: str) -> None: events_dict = Dict[int, List[Dict[str, Union[str, int]]]]() ordered_event_dict = initializeJobGraph(events_dict)

print(type(ordered_event_dict) is Dict[int, List[Dict[str, Union[str, int]]]])  # False
print(type(ordered_event_dict) is pyobj)  # True

print(ordered_event_dict)

if name == "main": arg1 = sys.argv[1] arg2 = sys.argv[2] main(arg1, arg2)

aresper commented 11 months ago

Great, thanks! The overall compilation of my framework is now successful.

I am now trying to run, but I am getting problems with the python libs.

I am checking the procedure here: https://docs.exaloop.io/codon/interoperability/python

I seems that only Python 3.6 and later are supported. Unfortunately my environment is a bit old an complex and I still have Python 3.5. I guess I will to install a later version and update CODON_PYTHON variable. I tried with 3.5 and below is the error I get. Any hints or the the above procedure should solve the issue?

me@desktop:~/Python-sandbox/23-07-01-codon-typecheck-fix$ ./main_0_0 0 0
CError: /usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/libpython3.5.so: undefined symbol: PySlice_Unpack

Raised from: std.internal.dlopen.dlsym.2:0
/home/alexandre/.codon/lib/codon/stdlib/internal/dlopen.codon:42:9
aresper commented 11 months ago

Performed python3.6 installation, but now I get a different error. Raised a different issue to track: https://github.com/exaloop/codon/issues/427