Mercurial > pymonkey
annotate object.c @ 21:fc04e5f1c675
Changed object constructor to take a context instead of a runtime.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sun, 28 Jun 2009 20:40:18 -0700 |
parents | f3223debd70b |
children | 988a8998c75f |
rev | line source |
---|---|
13 | 1 #include "object.h" |
21
fc04e5f1c675
Changed object constructor to take a context instead of a runtime.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
2 #include "runtime.h" |
13 | 3 |
4 JSClass PYM_JS_ObjectClass = { | |
5 "PymonkeyObject", JSCLASS_GLOBAL_FLAGS, | |
6 JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, | |
7 JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub, | |
8 JSCLASS_NO_OPTIONAL_MEMBERS | |
9 }; | |
10 | |
11 static void | |
12 PYM_JSObjectDealloc(PYM_JSObject *self) | |
13 { | |
14 // JS_RemoveRoot() always returns JS_TRUE, so don't | |
15 // bother checking its return value. | |
16 | |
15
baa4cb961330
JS objects in python-land are now rooted while in python-land so that they're not gc'd while in python-land.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
17 if (self->obj) { |
baa4cb961330
JS objects in python-land are now rooted while in python-land so that they're not gc'd while in python-land.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
18 JS_RemoveRootRT(self->runtime->rt, &self->obj); |
baa4cb961330
JS objects in python-land are now rooted while in python-land so that they're not gc'd while in python-land.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
19 self->obj = NULL; |
baa4cb961330
JS objects in python-land are now rooted while in python-land so that they're not gc'd while in python-land.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
20 } |
baa4cb961330
JS objects in python-land are now rooted while in python-land so that they're not gc'd while in python-land.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
21 |
baa4cb961330
JS objects in python-land are now rooted while in python-land so that they're not gc'd while in python-land.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
22 Py_DECREF(self->runtime); |
baa4cb961330
JS objects in python-land are now rooted while in python-land so that they're not gc'd while in python-land.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
23 self->runtime = NULL; |
13 | 24 } |
25 | |
26 PyTypeObject PYM_JSObjectType = { | |
27 PyObject_HEAD_INIT(NULL) | |
28 0, /*ob_size*/ | |
29 "pymonkey.Object", /*tp_name*/ | |
30 sizeof(PYM_JSObject), /*tp_basicsize*/ | |
31 0, /*tp_itemsize*/ | |
32 /*tp_dealloc*/ | |
33 (destructor) PYM_JSObjectDealloc, | |
34 0, /*tp_print*/ | |
35 0, /*tp_getattr*/ | |
36 0, /*tp_setattr*/ | |
37 0, /*tp_compare*/ | |
38 0, /*tp_repr*/ | |
39 0, /*tp_as_number*/ | |
40 0, /*tp_as_sequence*/ | |
41 0, /*tp_as_mapping*/ | |
42 0, /*tp_hash */ | |
43 0, /*tp_call*/ | |
44 0, /*tp_str*/ | |
45 0, /*tp_getattro*/ | |
46 0, /*tp_setattro*/ | |
47 0, /*tp_as_buffer*/ | |
48 Py_TPFLAGS_DEFAULT, /*tp_flags*/ | |
49 /* tp_doc */ | |
50 "JavaScript Object.", | |
51 0, /* tp_traverse */ | |
52 0, /* tp_clear */ | |
53 0, /* tp_richcompare */ | |
54 0, /* tp_weaklistoffset */ | |
55 0, /* tp_iter */ | |
56 0, /* tp_iternext */ | |
57 0, /* tp_methods */ | |
58 0, /* tp_members */ | |
59 0, /* tp_getset */ | |
60 0, /* tp_base */ | |
61 0, /* tp_dict */ | |
62 0, /* tp_descr_get */ | |
63 0, /* tp_descr_set */ | |
64 0, /* tp_dictoffset */ | |
65 0, /* tp_init */ | |
66 0, /* tp_alloc */ | |
67 0, /* tp_new */ | |
68 }; | |
18
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
69 |
21
fc04e5f1c675
Changed object constructor to take a context instead of a runtime.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
70 PYM_JSObject *PYM_newJSObject(PYM_JSContextObject *context, |
18
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
71 JSObject *obj) { |
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
72 PYM_JSObject *object = PyObject_New(PYM_JSObject, |
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
73 &PYM_JSObjectType); |
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
74 if (object == NULL) |
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
75 return NULL; |
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
76 |
21
fc04e5f1c675
Changed object constructor to take a context instead of a runtime.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
77 object->runtime = context->runtime; |
18
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
78 Py_INCREF(object->runtime); |
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
79 |
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
80 object->obj = obj; |
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
81 |
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
82 JS_AddNamedRootRT(object->runtime->rt, &object->obj, |
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
83 "Pymonkey-Generated Object"); |
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
84 |
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
85 return object; |
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
86 } |