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
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'ext/pycall/pycall.c', line 321 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
275 276 277 278 279 |
# File 'ext/pycall/pycall.c', line 275 static VALUE pycall_pyptr_s_decref(VALUE klass, VALUE pyptr) { return pycall_pyptr_decref(pyptr); } |
.incref(pyptr) ⇒ Object
244 245 246 247 248 |
# File 'ext/pycall/pycall.c', line 244 static VALUE pycall_pyptr_s_incref(VALUE klass, VALUE pyptr) { return pycall_pyptr_incref(pyptr); } |
.sizeof(pyptr) ⇒ Object
281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'ext/pycall/pycall.c', line 281 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
358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'ext/pycall/pycall.c', line 358 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
358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'ext/pycall/pycall.c', line 358 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
372 373 374 375 376 377 |
# File 'ext/pycall/pycall.c', line 372 static VALUE pycall_pyptr_get_ptr_address(VALUE obj) { PyObject* pyobj = get_pyobj_ptr(obj); return PTR2NUM(pyobj); } |
#__ob_refcnt__ ⇒ Object
379 380 381 382 383 384 385 386 |
# File 'ext/pycall/pycall.c', line 379 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
390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'ext/pycall/pycall.c', line 390 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
411 412 413 414 415 |
# File 'ext/pycall/pycall.c', line 411 static VALUE pycall_pyptr_class(VALUE obj) { return CLASS_OF(obj); } |
#eql?(other) ⇒ Boolean
358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'ext/pycall/pycall.c', line 358 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
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
# File 'ext/pycall/pycall.c', line 467 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
417 418 419 420 421 422 423 424 425 426 427 |
# File 'ext/pycall/pycall.c', line 417 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); return str; } |
#is_a?(klass) ⇒ Boolean
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'ext/pycall/pycall.c', line 446 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
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'ext/pycall/pycall.c', line 446 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
351 352 353 354 355 356 |
# File 'ext/pycall/pycall.c', line 351 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
344 345 346 347 348 349 |
# File 'ext/pycall/pycall.c', line 344 static VALUE pycall_pyptr_is_none(VALUE obj) { PyObject* pyobj = get_pyobj_ptr(obj); return pyobj == Py_API(_Py_NoneStruct) ? Qtrue : Qfalse; } |
#null? ⇒ Boolean
337 338 339 340 341 342 |
# File 'ext/pycall/pycall.c', line 337 static VALUE pycall_pyptr_is_null(VALUE obj) { PyObject* pyobj = get_pyobj_ptr(obj); return pyobj ? Qfalse : Qtrue; } |
#object_id ⇒ Object
405 406 407 408 409 |
# File 'ext/pycall/pycall.c', line 405 static VALUE pycall_pyptr_object_id(VALUE obj) { return rb_obj_id(obj); } |