Class: PyCall::PyPtr
- Inherits:
- BasicObject
- Includes:
- PP::ObjectMixin
- Defined in:
- lib/pycall/pretty_print.rb,
ext/pycall/pycall.c
Direct Known Subclasses
Constant Summary collapse
- NULL =
pycall_pyptr_new(NULL)
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #===(other) ⇒ Object
- #__address__ ⇒ Object
- #__ob_refcnt__ ⇒ Object
- #__ob_type__ ⇒ Object
- #class ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #initialize(val) ⇒ Object constructor
- #inspect ⇒ Object
- #is_a?(klass) ⇒ Boolean
- #kind_of?(klass) ⇒ Boolean
- #nil? ⇒ Boolean
- #none? ⇒ Boolean
- #null? ⇒ Boolean
- #object_id ⇒ Object
Constructor Details
#initialize(val) ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'ext/pycall/pycall.c', line 255 static VALUE pycall_pyptr_initialize(VALUE pyptr, VALUE val) { VALUE addr; PyObject *pyobj; addr = rb_check_to_integer(val, "to_int"); if (NIL_P(addr)) { rb_raise(rb_eTypeError, "Invalid PyObject address: %"PRIsVALUE, val); } pyobj = (PyObject *)NUM2PTR(addr); DATA_PTR(pyptr) = pyobj; return pyptr; } |
Class Method Details
.decref(pyptr) ⇒ Object
209 210 211 212 213 |
# File 'ext/pycall/pycall.c', line 209 static VALUE pycall_pyptr_s_decref(VALUE klass, VALUE pyptr) { return pycall_pyptr_decref(pyptr); } |
.incref(pyptr) ⇒ Object
178 179 180 181 182 |
# File 'ext/pycall/pycall.c', line 178 static VALUE pycall_pyptr_s_incref(VALUE klass, VALUE pyptr) { return pycall_pyptr_incref(pyptr); } |
.sizeof(pyptr) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'ext/pycall/pycall.c', line 215 static VALUE pycall_pyptr_s_sizeof(VALUE klass, VALUE pyptr) { size_t size; PyObject *pyobj; pyobj = try_get_pyobj_ptr(pyptr); if (pyobj == NULL) return Qnil; size = _PySys_GetSizeOf(pyobj); return SIZET2NUM(size); } |
Instance Method Details
#==(other) ⇒ Object
292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'ext/pycall/pycall.c', line 292 static VALUE pycall_pyptr_eq(VALUE obj, VALUE other) { PyObject* pyobj; PyObject* pyobj_other; if (!is_pycall_pyptr(other)) return Qfalse; pyobj = get_pyobj_ptr(obj); pyobj_other = get_pyobj_ptr(other); return pyobj == pyobj_other ? Qtrue : Qfalse; } |
#===(other) ⇒ Object
292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'ext/pycall/pycall.c', line 292 static VALUE pycall_pyptr_eq(VALUE obj, VALUE other) { PyObject* pyobj; PyObject* pyobj_other; if (!is_pycall_pyptr(other)) return Qfalse; pyobj = get_pyobj_ptr(obj); pyobj_other = get_pyobj_ptr(other); return pyobj == pyobj_other ? Qtrue : Qfalse; } |
#__address__ ⇒ Object
306 307 308 309 310 311 |
# File 'ext/pycall/pycall.c', line 306 static VALUE pycall_pyptr_get_ptr_address(VALUE obj) { PyObject* pyobj = get_pyobj_ptr(obj); return PTR2NUM(pyobj); } |
#__ob_refcnt__ ⇒ Object
313 314 315 316 317 318 319 320 |
# File 'ext/pycall/pycall.c', line 313 static VALUE pycall_pyptr_get_ob_refcnt(VALUE obj) { PyObject* pyobj = get_pyobj_ptr(obj); if (pyobj) return SSIZET2NUM(pyobj->ob_refcnt); return Qnil; } |
#__ob_type__ ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'ext/pycall/pycall.c', line 324 static VALUE pycall_pyptr_get_ob_type(VALUE obj) { PyObject* pyobj = get_pyobj_ptr(obj); if (pyobj) { VALUE res; if (Py_TYPE(pyobj) == Py_API(PyInstance_Type)) res = pycall_pytype_to_ruby((PyObject *)((PyInstanceObject *)pyobj)->in_class); else res = pycall_pytype_to_ruby((PyObject *)pyobj->ob_type); return res; } return Qnil; } |
#class ⇒ Object
345 346 347 348 349 |
# File 'ext/pycall/pycall.c', line 345 static VALUE pycall_pyptr_class(VALUE obj) { return CLASS_OF(obj); } |
#eql?(other) ⇒ Boolean
292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'ext/pycall/pycall.c', line 292 static VALUE pycall_pyptr_eq(VALUE obj, VALUE other) { PyObject* pyobj; PyObject* pyobj_other; if (!is_pycall_pyptr(other)) return Qfalse; pyobj = get_pyobj_ptr(obj); pyobj_other = get_pyobj_ptr(other); return pyobj == pyobj_other ? Qtrue : Qfalse; } |
#hash ⇒ Object
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'ext/pycall/pycall.c', line 402 static VALUE pycall_pyptr_hash(VALUE obj) { PyObject *pyobj = get_pyobj_ptr(obj); Py_hash_t h; if (!pyobj) return PTR2NUM(pyobj); h = PyObject_Hash(pyobj); if (h == -1) { Py_API(PyErr_Clear)(); return PTR2NUM(pyobj); } return SSIZET2NUM(h); } |
#inspect ⇒ Object
351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'ext/pycall/pycall.c', line 351 static VALUE pycall_pyptr_inspect(VALUE obj) { VALUE cname, str; PyObject* pyobj = get_pyobj_ptr(obj); cname = rb_class_name(CLASS_OF(obj)); str = rb_sprintf("#<%"PRIsVALUE":%p type=%s addr=%p>", cname, (void*)obj, Py_TYPE(pyobj)->tp_name, pyobj); OBJ_INFECT(str, obj); return str; } |
#is_a?(klass) ⇒ Boolean
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
# File 'ext/pycall/pycall.c', line 381 static VALUE pycall_pyptr_is_kind_of(VALUE obj, VALUE klass) { PyObject* pyobj = get_pyobj_ptr(obj); VALUE res; if (is_pycall_pyptr(klass)) { int res; PyObject* pyobj_klass = get_pyobj_ptr(klass); res = Py_API(PyObject_IsInstance)(pyobj, pyobj_klass); if (res >= 0) { return res ? Qtrue : Qfalse; } Py_API(PyErr_Clear)(); } klass = class_or_module_required(klass); res = rb_class_inherited_p(CLASS_OF(obj), klass); return NIL_P(res) ? Qfalse : res; } |
#kind_of?(klass) ⇒ Boolean
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
# File 'ext/pycall/pycall.c', line 381 static VALUE pycall_pyptr_is_kind_of(VALUE obj, VALUE klass) { PyObject* pyobj = get_pyobj_ptr(obj); VALUE res; if (is_pycall_pyptr(klass)) { int res; PyObject* pyobj_klass = get_pyobj_ptr(klass); res = Py_API(PyObject_IsInstance)(pyobj, pyobj_klass); if (res >= 0) { return res ? Qtrue : Qfalse; } Py_API(PyErr_Clear)(); } klass = class_or_module_required(klass); res = rb_class_inherited_p(CLASS_OF(obj), klass); return NIL_P(res) ? Qfalse : res; } |
#nil? ⇒ Boolean
285 286 287 288 289 290 |
# File 'ext/pycall/pycall.c', line 285 static VALUE pycall_pyptr_is_nil(VALUE obj) { PyObject* pyobj = get_pyobj_ptr(obj); return (pyobj == Py_API(_Py_NoneStruct)) || (pyobj == NULL) ? Qtrue : Qfalse; } |
#none? ⇒ Boolean
278 279 280 281 282 283 |
# File 'ext/pycall/pycall.c', line 278 static VALUE pycall_pyptr_is_none(VALUE obj) { PyObject* pyobj = get_pyobj_ptr(obj); return pyobj == Py_API(_Py_NoneStruct) ? Qtrue : Qfalse; } |
#null? ⇒ Boolean
271 272 273 274 275 276 |
# File 'ext/pycall/pycall.c', line 271 static VALUE pycall_pyptr_is_null(VALUE obj) { PyObject* pyobj = get_pyobj_ptr(obj); return pyobj ? Qfalse : Qtrue; } |
#object_id ⇒ Object
339 340 341 342 343 |
# File 'ext/pycall/pycall.c', line 339 static VALUE pycall_pyptr_object_id(VALUE obj) { return rb_obj_id(obj); } |