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
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'ext/pycall/pycall.c', line 313
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
267 268 269 270 271 |
# File 'ext/pycall/pycall.c', line 267
static VALUE
pycall_pyptr_s_decref(VALUE klass, VALUE pyptr)
{
return pycall_pyptr_decref(pyptr);
}
|
.incref(pyptr) ⇒ Object
236 237 238 239 240 |
# File 'ext/pycall/pycall.c', line 236
static VALUE
pycall_pyptr_s_incref(VALUE klass, VALUE pyptr)
{
return pycall_pyptr_incref(pyptr);
}
|
.sizeof(pyptr) ⇒ Object
273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'ext/pycall/pycall.c', line 273
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
350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'ext/pycall/pycall.c', line 350
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
350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'ext/pycall/pycall.c', line 350
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
364 365 366 367 368 369 |
# File 'ext/pycall/pycall.c', line 364
static VALUE
pycall_pyptr_get_ptr_address(VALUE obj)
{
PyObject* pyobj = get_pyobj_ptr(obj);
return PTR2NUM(pyobj);
}
|
#__ob_refcnt__ ⇒ Object
371 372 373 374 375 376 377 378 |
# File 'ext/pycall/pycall.c', line 371
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
382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'ext/pycall/pycall.c', line 382
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
403 404 405 406 407 |
# File 'ext/pycall/pycall.c', line 403
static VALUE
pycall_pyptr_class(VALUE obj)
{
return CLASS_OF(obj);
}
|
#eql?(other) ⇒ Boolean
350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'ext/pycall/pycall.c', line 350
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
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'ext/pycall/pycall.c', line 459
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
409 410 411 412 413 414 415 416 417 418 419 |
# File 'ext/pycall/pycall.c', line 409
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
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'ext/pycall/pycall.c', line 438
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
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'ext/pycall/pycall.c', line 438
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
343 344 345 346 347 348 |
# File 'ext/pycall/pycall.c', line 343
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
336 337 338 339 340 341 |
# File 'ext/pycall/pycall.c', line 336
static VALUE
pycall_pyptr_is_none(VALUE obj)
{
PyObject* pyobj = get_pyobj_ptr(obj);
return pyobj == Py_API(_Py_NoneStruct) ? Qtrue : Qfalse;
}
|
#null? ⇒ Boolean
329 330 331 332 333 334 |
# File 'ext/pycall/pycall.c', line 329
static VALUE
pycall_pyptr_is_null(VALUE obj)
{
PyObject* pyobj = get_pyobj_ptr(obj);
return pyobj ? Qfalse : Qtrue;
}
|
#object_id ⇒ Object
397 398 399 400 401 |
# File 'ext/pycall/pycall.c', line 397
static VALUE
pycall_pyptr_object_id(VALUE obj)
{
return rb_obj_id(obj);
}
|