forked from davisp/python-spidermonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashcobj.c
More file actions
103 lines (88 loc) · 2.65 KB
/
Copy pathhashcobj.c
File metadata and controls
103 lines (88 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Copyright 2009 Paul J. Davis <paul.joseph.davis@gmail.com>
*
* This file is part of the python-spidermonkey package released
* under the MIT license.
*
*/
#include "spidermonkey.h"
PyObject*
HashCObj_FromVoidPtr(void *cobj)
{
HashCObj* self = NULL;
self = PyObject_NEW(HashCObj, HashCObjType);
if(self == NULL) goto error;
self->cobj = cobj;
goto success;
error:
success:
return (PyObject*) self;
}
void*
HashCObj_AsVoidPtr(PyObject* self)
{
return ((HashCObj*)self)->cobj;
}
int
HashCObj_cmp(PyObject* self, PyObject* other)
{
int ret = -1;
if(!PyObject_TypeCheck(self, HashCObjType))
{
PyErr_SetString(PyExc_ValueError, "Invalid comparison object.");
goto error;
}
if(!PyObject_TypeCheck(other, HashCObjType))
{
PyErr_SetString(PyExc_ValueError, "Invalid comparison object 2.");
goto error;
}
if(((HashCObj*)self)->cobj == ((HashCObj*)other)->cobj)
{
ret = 0;
}
else
{
ret = 1;
}
goto success;
error:
success:
return ret;
}
PyObject*
HashCObj_repr(PyObject* self)
{
return PyString_FromFormat("<%s Ptr: %p>",
self->ob_type->tp_name,
((HashCObj*)self)->cobj);
}
long
HashCObj_hash(HashCObj* self)
{
return _Py_HashPointer(self->cobj);
}
PyTypeObject _HashCObjType = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"spidermonkey._HashCObj", /*tp_name*/
sizeof(HashCObj), /*tp_basicsize*/
0, /*tp_itemsize*/
0, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
(cmpfunc)HashCObj_cmp, /*tp_compare*/
(reprfunc)HashCObj_repr, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
(hashfunc)HashCObj_hash, /*tp_hash*/
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
0, /*tp_flags*/
"Internal hashing object.", /*tp_doc*/
};