Skip to content

Commit 8322cbd

Browse files
committed
Merge pull request #31 from am11/master
Code: Sends copy of string to upstream
2 parents ff58049 + 56c044c commit 8322cbd

File tree

6 files changed

+46
-21
lines changed

6 files changed

+46
-21
lines changed

appveyor.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
platform:
2+
- Win32
3+
- x64
4+
15
configuration:
26
- Debug
37
- Release
@@ -11,3 +15,7 @@ before_build:
1115
build:
1216
verbosity: minimal
1317
project: libsass-net.sln
18+
19+
on_success:
20+
- 7z a libsass-net.zip .
21+
- ps: Push-AppveyorArtifact libsass-net.zip

libsass/SassInterface.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,17 @@
1818
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
//SOFTWARE.
2020

21-
#include <exception>
22-
#include "native\sass_interface.h"
2321
#include "native\sass2scss.h"
2422
#include "StringToANSI.hpp"
2523
#include "SassInterface.hpp"
26-
#include "native\sass_context.h"
27-
28-
using namespace std;
2924

3025
namespace LibSassNet
3126
{
3227
int SassInterface::Compile(SassContext^ sassContext)
3328
{
3429
char* includePaths = MarshalString(sassContext->Options->IncludePaths);
3530
char* sourceString = MarshalString(sassContext->SourceString);
31+
char* lineFeed = MarshalString(sassContext->Options->LineFeed);
3632
struct Sass_Data_Context* ctx;
3733

3834
try
@@ -45,12 +41,13 @@ namespace LibSassNet
4541
sass_option_set_output_style(options, GetOutputStyle(sassContext->Options->OutputStyle));
4642
sass_option_set_source_comments(options, sassContext->Options->IncludeSourceComments);
4743
sass_option_set_precision(options, sassContext->Options->Precision);
44+
sass_option_set_linefeed(options, lineFeed);
4845
sass_option_set_include_path(options, includePaths);
49-
sass_option_set_omit_source_map_url(options, true);
46+
sass_option_set_omit_source_map_url(options, sassContext->Options->OmitSourceMappingUrl);
5047

5148
sass_compile_data_context(ctx);
5249

53-
sassContext->ErrorStatus = sass_context_get_error_status(ctx_out);
50+
sassContext->ErrorStatus = !!sass_context_get_error_status(ctx_out);
5451
sassContext->ErrorMessage = gcnew String(sass_context_get_error_message(ctx_out));
5552
sassContext->OutputString = gcnew String(sass_context_get_output_string(ctx_out));
5653

@@ -67,8 +64,6 @@ namespace LibSassNet
6764
finally
6865
{
6966
// Free resources
70-
FreeString(includePaths);
71-
FreeString(sourceString);
7267
sass_delete_data_context(ctx);
7368
}
7469
}
@@ -90,8 +85,9 @@ namespace LibSassNet
9085
char* includePaths = MarshalString(sassFileContext->Options->IncludePaths);
9186
char* mapFile = MarshalString(sassFileContext->OutputSourceMapFile);
9287
char* inputPath = MarshalString(sassFileContext->InputPath);
93-
88+
char* lineFeed = MarshalString(sassFileContext->Options->LineFeed);
9489
struct Sass_File_Context* ctx;
90+
9591
try
9692
{
9793
ctx = sass_make_file_context(inputPath);
@@ -103,13 +99,14 @@ namespace LibSassNet
10399
sass_option_set_output_style(options, GetOutputStyle(sassFileContext->Options->OutputStyle));
104100
sass_option_set_source_comments(options, sassFileContext->Options->IncludeSourceComments);
105101
sass_option_set_precision(options, sassFileContext->Options->Precision);
102+
sass_option_set_linefeed(options, lineFeed);
106103
sass_option_set_include_path(options, includePaths);
107-
sass_option_set_omit_source_map_url(options, String::IsNullOrEmpty(sassFileContext->OutputSourceMapFile));
104+
sass_option_set_omit_source_map_url(options, sassFileContext->Options->OmitSourceMappingUrl);
108105
sass_option_set_source_map_file(options, mapFile);
109106

110107
sass_compile_file_context(ctx);
111108

112-
sassFileContext->ErrorStatus = sass_context_get_error_status(ctx_out);
109+
sassFileContext->ErrorStatus = !!sass_context_get_error_status(ctx_out);
113110
sassFileContext->ErrorMessage = gcnew String(sass_context_get_error_message(ctx_out));
114111
sassFileContext->OutputString = gcnew String(sass_context_get_output_string(ctx_out));
115112
sassFileContext->OutputSourceMap = gcnew String(sass_context_get_source_map_string(ctx_out));
@@ -127,9 +124,6 @@ namespace LibSassNet
127124
finally
128125
{
129126
// Free resources
130-
FreeString(includePaths);
131-
FreeString(inputPath);
132-
FreeString(mapFile);
133127
sass_delete_file_context(ctx);
134128
}
135129
}
@@ -156,6 +150,7 @@ namespace LibSassNet
156150
}
157151
finally
158152
{
153+
// Upstream will not free the memory in case of sass2scss
159154
FreeString(sourceText);
160155
}
161156
}
@@ -205,4 +200,4 @@ namespace LibSassNet
205200
sass_free_folder_context(ctx);
206201
}
207202
}*/
208-
}
203+
}

