Add python3 support and improve ctypes wrapper#10
Conversation
We can just declare the enumerators and then the generated C code will use the values from dtrace.h
This commit changes the print statement to use a function and adds the python3 integer division operator. The str/bytes changes will be done in a follow-up change.
It's not currently used but can be useful to print information on which probe fired.
Explicitly set language_level=2 until the port to python3 is complete.
We have to open libdtrace.dylib not libdtrace.so
Also update tests since the callback function now receives a bytes object and not a string.
|
This is a rather large diff, I can split it up into multiple pull requests if needed. Otherwise I'd recommend looking at each of the individual commits rather than the full diff. |
Buffered output hanlding appears to be broken on macOS. The -B flag is disabled in dtrace.c () and compiling dtrace.c with that flag enabled results in the same crash that I see with python-dtrace: ``` * thread tmetsch#1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x7fb100000000) * frame #0: 0x00007fff6f83de52 libsystem_platform.dylib`_platform_strlen + 18 frame tmetsch#1: 0x00007fff6f6d9891 libsystem_c.dylib`__vfprintf + 5379 frame tmetsch#2: 0x00007fff6f6ffad3 libsystem_c.dylib`__v2printf + 475 frame tmetsch#3: 0x00007fff6f6e5ee7 libsystem_c.dylib`_vsnprintf + 417 frame tmetsch#4: 0x00007fff6f6e5f90 libsystem_c.dylib`vsnprintf + 68 frame tmetsch#5: 0x00007fff6d3650e3 libdtrace.dylib`dt_printf + 524 frame tmetsch#6: 0x00007fff6d33da7f libdtrace.dylib`dt_consume_cpu + 2536 frame tmetsch#7: 0x00007fff6d33c9e0 libdtrace.dylib`dtrace_consume + 1090 frame tmetsch#8: 0x00007fff6d366534 libdtrace.dylib`dtrace_work + 116 frame tmetsch#9: 0x000000010d6be9ff dtrace2`main(argc=4, argv=0x00007ffee2547250) at dtrace2.c:1834:17 frame tmetsch#10: 0x00007fff6f647cc9 libdyld.dylib`start + 1 ``` To work around this crash, output to stderr for now.
|
Thanks for this - this is great! Thanks for putting in the time to refactor this. Will need a bit of time to test this (by any chance did you check this on Solaris & FreeBSD & Mac?), but this certainly warrants a new release imho. Thanks again, and as usual - drinks on me once when we meet someday :-) |
I have some follow-up fixes for freebsd+macos that I will post as a PR after some minor cleanups. I don't have access to Solaris so I can only test FreeBSD+macOS (the latter appears to be broken right now). I've pushed the full set of changes to https://github.com/Cambridge-AdvancedOS/l41-python-dtrace/tree/python3 in case you'd like to have a look at them before I open the pr. |
|
Ok, that is great to know - I actually do not have access to a current Mac system. Will test this on Solaris so (y) |
|
Hey, quick Q - have you seen this error when running the simple example for the ctypes examples: |
|
I didn't run that example, but I can try running them all with py2+3 |
|
Seems to be an issue with how the data is provided to the callback. Looks like it is a byte array now, proper formatting fixes it. |
|
This is a "preview" branch of this PR - did some minor code style changes here and there. This seems to work on Solaris (OmniOS) atm with python 3. Need to check python 2 - once it is backward compatible will merge with the master branch or decide to make python 3 a requirement (it is EoY 2020 after all). https://github.com/tmetsch/python-dtrace/tree/arichardson-python3-support |
|
@tmetsch Thanks! I checked the hello world example with python2, but I can also make sure the other works for one last py2 release if you'd like? |
|
This looks all good - I did merge it into the master now. All examples did run with python 2 & 3 on OmniOS. So did the unittests etc. Thanks so much for this - this is awesome!! |
This pull requests allows building for python3 and add function
signatures to the ctypes wrapper.
Fixes #3
Fixes #4