Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit d8308a7

Browse files
Merge pull request #956 from IntelPython/master
Merge from master 2021_w5
2 parents 5d09505 + 79fb01b commit d8308a7

23 files changed

Lines changed: 936 additions & 570 deletions

conda-recipe/meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ requirements:
2020
- {{ compiler('cxx') }} # [not osx]
2121
- wheel
2222
- python
23+
- numba {{ NUMBA_VERSION }}
2324

2425
host:
2526
- python
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2020, Intel Corporation All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
#
10+
# Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
# *****************************************************************************
26+
27+
import pandas as pd
28+
from numba import njit
29+
30+
31+
@njit
32+
def dataframe_columns():
33+
df = pd.DataFrame({'A': [1, 2], 'AA': [3, 4], 'B': [5, 6]}, index=['a', 'b'])
34+
result = df.columns
35+
36+
return result # A tuple of column names ('A', 'AA', 'B')
37+
38+
39+
print(dataframe_columns())

sdc/_meminfo.h

Lines changed: 0 additions & 182 deletions
This file was deleted.

sdc/_str_decode.cpp

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626

2727
#include <Python.h>
2828
#include <iostream>
29+
#include <stdlib.h>
2930

30-
#include "_meminfo.h"
31+
#include "numba/core/runtime/nrt_external.h"
3132

3233
#ifndef Py_UNREACHABLE
3334
#define Py_UNREACHABLE() abort()
@@ -37,6 +38,7 @@
3738

