Skip to content

Commit

Permalink
Merge pull request #3032 from yebblies/libfactory
Browse files Browse the repository at this point in the history
[DDMD] Always create libs through named factory functions
  • Loading branch information
WalterBright committed Dec 31, 2013
2 parents df5166a + d4ca20e commit 78331fc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
20 changes: 17 additions & 3 deletions src/lib.h
Expand Up @@ -15,18 +15,32 @@
#pragma once
#endif /* __DMC__ */

Library *LibMSCoff_factory();
Library *LibOMF_factory();
Library *LibElf_factory();
Library *LibMach_factory();

class Library
{
public:
static Library *factory();
static Library *factory()
{
#if TARGET_WINDOS
return global.params.is64bit ? LibMSCoff_factory() : LibOMF_factory();
#elif TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
return LibElf_factory();
#elif TARGET_OSX
return LibMach_factory();
#else
assert(0); // unsupported system
#endif
}

virtual void setFilename(const char *dir, const char *filename) = 0;
virtual void addObject(const char *module_name, void *buf, size_t buflen) = 0;
virtual void addLibrary(void *buf, size_t buflen) = 0;
virtual void write() = 0;
};

Library *LibMSCoff_factory();

#endif /* DMD_LIB_H */

2 changes: 1 addition & 1 deletion src/libelf.c
Expand Up @@ -69,7 +69,7 @@ class LibElf : public Library
Loc loc;
};

Library *Library::factory()
Library *LibElf_factory()
{
return new LibElf();
}
Expand Down
2 changes: 1 addition & 1 deletion src/libmach.c
Expand Up @@ -79,7 +79,7 @@ class LibMach : public Library
Loc loc;
};

Library *Library::factory()
Library *LibMach_factory()
{
return new LibMach();
}
Expand Down
4 changes: 2 additions & 2 deletions src/libomf.c
Expand Up @@ -79,9 +79,9 @@ class LibOMF : public Library
Loc loc;
};

Library *Library::factory()
Library *LibOMF_factory()
{
return global.params.is64bit ? LibMSCoff_factory() : new LibOMF();
return new LibOMF();
}

LibOMF::LibOMF()
Expand Down

0 comments on commit 78331fc

Please sign in to comment.