ObjFW  Diff

Differences From Artifact [ce39c495db]:

To Artifact [f1aef89fda]:

  • File src/runtime/selector.m — part of check-in [e5b241b72d] at 2012-07-09 21:10:59 on branch trunk — Fix two bugs in sel_registerName.

    The first was that sel_registerName would crash if no selector has ever
    been registered before. This caused a crash on NetBSD in has_load, as
    the first class being loaded there (Protocol) had no selectors and
    has_load uses sel_registerName in order to get the load selector.

    The second one was that the hashtable was read without a lock to see if
    the selector has already been registered before. (user: js, size: 2851) [annotate] [blame] [check-ins using]


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

SEL
sel_registerName(const char *name)
{
	const struct objc_abi_selector *rsel;
	struct objc_abi_selector *sel;




	if ((rsel = objc_hashtable_get(selectors, name)) != NULL)

		return (SEL)rsel;


	/* FIXME: Free on objc_exit() */
	if ((sel = malloc(sizeof(struct objc_abi_selector))) == NULL)
		ERROR("Not enough memory to allocate selector!");

	if ((sel->name = strdup(name)) == NULL)
		ERROR("Not enough memory to allocate selector!");

	sel->types = NULL;

	objc_global_mutex_lock();
	objc_register_selector(sel);
	objc_global_mutex_unlock();


	return (SEL)sel;
}

void
objc_register_all_selectors(struct objc_abi_symtab *symtab)
{
	struct objc_abi_selector *sel;







>
>
>
|
>

>










<

<

>







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
95

SEL
sel_registerName(const char *name)
{
	const struct objc_abi_selector *rsel;
	struct objc_abi_selector *sel;

	objc_global_mutex_lock();

	if (selectors != NULL &&
	    (rsel = objc_hashtable_get(selectors, name)) != NULL) {
		objc_global_mutex_unlock();
		return (SEL)rsel;
	}

	/* FIXME: Free on objc_exit() */
	if ((sel = malloc(sizeof(struct objc_abi_selector))) == NULL)
		ERROR("Not enough memory to allocate selector!");

	if ((sel->name = strdup(name)) == NULL)
		ERROR("Not enough memory to allocate selector!");

	sel->types = NULL;


	objc_register_selector(sel);


	objc_global_mutex_unlock();
	return (SEL)sel;
}

void
objc_register_all_selectors(struct objc_abi_symtab *symtab)
{
	struct objc_abi_selector *sel;