CoreFW  Diff

Differences From Artifact [997da41042]:

To Artifact [3d2cb3ed1b]:


21
22
23
24
25
26
27

28
29

30
31
32
33
34
35
36
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdlib.h>


#include "object.h"


void*
cfw_new(CFWClass *class, ...)
{
	CFWObject *obj;

	if ((obj = malloc(class->size)) == NULL)







>


>







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdlib.h>
#include <assert.h>

#include "object.h"
#include "refpool.h"

void*
cfw_new(CFWClass *class, ...)
{
	CFWObject *obj;

	if ((obj = malloc(class->size)) == NULL)
46
47
48
49
50
51
52

































53
54
55
56
57
58
59
		if (!class->ctor(obj, args)) {
			cfw_unref(obj);
			return NULL;
		}

		va_end(args);
	}


































	return obj;
}

void*
cfw_ref(void *ptr)
{







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
86
87
88
89
90
91
92
93
94
		if (!class->ctor(obj, args)) {
			cfw_unref(obj);
			return NULL;
		}

		va_end(args);
	}

	return obj;
}

void*
cfw_new_p(CFWClass *class, ...)
{
	CFWObject *obj;

	assert(class != cfw_refpool);

	if ((obj = malloc(class->size)) == NULL)
		return NULL;

	obj->cls = class;
	obj->ref_cnt = 1;

	if (class->ctor != NULL) {
		va_list args;
		va_start(args, class);

		if (!class->ctor(obj, args)) {
			cfw_unref(obj);
			return NULL;
		}

		va_end(args);
	}

	if (!cfw_refpool_add(obj)) {
		cfw_unref(obj);
		return NULL;
	}

	return obj;
}

void*
cfw_ref(void *ptr)
{