/*
    Copyright (c) 2007 SIEGE Development Team
    All rights reserved.
    
    This file is part of libSIEGE.
    
    This software is copyrighted work licensed under the terms of the
    2-clause BSD license. Please consult the file "license.txt" for
    details.
    
    If you did not recieve the file with this program, please email
    Tim Chas <darkuranium@gmail.com>.
*/

#include "common.h"

#include <stdlib.h>
#include <string.h>

void* pysHandleGet(PyObject* self, char* name, char* type)
{
    PyObject* handle = PyObject_GetAttrString(self, name);
    if(handle == NULL)
        return NULL;

    void* chandle;
    PYS_CAPSULE_GET(chandle, type, handle);
    Py_DECREF(handle);
    return chandle;
}

void* pysHandleGetAttach(PyObject* from, PyObject* to, char* name, char* type)
{
    PyObject* handle = PyObject_GetAttrString(from, name);
    if(handle == NULL)
        return NULL;

    void* chandle;
    PYS_CAPSULE_GET(chandle, type, handle);

    PyObject_SetAttrString(to, name, handle);
    Py_DECREF(handle);
    return chandle;
}
