systemfuncs.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. class SystemFunction(object):
  2. name = None
  3. @classmethod
  4. def getFunctionName(cls):
  5. return cls.name
  6. @classmethod
  7. def getMakeName(cls):
  8. return cls.name.upper()
  9. @classmethod
  10. def iterHeaders(cls, targetPlatform):
  11. raise NotImplementedError
  12. class FTruncateFunction(SystemFunction):
  13. name = 'ftruncate'
  14. @classmethod
  15. def iterHeaders(cls, targetPlatform):
  16. yield '<unistd.h>'
  17. class MMapFunction(SystemFunction):
  18. name = 'mmap'
  19. @classmethod
  20. def iterHeaders(cls, targetPlatform):
  21. if targetPlatform in ('darwin', 'openbsd'):
  22. yield '<sys/types.h>'
  23. yield '<sys/mman.h>'
  24. class PosixMemAlignFunction(SystemFunction):
  25. name = 'posix_memalign'
  26. @classmethod
  27. def iterHeaders(cls, targetPlatform):
  28. yield '<stdlib.h>'
  29. class NftwFunction(SystemFunction):
  30. name = 'nftw'
  31. @classmethod
  32. def iterHeaders(cls, targetPlatform):
  33. yield '<ftw.h>'
  34. # Build a list of system functions using introspection.
  35. def _discoverSystemFunctions(localObjects):
  36. for obj in localObjects:
  37. if isinstance(obj, type) and issubclass(obj, SystemFunction):
  38. if obj is not SystemFunction:
  39. yield obj
  40. systemFunctions = list(_discoverSystemFunctions(locals().itervalues()))