(context)
| 91 | |
| 92 | |
| 93 | def getCodeObjectsInitCode(context): |
| 94 | # There is a bit of details to this, and we are making some optimizations as |
| 95 | # well as customization to what path should be put there. |
| 96 | |
| 97 | if isExperimental("new-code-objects"): |
| 98 | return () |
| 99 | |
| 100 | statements = [] |
| 101 | |
| 102 | code_objects = context.getCodeObjects() |
| 103 | |
| 104 | # Create the always identical, but dynamic filename first thing. |
| 105 | module_filename = context.getOwner().getRunTimeFilename() |
| 106 | |
| 107 | # We do not care about release of this object, as code object live |
| 108 | # forever anyway. |
| 109 | if getFileReferenceMode() == "frozen" or os.path.isabs(module_filename): |
| 110 | template = "module_filename_obj = %s; CHECK_OBJECT(module_filename_obj);" |
| 111 | else: |
| 112 | template = "module_filename_obj = MAKE_RELATIVE_PATH(%s); CHECK_OBJECT(module_filename_obj);" |
| 113 | |
| 114 | if str is bytes and type(module_filename) is unicode: |
| 115 | module_filename = module_filename.encode("utf8") |
| 116 | |
| 117 | # The code object will not work from any other type, cannot be e.g. unicode. |
| 118 | assert type(module_filename) is str, (type(module_filename), module_filename) |
| 119 | |
| 120 | statements.append(template % (context.getConstantCode(constant=module_filename))) |
| 121 | |
| 122 | for code_object_key, code_identifier in code_objects: |
| 123 | # Make sure the filename is always identical. |
| 124 | assert code_object_key.co_filename == module_filename, code_object_key |
| 125 | |
| 126 | args = ( |
| 127 | code_identifier, |
| 128 | ", ".join(str(s) for s in _getMakeCodeObjectArgs(code_object_key, context)), |
| 129 | ) |
| 130 | |
| 131 | code = "%s = MAKE_CODE_OBJECT(module_filename_obj, %s);" % args |
| 132 | |
| 133 | statements.append(code) |
| 134 | |
| 135 | if context.getOwner().getFullName() == "__main__": |
| 136 | if code_object_key[1] == "<module>": |
| 137 | statements.append("code_objects_main = %s;" % code_identifier) |
| 138 | |
| 139 | return statements |
| 140 | |
| 141 | |
| 142 | def getCodeObjectAccessCode(code_object, context): |
no test coverage detected
searching dependent graphs…