PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/py2exe/source/mktab.py

https://bitbucket.org/briancurtin/py2exe3
Python | 102 lines | 97 code | 2 blank | 3 comment | 4 complexity | b2f2c1b4faf92fb83a038fc02dd85370 MD5 | raw file
  1. # A script to generate helper files for dynamic linking to the Python dll
  2. #
  3. decls = '''
  4. void, Py_Initialize, (void)
  5. int, PyRun_SimpleString, (char *)
  6. void, Py_Finalize, (void)
  7. char *, Py_GetPath, (void)
  8. void, Py_SetPythonHome, (char *)
  9. void, Py_SetProgramName, (char *)
  10. PyObject *, PyMarshal_ReadObjectFromString, (char *, Py_ssize_t)
  11. PyObject *, PyObject_CallFunction, (PyObject *, char *, ...)
  12. int, PyString_AsStringAndSize, (PyObject *, char **, Py_ssize_t *)
  13. char *, PyString_AsString, (PyObject *)
  14. int, PyArg_ParseTuple, (PyObject *, char *, ...)
  15. PyObject *, PyErr_Format, (PyObject *, const char *, ...)
  16. PyObject *, PyImport_ImportModule, (char *)
  17. PyObject *, PyInt_FromLong, (long)
  18. long, PyInt_AsLong, (PyObject *)
  19. PyObject *, PyLong_FromVoidPtr, (void *)
  20. PyObject *, Py_InitModule4, (char *, PyMethodDef *, char *, PyObject *, int)
  21. PyObject *, PyTuple_New, (Py_ssize_t)
  22. int, PyTuple_SetItem, (PyObject*, Py_ssize_t, PyObject *)
  23. int, Py_IsInitialized, (void)
  24. int, PyObject_SetAttrString, (PyObject *, char *, PyObject *)
  25. PyObject *, PyCFunction_NewEx, (PyMethodDef *, PyObject *, PyObject *)
  26. PyObject *, PyObject_GetAttrString, (PyObject *, char *)
  27. PyObject *, Py_BuildValue, (char *, ...)
  28. PyObject *, PyObject_Call, (PyObject *, PyObject *, PyObject *)
  29. void, PySys_WriteStderr, (const char *, ...)
  30. PyObject *, PyErr_Occurred, (void)
  31. void, PyErr_Clear, (void)
  32. int, PyObject_IsInstance, (PyObject *, PyObject *)
  33. PyObject, PyInt_Type
  34. PyObject, _Py_NoneStruct
  35. PyObject *, PyExc_ImportError
  36. char *, _Py_PackageContext
  37. PyGILState_STATE, PyGILState_Ensure, (void)
  38. void, PyGILState_Release, (PyGILState_STATE)
  39. void, PySys_SetObject, (char *, PyObject *)
  40. PyObject *, PySys_GetObject, (char *)
  41. PyObject *, PyString_FromString, (char *)
  42. int, Py_FdIsInteractive, (FILE *, char *)
  43. int, PyRun_InteractiveLoop, (FILE *, char *)
  44. void, PySys_SetArgv, (int, char **)
  45. PyObject *, PyImport_AddModule, (char *)
  46. PyObject *, PyModule_GetDict, (PyObject *)
  47. Py_ssize_t, PySequence_Length, (PyObject *)
  48. PyObject *, PySequence_GetItem, (PyObject *, Py_ssize_t)
  49. //int, PyCode_Check, (PyObject *)
  50. PyObject *, PyEval_EvalCode, (PyCodeObject *, PyObject *, PyObject *)
  51. void, PyErr_Print, (void)
  52. PyObject *, PyBool_FromLong, (long)
  53. int, Py_VerboseFlag
  54. int, Py_NoSiteFlag
  55. int, Py_OptimizeFlag
  56. int, Py_IgnoreEnvironmentFlag
  57. PyObject *, PyObject_Str, (PyObject *)
  58. PyObject *, PyList_New, (Py_ssize_t)
  59. int, PyList_SetItem, (PyObject *, Py_ssize_t, PyObject *)
  60. int, PyList_Append, (PyObject *, PyObject *)
  61. '''.strip().splitlines()
  62. import string
  63. hfile = open("import-tab.h", "w")
  64. cfile = open("import-tab.c", "w")
  65. index = 0
  66. for decl in decls:
  67. if not decl or decl.startswith("//"):
  68. continue
  69. items = decl.split(',', 2)
  70. if len(items) == 3:
  71. # exported function with argument list
  72. restype, name, argtypes = map(string.strip, items)
  73. print >> hfile, '#define %(name)s ((%(restype)s(*)%(argtypes)s)imports[%(index)d].proc)' % locals()
  74. elif len(items) == 2:
  75. # exported data
  76. typ, name = map(string.strip, items)
  77. print >> hfile, '#define %(name)s (*(%(typ)s(*))imports[%(index)s].proc)' % locals()
  78. else:
  79. raise ValueError, "could not parse %r" % decl
  80. if name == "Py_InitModule4":
  81. print >> cfile, '#ifdef _DEBUG'
  82. print >> cfile, '\t{ "Py_InitModule4TraceRefs", NULL },' % locals()
  83. print >> cfile, '#else'
  84. print >> cfile, '# if defined (_WIN64)'
  85. print >> cfile, '\t{ "Py_InitModule4_64", NULL },' % locals()
  86. print >> cfile, '# else'
  87. print >> cfile, '\t{ "Py_InitModule4", NULL },' % locals()
  88. print >> cfile, '# endif'
  89. print >> cfile, '#endif'
  90. else:
  91. print >> cfile, '\t{ "%(name)s", NULL },' % locals()
  92. index += 1
  93. hfile.close()
  94. cfile.close()