libsass/SassInterface.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//SOFTWARE.
2020

2121
#include "ISassInterface.hpp"
22+
#include "native\sass_context.h"
2223

2324
namespace LibSassNet
2425
{
@@ -33,4 +34,4 @@ namespace LibSassNet
3334
// Folder context isn't implemented in core libsass library now
3435
/*virtual int Compile(SassFolderContext^ sassFolderContext);*/
3536
};
36-
}
37+
}

libsass/SassOptions.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ namespace LibSassNet
2929
public:
3030
property int OutputStyle;
3131
property bool IncludeSourceComments;
32+
property bool OmitSourceMappingUrl;
3233
property int Precision;
3334
property String^ IncludePaths;
35+
property String^ LineFeed;
3436
};
3537

3638
public ref class SassContext

libsass/StringToANSI.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//SOFTWARE.
2020

2121
#using <System.dll>
22+
#include <string>
2223
#include "StringToANSI.hpp"
2324

2425
using namespace System;
@@ -27,8 +28,18 @@ using namespace System::Runtime::InteropServices;
2728
namespace LibSassNet
2829
{
2930
char* MarshalString(String^ s)
30-
{
31-
return (char*) ((Marshal::StringToCoTaskMemAnsi(s)).ToPointer());
31+
{
32+
if (!s) {
33+
return nullptr;
34+
}
35+
36+
char* original_str = (char*)(Marshal::StringToCoTaskMemAnsi(s)).ToPointer();
37+
char* target_str = (char*)malloc(strlen(original_str) + 1);
38+
strcpy(target_str, original_str);
39+
40+
FreeString(original_str);
41+
42+
return target_str;
3243
}
3344

3445
void FreeString(const char* p)

libsassnet/SassCompiler.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public class SassCompiler : ISassCompiler
2929
{
3030
private readonly ISassInterface _sassInterface;
3131

32+
public string OutputLineFeed { get; set; }
33+
34+
public bool OmitSourceMappingUrl { get; set; }
35+
3236
public SassCompiler()
3337
{
3438
_sassInterface = new SassInterface();
@@ -50,7 +54,9 @@ public string Compile(string source, OutputStyle outputStyle = OutputStyle.Neste
5054
OutputStyle = (int)outputStyle,
5155
IncludeSourceComments = includeSourceComments,
5256
IncludePaths = includePaths != null ? String.Join(";", includePaths) : String.Empty,
53-
Precision = precision
57+
Precision = precision,
58+
LineFeed = OutputLineFeed ?? (OutputLineFeed = "\r\n"),
59+
OmitSourceMappingUrl = OmitSourceMappingUrl
5460
}
5561
};
5662

@@ -83,7 +89,9 @@ public CompileFileResult CompileFile(string inputPath, OutputStyle outputStyle =
8389
OutputStyle = (int)outputStyle,
8490
IncludeSourceComments = includeSourceComments,
8591
IncludePaths = String.Join(";", includePaths),
86-
Precision = precision
92+
Precision = precision,
93+
LineFeed = OutputLineFeed ?? (OutputLineFeed = "\r\n"),
94+
OmitSourceMappingUrl = OmitSourceMappingUrl
8795
},
8896
OutputSourceMapFile = sourceMapPath
8997
};

0 commit comments

Comments
 (0)