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
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'ext/pycall/pycall.c', line 309
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
263 264 265 266 267 |
# File 'ext/pycall/pycall.c', line 263
static VALUE
pycall_pyptr_s_decref(VALUE klass, VALUE pyptr)
{
return pycall_pyptr_decref(pyptr);
}
|
.incref(pyptr) ⇒ Object
232 233 234 235 236 |
# File 'ext/pycall/pycall.c', line 232
static VALUE
pycall_pyptr_s_incref(VALUE klass, VALUE pyptr)
{
return pycall_pyptr_incref(pyptr);
}
|
.sizeof(pyptr) ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'ext/pycall/pycall.c', line 269
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
346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'ext/pycall/pycall.c', line 346
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
346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'ext/pycall/pycall.c', line 346
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
360 361 362 363 364 365 |
# File 'ext/pycall/pycall.c', line 360
static VALUE
pycall_pyptr_get_ptr_address(VALUE obj)
{
PyObject* pyobj = get_pyobj_ptr(obj);
return PTR2NUM(pyobj);
}
|
#__ob_refcnt__ ⇒ Object
367 368 369 370 371 372 373 374 |
# File 'ext/pycall/pycall.c', line 367
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
378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'ext/pycall/pycall.c', line 378
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
399 400 401 402 403 |
# File 'ext/pycall/pycall.c', line 399
static VALUE
pycall_pyptr_class(VALUE obj)
{
return CLASS_OF(obj);
}
|
#eql?(other) ⇒ Boolean
346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'ext/pycall/pycall.c', line 346
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
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
# File 'ext/pycall/pycall.c', line 456
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
405 406 407 408 409 410 411 412 413 414 415 416 |
# File 'ext/pycall/pycall.c', line 405
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
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'ext/pycall/pycall.c', line 435
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
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'ext/pycall/pycall.c', line 435
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
339 340 341 342 343 344 |
# File 'ext/pycall/pycall.c', line 339
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
332 333 334 335 336 337 |
# File 'ext/pycall/pycall.c', line 332
static VALUE
pycall_pyptr_is_none(VALUE obj)
{
PyObject* pyobj = get_pyobj_ptr(obj);
return pyobj == Py_API(_Py_NoneStruct) ? Qtrue : Qfalse;
}
|
#null? ⇒ Boolean
325 326 327 328 329 330 |
# File 'ext/pycall/pycall.c', line 325
static VALUE
pycall_pyptr_is_null(VALUE obj)
{
PyObject* pyobj = get_pyobj_ptr(obj);
return pyobj ? Qfalse : Qtrue;
}
|
#object_id ⇒ Object
393 394 395 396 397 |
# File 'ext/pycall/pycall.c', line 393
static VALUE
pycall_pyptr_object_id(VALUE obj)
{
return rb_obj_id(obj);
}
|