ctypes
play

ctypes Direct access to happiness.dll Mike C. Fletcher VRPlumber - PowerPoint PPT Presentation

ctypes Direct access to happiness.dll Mike C. Fletcher VRPlumber Consulting Inc. Who is this guy PyOpenGL lead developer (other stuff too) OpenGLContext, SimpleParse, StarPy, TTFQuery, BasicProperty, PyDispatcher (and a consultant on


  1. ctypes Direct access to happiness.dll Mike C. Fletcher – VRPlumber Consulting Inc.

  2. Who is this guy PyOpenGL lead developer (other stuff too) OpenGLContext, SimpleParse, StarPy, TTFQuery, BasicProperty, PyDispatcher (and a consultant on VoIP and other stuff) Mike C. Fletcher – VRPlumber Consulting Inc.

  3. What I've done lately Rewrote PyOpenGL from SWIG to ctypes (Why?) Mike C. Fletcher – VRPlumber Consulting Inc.

  4. Python will be faster Mike C. Fletcher – VRPlumber Consulting Inc.

  5. Because it must The language is fine We need speed to expand into new areas (e.g. games) Mike C. Fletcher – VRPlumber Consulting Inc.

  6. Or PyPy will replace it Or IronPython Or OLPC-Python Or Parrot Or something else... Mike C. Fletcher – VRPlumber Consulting Inc.

  7. (And no...) We really don't care about a new print syntax Mike C. Fletcher – VRPlumber Consulting Inc.

  8. As Python accellerates We can think about replacing C (Particularly C extensions) Mike C. Fletcher – VRPlumber Consulting Inc.

  9. Extensions were about Speed (zoom, zoom) Mike C. Fletcher – VRPlumber Consulting Inc.

  10. But also Pre-written libraries of code Mike C. Fletcher – VRPlumber Consulting Inc.

  11. When s Python ~= s C (Get working on this peoples) Mike C. Fletcher – VRPlumber Consulting Inc.

  12. We still need Access to pre-written libraries of code (From pure Python) Mike C. Fletcher – VRPlumber Consulting Inc.

  13. Lucky we already have it It's been around for years Mike C. Fletcher – VRPlumber Consulting Inc.

  14. Hacker's ctypes (old school) >>> import ctypes >>> happiness = ctypes.cdll.LoadLibrary( './happiness.so' ) >>> happiness.hello( 'Hello world %i\n', 42 ) Hello world 42 15 # return value Mike C. Fletcher – VRPlumber Consulting Inc.

  15. Yawn (In a mind blowingly “cool” sort of way) Mike C. Fletcher – VRPlumber Consulting Inc.

  16. That is so 2004 Just a hacker's toy Mike C. Fletcher – VRPlumber Consulting Inc.

  17. But it was COOL We could poke deep in the machine Twiddle random bits Make things happen Mike C. Fletcher – VRPlumber Consulting Inc.

  18. Um, we said “Yawn” Hacker's backwater for years (No-one really cared) Mike C. Fletcher – VRPlumber Consulting Inc.

  19. What's different? Standard library inclusion Mike C. Fletcher – VRPlumber Consulting Inc.

  20. What's different? Automated code generation Mike C. Fletcher – VRPlumber Consulting Inc.

  21. What's different? PyPy support Mike C. Fletcher – VRPlumber Consulting Inc.

  22. What's different? Numpy Support Mike C. Fletcher – VRPlumber Consulting Inc.

  23. What's different? Bigger projects possible Mike C. Fletcher – VRPlumber Consulting Inc.

  24. Bigger, you say? Comtypes Pygame-ctypes Pyglet PyOpenGL Mike C. Fletcher – VRPlumber Consulting Inc.

  25. PyOpenGL Scale 2189 C functions 3475 constant definitions 262 extension modules 6 possible core versions Mike C. Fletcher – VRPlumber Consulting Inc.

  26. Where we came from 1.x Manual Wrapping 2.x SWIG Wrapping with custom distutils Mike C. Fletcher – VRPlumber Consulting Inc.

  27. 1.x died years ago Manual wrapping way too time consuming (This is where I came into the picture, life support for a dying project) Mike C. Fletcher – VRPlumber Consulting Inc.

  28. Really No one wants to code in C Mike C. Fletcher – VRPlumber Consulting Inc.

  29. The promised land SWIG (Tarn decided to use this to rewrite the project) Mike C. Fletcher – VRPlumber Consulting Inc.

  30. Macro headaches Level upon levels of macro expansion SWIG typemaps, SWIG macros, macros, macro- expanded utility libraries (Easy to write, extremely difficult to maintain) Mike C. Fletcher – VRPlumber Consulting Inc.

  31. C compilation problems Complex build process Edit/compile/run cycle of 20 minutes+ Togl build procedure constantly broken No compiler on one platform Mike C. Fletcher – VRPlumber Consulting Inc.

  32. Developer fatigue No one wanted to do the day-to-day stuff (Because it was such a pain) Mike C. Fletcher – VRPlumber Consulting Inc.

  33. Few joined, none stayed Figuring out how to start was way too hard Mike C. Fletcher – VRPlumber Consulting Inc.

  34. So I was going to dump PyOpenGL Wasn't enough fun to spend my free time on it Mike C. Fletcher – VRPlumber Consulting Inc.

  35. Won't someone think of the users? 70+ downloads a day (outside the distributions or applications) Mike C. Fletcher – VRPlumber Consulting Inc.

  36. Won't someone think of the users? Hundreds, maybe thousands of applications (Science, extension systems, graphic libraries) Mike C. Fletcher – VRPlumber Consulting Inc.

  37. We should try ctypes (Rene suggested it IIRC) Mike C. Fletcher – VRPlumber Consulting Inc.

  38. First tests Could create C-like API easily with custom (hacky) auto-generation Mike C. Fletcher – VRPlumber Consulting Inc.

  39. But it wasn't compatible So I ignored it for a while (And things got worse) Mike C. Fletcher – VRPlumber Consulting Inc.

  40. Second tests Not “can we wrap OpenGL” “Can we create PyOpenGL” Mike C. Fletcher – VRPlumber Consulting Inc.

  41. The goal Fully compatible with PyOpenGL 2.x (reasonably compatible) With half a dozen new fixes/features Full extension coverage Mike C. Fletcher – VRPlumber Consulting Inc.

  42. A few bugs early on AMD64 platform issues, mostly Mike C. Fletcher – VRPlumber Consulting Inc.

  43. But we could make it work So we did Mike C. Fletcher – VRPlumber Consulting Inc.

  44. Array handling 3 different array systems (now pluggable) Fairly trivial, it turns out (Even easier now) Mike C. Fletcher – VRPlumber Consulting Inc.

  45. No high-level automation No automated type/name matching (Yay, wrote it in Python) Mike C. Fletcher – VRPlumber Consulting Inc.

  46. Library loading Platform specific (no big deal) Needs to be available (hmm) Needs to be dynamic library Mike C. Fletcher – VRPlumber Consulting Inc.

  47. No C++ We don't care, others will Mike C. Fletcher – VRPlumber Consulting Inc.

  48. Macro problems We don't have a lot of them Just hacked around them in Python Mike C. Fletcher – VRPlumber Consulting Inc.

  49. Speed problems 2-5x slower (Delicious irony of slowing down to speed up) Mike C. Fletcher – VRPlumber Consulting Inc.

  50. Documentation Not as extensive as you'd want Mike C. Fletcher – VRPlumber Consulting Inc.

  51. What we got Mike C. Fletcher – VRPlumber Consulting Inc.

  52. No C coding No one wants to code in C Mike C. Fletcher – VRPlumber Consulting Inc.

  53. Lower barrier to entry Hack from day one Mike C. Fletcher – VRPlumber Consulting Inc.

  54. Easier to contribute Developer's “hacks” integrate easily Mike C. Fletcher – VRPlumber Consulting Inc.

  55. Easier to install easy_install PyOpenGL Mike C. Fletcher – VRPlumber Consulting Inc.

  56. Easier to build (do nothing) Mike C. Fletcher – VRPlumber Consulting Inc.

  57. Easier to debug Walk through the whole wrapping process Mike C. Fletcher – VRPlumber Consulting Inc.

  58. More coverage Core library 1.3 through 2.0 (automatic) All registered extensions Silly little regex script creates them (Pyglet guys have a more advanced wrapper) Mike C. Fletcher – VRPlumber Consulting Inc.

  59. New features Pluggable data-format support Optional logged operation Run-time binding (dll substitution) Mike C. Fletcher – VRPlumber Consulting Inc.

  60. Compatible Some users don't even realise it's a new technology, it's just “3.0” Mike C. Fletcher – VRPlumber Consulting Inc.

  61. We're future-facing again Type inferencing ready Mike C. Fletcher – VRPlumber Consulting Inc.

  62. We're future-facing again PyPy ready Mike C. Fletcher – VRPlumber Consulting Inc.

  63. We're future-facing again Numpy compatible (pluggable data-types throughout) Mike C. Fletcher – VRPlumber Consulting Inc.

  64. I'm motivated again Development is fun Mike C. Fletcher – VRPlumber Consulting Inc.

  65. Why ctypes? You have libraries in C you want to use (Loadable libraries without many macros) Mike C. Fletcher – VRPlumber Consulting Inc.

  66. Why ctypes? You want to code in Python (No-one wants to code in C) Mike C. Fletcher – VRPlumber Consulting Inc.

  67. Why ctypes? You want to avoid users having to compile your code (Drop a pure-Python .egg) Mike C. Fletcher – VRPlumber Consulting Inc.

  68. You want to code Python Because Python is fun (and no-one wants to code in C) Mike C. Fletcher – VRPlumber Consulting Inc.

  69. Why ctypes? Because you want to load happiness.dll into your namespace Mike C. Fletcher – VRPlumber Consulting Inc.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend