summaryrefslogtreecommitdiffstats
path: root/libmsi/handle.c
blob: e1b44943c4b68cb2a60c0e990e818a7be4db2032 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Implementation of the Microsoft Installer (msi.dll)
 *
 * Copyright 2002-2004 Mike McCormack for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <stdarg.h>
#include <assert.h>

#include "debug.h"
#include "libmsi.h"
#include "msipriv.h"


void *alloc_msiobject(unsigned size, msihandledestructor destroy )
{
    LibmsiObject *info;

    info = msi_alloc_zero( size );
    if( info )
    {
        info->magic = 0xC007C0DE;
        info->refcount = 1;
        info->destructor = destroy;
    }

    return info;
}

void msiobj_addref( LibmsiObject *info )
{
    if( !info )
        return;

    assert(info->magic == 0xC007C0DE);
    __sync_add_and_fetch(&info->refcount, 1);
}

int msiobj_release( LibmsiObject *obj )
{
    int ret;

    if( !obj )
        return -1;

    assert(obj->magic == 0xC007C0DE);
    ret = __sync_sub_and_fetch( &obj->refcount, 1 );
    if( ret==0 )
    {
        if( obj->destructor )
            obj->destructor( obj );
        obj->magic = 0xDEADB0D7;
        msi_free( obj );
        TRACE("object %p destroyed\n", obj);
    }

    return ret;
}

/***********************************************************
 *   libmsi_unref   [MSI.@]
 */
LibmsiResult libmsi_unref(void *obj)
{
    TRACE("%x\n",obj);

    if( obj )
        msiobj_release( obj );

    return LIBMSI_RESULT_SUCCESS;
}