3839
typedef struct
3940
{
41+
NRT_api_functions* nrt;
4042
NRT_MemInfo* buffer;
4143
void* data;
4244
enum PyUnicode_Kind kind;
@@ -120,20 +122,28 @@ void _C_UnicodeWriter_Init(_C_UnicodeWriter* writer)
120122
#include "stringlib/undef.h"
121123

122124
static inline int _C_UnicodeWriter_WriteCharInline(_C_UnicodeWriter* writer, Py_UCS4 ch);
123-
static int _copy_characters(NRT_MemInfo* to,
125+
static int _copy_characters(NRT_api_functions* nrt,
126+
NRT_MemInfo* to,
124127
Py_ssize_t to_start,
125128
NRT_MemInfo* from,
126129
Py_ssize_t from_start,
127130
Py_ssize_t how_many,
128131
unsigned int from_kind,
129132
unsigned int to_kind);
130133

134+
135+
static void str_data_dtor(void* data_ptr)
136+
{
137+
free(data_ptr);
138+
}
139+
131140
// similar to PyUnicode_New()
132141
NRT_MemInfo* alloc_writer(_C_UnicodeWriter* writer, Py_ssize_t newlen, Py_UCS4 maxchar)
133142
{
134143
enum PyUnicode_Kind kind;
135144
int is_ascii = 0;
136145
Py_ssize_t char_size;
146+
auto nrt = writer->nrt;
137147

138148
if (maxchar < 128)
139149
{
@@ -161,20 +171,22 @@ NRT_MemInfo* alloc_writer(_C_UnicodeWriter* writer, Py_ssize_t newlen, Py_UCS4 m
161171
kind = PyUnicode_4BYTE_KIND;
162172
char_size = 4;
163173
}
164-
NRT_MemInfo* newbuffer = NRT_MemInfo_alloc_safe((newlen + 1) * char_size);
165-
if (newbuffer == NULL)
174+
175+
char* str_data = (char*)malloc((newlen + 1) * char_size);
176+
if (str_data == NULL)
166177
{
167178
return NULL;
168179
}
169180

181+
auto newbuffer = nrt->manage_memory(str_data, str_data_dtor);
170182
if (writer->buffer != NULL)
171183
{
172-
_copy_characters(newbuffer, 0, writer->buffer, 0, writer->pos, writer->kind, kind);
173-
NRT_MemInfo_call_dtor(writer->buffer);
184+
_copy_characters(nrt, newbuffer, 0, writer->buffer, 0, writer->pos, writer->kind, kind);
185+
nrt->release(writer->buffer);
174186
}
175187
writer->buffer = newbuffer;
176188
writer->maxchar = KIND_MAX_CHAR_VALUE(kind);
177-
writer->data = writer->buffer->data;
189+
writer->data = nrt->get_data(writer->buffer);
178190

179191
if (!writer->readonly)
180192
{
@@ -356,19 +368,22 @@ static Py_ssize_t ascii_decode(const char* start, const char* end, Py_UCS1* dest
356368
return p - start;
357369
}
358370

371+
359372
// ported from CPython PyUnicode_DecodeUTF8Stateful: https://github.com/python/cpython/blob/31e8d69bfe7cf5d4ffe0967cb225d2a8a229cc97/Objects/unicodeobject.c#L4813
360-
void decode_utf8(const char* s, Py_ssize_t size, int* kind, int* is_ascii, int* length, NRT_MemInfo** meminfo)
373+
void decode_utf8(const char* s, Py_ssize_t size, int* kind, int* is_ascii, int* length, NRT_MemInfo** meminfo, void* nrt_table)
361374
{
362375
_C_UnicodeWriter writer;
363376
const char* end = s + size;
377+
auto nrt = (NRT_api_functions*)nrt_table;
364378

365379
const char* errmsg = "";
366380
*is_ascii = 0;
367381

368382
if (size == 0)
369383
{
370-
(*meminfo) = NRT_MemInfo_alloc_safe(1);
371-
((char*)((*meminfo)->data))[0] = 0;
384+
char* str_data = (char*)malloc(1);
385+
(*meminfo) = nrt->manage_memory(str_data, str_data_dtor);
386+
((char*)(nrt->get_data(*meminfo)))[0] = 0;
372387
*kind = PyUnicode_1BYTE_KIND;
373388
*is_ascii = 1;
374389
*length = 0;
@@ -379,9 +394,10 @@ void decode_utf8(const char* s, Py_ssize_t size, int* kind, int* is_ascii, int*
379394
if (size == 1 && (unsigned char)s[0] < 128)
380395
{
381396
// TODO interning
382-
(*meminfo) = NRT_MemInfo_alloc_safe(2);
383-
((char*)((*meminfo)->data))[0] = s[0];
384-
((char*)((*meminfo)->data))[1] = 0;
397+
char* str_data = (char*)malloc(2);
398+
(*meminfo) = nrt->manage_memory(str_data, str_data_dtor);
399+
((char*)(nrt->get_data(*meminfo)))[0] = s[0];
400+
((char*)(nrt->get_data(*meminfo)))[1] = 0;
385401
*kind = PyUnicode_1BYTE_KIND;
386402
*is_ascii = 1;
387403
*length = 1;
@@ -390,6 +406,7 @@ void decode_utf8(const char* s, Py_ssize_t size, int* kind, int* is_ascii, int*
390406

391407
_C_UnicodeWriter_Init(&writer);
392408
writer.min_length = size;
409+
writer.nrt = nrt;
393410
if (_C_UnicodeWriter_Prepare(&writer, writer.min_length, 127) == -1)
394411
goto onError;
395412

@@ -469,7 +486,7 @@ void decode_utf8(const char* s, Py_ssize_t size, int* kind, int* is_ascii, int*
469486

470487
onError:
471488
std::cerr << "utf8 decode error:" << errmsg << std::endl;
472-
NRT_MemInfo_call_dtor(writer.buffer);
489+
nrt->release(*meminfo);
473490
return;
474491
}
475492

@@ -499,7 +516,8 @@ void decode_utf8(const char* s, Py_ssize_t size, int* kind, int* is_ascii, int*
499516
*_to++ = (to_type)*_iter++; \
500517
} while (0)
501518

502-
static int _copy_characters(NRT_MemInfo* to,
519+
static int _copy_characters(NRT_api_functions* nrt,
520+
NRT_MemInfo* to,
503521
Py_ssize_t to_start,
504522
NRT_MemInfo* from,
505523
Py_ssize_t from_start,
@@ -516,8 +534,8 @@ static int _copy_characters(NRT_MemInfo* to,
516534
if (how_many == 0)
517535
return 0;
518536

519-
from_data = from->data;
520-
to_data = to->data;
537+
from_data = nrt->get_data(from);
538+
to_data = nrt->get_data(to);
521539

522540
if (from_kind == to_kind)
523541
{

0 commit comments

Comments
 (0)