ObjFW  Check-in [e5b241b72d]

Overview
Comment: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.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e5b241b72d11c754c53d946cc8a8a5bb2673cadff3f5953130e7cd732d87f4d0
User & Date: js on 2012-07-09 21:10:59
Other Links: manifest | tags
Context
2012-07-10
22:01
New platforms list. check-in: 1d67417011 user: js tags: trunk
2012-07-09
21:10
Fix two bugs in sel_registerName. check-in: e5b241b72d user: js tags: trunk
2012-07-08
13:34
objfw-config: Always add -funwind-tables. check-in: 8f50777186 user: js tags: trunk
Changes

Modified src/runtime/selector.m from [ce39c495db] to [f1aef89fda].

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;