OLD | NEW |
1 # Python bindings for Yasm: Pyrex input file for bytecode.h | 1 # Python bindings for Yasm: Pyrex input file for bytecode.h |
2 # | 2 # |
3 # Copyright (C) 2006 Michael Urman, Peter Johnson | 3 # Copyright (C) 2006 Michael Urman, Peter Johnson |
4 # | 4 # |
5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
6 # modification, are permitted provided that the following conditions | 6 # modification, are permitted provided that the following conditions |
7 # are met: | 7 # are met: |
8 # 1. Redistributions of source code must retain the above copyright | 8 # 1. Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # 2. Redistributions in binary form must reproduce the above copyright | 10 # 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 10 matching lines...) Expand all Loading... |
21 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 21 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
22 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 22 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
23 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 23 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
24 # POSSIBILITY OF SUCH DAMAGE. | 24 # POSSIBILITY OF SUCH DAMAGE. |
25 | 25 |
26 cdef class Bytecode: | 26 cdef class Bytecode: |
27 cdef yasm_bytecode *bc | 27 cdef yasm_bytecode *bc |
28 | 28 |
29 cdef object __weakref__ # make weak-referenceable | 29 cdef object __weakref__ # make weak-referenceable |
30 | 30 |
31 def __new__(self, bc): | 31 def __cinit__(self, bc): |
32 self.bc = NULL | 32 self.bc = NULL |
33 if PyCObject_Check(bc): | 33 if PyCObject_Check(bc): |
34 self.bc = <yasm_bytecode *>__get_voidp(bc, Bytecode) | 34 self.bc = <yasm_bytecode *>__get_voidp(bc, Bytecode) |
35 else: | 35 else: |
36 raise NotImplementedError | 36 raise NotImplementedError |
37 | 37 |
38 def __dealloc__(self): | 38 def __dealloc__(self): |
39 # Only free if we're not part of a section; if we're part of a section | 39 # Only free if we're not part of a section; if we're part of a section |
40 # the section takes care of freeing the bytecodes. | 40 # the section takes care of freeing the bytecodes. |
41 if self.bc.section == NULL: | 41 if self.bc.section == NULL: |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 bc = yasm_bc_create_org(start, line, value) | 98 bc = yasm_bc_create_org(start, line, value) |
99 obj = Bytecode.__new__(cls, __pass_voidp(bc, Bytecode)) | 99 obj = Bytecode.__new__(cls, __pass_voidp(bc, Bytecode)) |
100 __bytecode_map[PyCObject_FromVoidPtr(bc, NULL)] = obj | 100 __bytecode_map[PyCObject_FromVoidPtr(bc, NULL)] = obj |
101 return obj | 101 return obj |
102 __org__new__ = staticmethod(__org__new__) | 102 __org__new__ = staticmethod(__org__new__) |
103 class Org(Bytecode): | 103 class Org(Bytecode): |
104 __new__ = __org__new__ | 104 __new__ = __org__new__ |
105 | 105 |
106 | 106 |
107 #cdef class Section: | 107 #cdef class Section: |
OLD | NEW |