Skip to content

Instantly share code, notes, and snippets.

@kripken
Created January 16, 2019 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kripken/23c0e8749971d727cc402e2b513aa429 to your computer and use it in GitHub Desktop.
Save kripken/23c0e8749971d727cc402e2b513aa429 to your computer and use it in GitHub Desktop.
@needs_dlfcn
def test_dylink_global_ctor_and_stack(self):
# a global ctor in the main module must not call a side module before the side module is
# all set up - otherwise, the stack may be in the wrong place.
self.emcc_args += ['-g']
with env_modify({'EMCC_FORCE_STDLIBS': 'libc++'}):
self.dylink_test(header=r'''
#include<string>
const int gStudent = 10;
class Student{
private:
std::string name;
public:
Student(std::string);
virtual void display();
};
const Student gOneStudent("gOneStudent");
''', main=r'''
#include "header.h"
#include <iostream>
using namespace std;
int main(int argc, char *argv[]){
Student s("Angad");
s.display();
cout <<"\ngStudent=" << gStudent << std::flush;
cout << std::endl;
return 0;
}
''', side=r'''
#include <iostream>
#include "header.h"
using namespace std;
Student::Student(string name):name(name){}
void Student::display(){
cout << "A student with name " << this->name << endl;
}''', expected=['A student with name Angad'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment